The Problem
You’ve integrated an LLM into your PHP application. Now what?The Solution
Instructor gives you structured, validated, type-safe outputs:How It Works
Instructor uses a three-step process:- Define - You create a PHP class with typed properties
- Extract - Instructor sends your schema to the LLM with optimized prompts
- Validate - Results are validated; failures trigger automatic retry with feedback
Key Benefits
1. Type Safety
Your IDE understands the response. Autocomplete works. Static analysis catches errors.2. Automatic Validation
Use Symfony Validator constraints. Invalid responses trigger automatic retry:3. Self-Correcting Retries
LLMs make mistakes. Instructor handles this gracefully:4. Provider Independence
Write once, run anywhere. Switch LLM providers without changing your code:5. Multiple Output Modes
Works with any model capability:6. Streaming Support
Get partial results as they arrive:7. Multimodal Inputs
Process text, images, and chat conversations with the same API:Comparison
Without Instructor
With Instructor
Why Not Just Use JSON Mode / JSON Schema?
“But OpenAI hasresponse_format: json_object and strict JSON Schema mode now. Why do I need Instructor?”
Good question. Here’s what you’re still stuck with:
1. Provider Inconsistency
Every provider does it differently:
With raw APIs: You write different code for each provider.
With Instructor: One API. Instructor picks the best extraction method automatically.
2. No Object Hydration
JSON Schema gives you… JSON. Not objects.3. Schema Definition Hell
JSON Schema is verbose and lives separately from your code:4. No Validation Beyond Types
JSON Schema validates structure, not business logic:5. No Retry Mechanism
JSON Schema mode fails silently or throws. You handle recovery:6. No Streaming Support for Structured Data
JSON Schema mode gives you complete-or-nothing:7. Anthropic Doesn’t Have JSON Mode
Claude is one of the best models, but Anthropic has no native JSON mode:8. The Real-World Comparison
The Bottom Line
JSON Schema mode is a step forward, but it’s a low-level primitive. You still need to:- Write provider-specific code
- Manually deserialize to objects
- Implement your own validation
- Build your own retry logic
- Handle streaming yourself
- Maintain schemas separate from code
->get().
When to Use Instructor
Great for:- Extracting structured data from unstructured text
- Building forms that accept natural language
- Processing documents (invoices, resumes, contracts)
- Content classification and tagging
- Data transformation pipelines
- Any task requiring reliable LLM output structure
- Open-ended creative writing
- Tasks where free-form text is the desired output
- Simple completions without structure requirements
The Instructor Family
Instructor exists in multiple languages with consistent APIs:Ready to get started? Jump to the Getting Started Guide or explore the Cookbook for practical examples.