Skip to main content
Instructor is a Python library for generating structured outputs from LLMs using Pydantic models. Braintrust integrates with Instructor to trace structured output generation.

Setup

Install Instructor alongside the Braintrust SDK and OpenAI client:

Trace with Instructor

When using Instructor with Braintrust, wrap the OpenAI client with wrap_openai before patching with Instructor. This ensures Braintrust captures the low-level metrics and headers from OpenAI.
trace-instructor.py
The order matters: instructor.patch(wrap_openai(OpenAI())) ensures Braintrust captures complete metrics.

Resources