Setup
Install the Braintrust SDK and Instructor alongside your provider SDK:.env
Tracing Instructor requires
instructor 1.11.0 or later and the Braintrust Python SDK v0.23.0 or later.Auto-instrumentation
To trace Instructor without wrapping each client, callinit_logger() and auto_instrument() once at startup. auto_instrument() patches Instructor’s create methods along with the underlying provider SDK, so each extraction appears as a task span with the provider’s LLM call nested beneath it.Instrument only Instructor
Instrument only Instructor
To patch Instructor without enabling Braintrust’s other integrations, wrap the client with
wrap_instructor() instead. See Manual instrumentation.Manual instrumentation
To trace Instructor yourself, wrap the Instructor client withwrap_instructor(). Wrap the underlying provider client with wrap_openai() first so the provider’s LLM call is captured as a child of the Instructor span.What Braintrust traces
Braintrust captures:- Structured-output spans (
instructor.create,instructor.create_with_completion,instructor.create_partial, andinstructor.create_iterable), with the request messages, response model, and Instructor mode as input, and the extracted Pydantic model as output. - Extraction metadata, including the model, provider, response model, Instructor mode, and configured max retries.
- Retry details, including the retry count and the Pydantic validation errors that triggered each retry.
wrap_openai() or auto_instrument()) to see token counts alongside the extraction.