Instructor Package Cheatsheet
Code-verified quick reference forpackages/instructor.
Core Flow
Create StructuredOutput
Request Configuration (StructuredOutput)
Runtime / Provider Setup
OutputMode Enum
Pipeline Overrides
Execution
PendingStructuredOutput is a lazy handle:
- no provider call happens until one of the read methods above is used
get(),response(),inferenceResponse(), andstream()coordinate one execution- mutable lifecycle bookkeeping sits behind the internal execution session, not on the facade-facing handle
- long-lived streaming state stays in the dedicated stream/state objects
StructuredOutput and PendingStructuredOutput):
PendingStructuredOutput):
Streaming (StructuredOutputStream)
lastResponse() / finalResponse() return StructuredOutputResponse.
Use ->inferenceResponse() when you need the nested raw InferenceResponse.
Response Model Helpers
Sequence
Scalar
Maybe
Output Controls
Cached Context
Examples API
Events
Testing
Deterministic test seams:Tests\Support\FakeInferenceDriver- queue sync
InferenceResponsefixtures or streamingPartialInferenceDeltabatches - best for most unit and regression tests inside
packages/instructor
- queue sync
Tests\MockHttp- builds an HTTP client around
MockHttpDriver - use when provider adapter and HTTP response shape still matter
- builds an HTTP client around
Tests\Integration\Support\ProbeStreamDriver- observation helper for streaming immediacy and call-count assertions
Tests\Support\ProbeIterator- explicit iterator helper for controlled delta emission in integration tests