What You Gain
Response Models Replace Manual Parsing
Without Instructor, extracting structured data from an LLM means defining verbose function-call schemas, parsing JSON responses, and mapping fields to your domain objects by hand. With Instructor, you write a plain PHP class and let the library derive the schema, call the model, and hydrate the result automatically. Your code becomes simpler and easier to reason about. The response model is the documentation of what you expect.Validation Before You Trust The Data
LLM output is probabilistic. A model might return a malformed email address, a negative age, or a value outside an expected set. Instructor validates every response against your rules before returning it. Validation uses Symfony validation attributes, so you can apply the same constraints you already use in the rest of your PHP application:#[Assert\Callback]
annotation. This lets you enforce cross-field rules, business logic, or any constraint
that goes beyond simple attribute checks:
Self-Correcting Retries
When validation fails, Instructor does not simply throw an exception. If retries are configured, it sends the validation errors back to the LLM as context and asks it to try again. The model sees exactly which fields failed and why, giving it a strong signal for correction.Streaming Without Changing The Request Shape
You can stream partial results as the LLM generates tokens. The request definition stays the same — you simply read the result differently:Sequence wrapper combined with stream()->sequence() yields
each completed item as soon as it is ready, so your application can begin processing
before the full response arrives.
A Provider-Agnostic API
Instructor works with OpenAI, Anthropic, Google, Azure, and other providers through the Polyglot inference layer. Switching providers is a configuration change, not a code rewrite:The Workflow At A Glance
Working with Instructor follows a consistent three-step pattern. Step 1: Define the data model. Create a PHP class with typed public properties that maps to the information you want to extract:StructuredOutput:
When Instructor Is A Good Fit
Instructor works well when you need to:- Extract structured records from unstructured text (emails, documents, chat logs)
- Classify or label content into predefined categories
- Transform one structured format into another via an LLM
- Generate data that must conform to a strict schema
- Build pipelines where the output of one LLM step is the typed input to the next