Skip to main content
LLMs are powerful, but their outputs are unpredictable. Instructor solves this.

The Problem

You’ve integrated an LLM into your PHP application. Now what?
The result? Fragile code, inconsistent data, and endless edge cases.

The Solution

Instructor gives you structured, validated, type-safe outputs:

How It Works

Instructor uses a three-step process:
  1. Define - You create a PHP class with typed properties
  2. Extract - Instructor sends your schema to the LLM with optimized prompts
  3. 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:
On validation failure, Instructor tells the LLM exactly what went wrong:

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

Same result. Zero boilerplate.

Why Not Just Use JSON Mode / JSON Schema?

“But OpenAI has response_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.
With Instructor: Direct to typed objects, including nested structures.

3. Schema Definition Hell

JSON Schema is verbose and lives separately from your code:
With Instructor: Your PHP class IS the schema.
Schema and validation rules in one place. IDE autocomplete. Type checking. Refactoring support.

4. No Validation Beyond Types

JSON Schema validates structure, not business logic:
With Instructor: Full validation with Symfony constraints.

5. No Retry Mechanism

JSON Schema mode fails silently or throws. You handle recovery:
With Instructor: Automatic retry with error feedback.

6. No Streaming Support for Structured Data

JSON Schema mode gives you complete-or-nothing:
With Instructor: Full streaming with partial updates.

7. Anthropic Doesn’t Have JSON Mode

Claude is one of the best models, but Anthropic has no native JSON mode:
With Instructor: Works seamlessly with Claude.

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
Instructor handles all of this. You define a PHP class and call ->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
Not designed for:
  • 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.