Skip to content

feat: Add Instructor integration#465

Merged
Abhijeet Prasad (AbhiPrasad) merged 1 commit into
mainfrom
feat/instructor-integration
May 26, 2026
Merged

feat: Add Instructor integration#465
Abhijeet Prasad (AbhiPrasad) merged 1 commit into
mainfrom
feat/instructor-integration

Conversation

@AbhiPrasad
Copy link
Copy Markdown
Member

@AbhiPrasad Abhijeet Prasad (AbhiPrasad) commented May 26, 2026

ref https://python.useinstructor.com/
resolves #460

Users can enable Instructor tracing either globally with auto-instrumentation:

import braintrust

braintrust.auto_instrument()

or explicitly for Instructor only:

from braintrust.integrations import InstructorIntegration

InstructorIntegration.setup()

Manual wrapping is also supported for direct client/class wrapping:

from braintrust import wrap_instructor

client = wrap_instructor(client)

The integration instruments sync and async Instructor structured-output APIs, including create, create_with_completion, create_partial, and create_iterable.

It emits task spans for Instructor structured-output work. Each span captures the response model, mode, messages, max retries, retry count, validation errors, and the extracted Pydantic output (or collected iterable/partial outputs):

{
    "input": {
        "response_model": "Person",
        "mode": "TOOLS",
        "messages": [...],
    },
    "output": {"name": "Grace", "age": 45},
    "metadata": {
        "response_model": "Person",
        "mode": "TOOLS",
        "max_retries": 3,
        "retry_count": 0,
        "validation_errors": [],
    },
}

Token usage and LLM request/response spans remain owned by the underlying provider integrations such as OpenAI or Anthropic to avoid double-counting.

@AbhiPrasad Abhijeet Prasad (AbhiPrasad) changed the title Add Instructor integration feat: Add Instructor integration May 26, 2026
Users can enable Instructor tracing either globally with auto-instrumentation:

```python
import braintrust

braintrust.auto_instrument()
```

or explicitly for Instructor only:

```python
from braintrust.integrations import InstructorIntegration

InstructorIntegration.setup()
```

Manual wrapping is also supported for direct client/class wrapping:

```python
from braintrust import wrap_instructor

client = wrap_instructor(client)
```

The integration instruments sync and async Instructor structured-output APIs, including `create`, `create_with_completion`, `create_partial`, and `create_iterable`.

It emits `task` spans for Instructor structured-output work. Each span captures the response model, mode, messages, max retries, retry count, validation errors, and the extracted Pydantic output (or collected iterable/partial outputs):

```python
{
    "input": {
        "response_model": "Person",
        "mode": "TOOLS",
        "messages": [...],
    },
    "output": {"name": "Grace", "age": 45},
    "metadata": {
        "response_model": "Person",
        "mode": "TOOLS",
        "max_retries": 3,
        "retry_count": 0,
        "validation_errors": [],
    },
}
```

Token usage and LLM request/response spans remain owned by the underlying provider integrations such as OpenAI or Anthropic to avoid double-counting.
@AbhiPrasad Abhijeet Prasad (AbhiPrasad) merged commit a69244e into main May 26, 2026
82 checks passed
@AbhiPrasad Abhijeet Prasad (AbhiPrasad) deleted the feat/instructor-integration branch May 26, 2026 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bot] Add Instructor native integration for multi-provider structured output instrumentation

2 participants