Instructor (tracing)
Instructor (tracing)
Instructor is a Python LLM SDK for extracting structured data from model responses. Respan captures Instructor calls as chat spans and uses respan-tracing for workflow names, metadata propagation, and export.
Instructor does not create its own workflow trace object. Use @workflow, @task, and propagate_attributes from respan-tracing when you want recognizable trace names around Instructor calls.
Set up Respan
Create an account at platform.respan.ai and grab an API key.
Run npx @respan/cli setup to set up with your coding agent.
Use Respan Gateway
See Instructor gateway setup to route this integration through the Respan gateway.
Example projects
- Example repo root:
respan-example-projects/python/tracing/instructor
Setup
Set environment variables
RESPAN_API_KEY exports traces to Respan. OPENAI_API_KEY is used by the OpenAI client in this tracing-only example.
View your trace
Open the Traces page to see the named workflow and the Instructor chat span. High-level Instructor calls are named by API when context is available, such as instructor.create, instructor.create_with_completion, instructor.create_iterable, and instructor.async_create.
Configuration
InstructorInstrumentor() does not require constructor options. Activate it after RespanTelemetry is initialized.
What gets captured
Captured attributes include prompt messages, serialized output, model, token usage, provider, response schema in llm.request.functions, customer_identifier, thread_identifier, and custom metadata.
Attributes
In RespanTelemetry
Set defaults at initialization. These apply to Instructor spans exported by this telemetry instance.
With propagate_attributes
Override per request using a context scope.
Decorators
Decorators are optional for capture, but recommended for Instructor because Instructor itself does not create named workflow traces. Use @workflow to name an extraction pipeline and @task to split multi-step parsing.
Examples
Structured extraction with create
Parsed output plus raw completion
Multiple objects with create_iterable
Async create
Hooks
Instructor hooks run inside the same traced request. Use them for local diagnostics; use Respan metadata for filtering and analytics.