Skip to main content
A comprehensive overview of Instructor’s capabilities.

Core Features

Structured Output Extraction

Define a PHP class, get a populated object back:
Key capabilities:
  • Works with any PHP class with typed properties
  • Supports nested objects and arrays
  • Handles nullable fields gracefully
  • Preserves type information throughout

Automatic Validation

Built-in support for Symfony Validator:
Validation features:
  • All Symfony validation constraints supported
  • Custom validators work out of the box
  • Validation errors trigger automatic retry
  • Error messages sent to LLM for self-correction

Self-Correcting Retries

When validation fails, Instructor automatically retries:
Retry behavior:
  1. LLM generates response
  2. Response validated against constraints
  3. On failure: errors sent back to LLM with context
  4. LLM attempts correction
  5. Repeat until valid or max retries reached

Input Flexibility

Text Input

Simple string input:

Chat Messages

OpenAI-style message arrays:

Image Input

Process images with vision-capable models:
Supported formats: JPEG, PNG, GIF, WebP

Structured Input

Pass objects or arrays as input:

Output Modes

Tools Mode (Default)

Uses LLM function/tool calling:
Best for: OpenAI, Anthropic, most modern models

JSON Schema Mode

Strict schema enforcement:
Best for: GPT-4, models with strict JSON Schema support

JSON Mode

Basic JSON response format:
Best for: Models supporting JSON mode without strict schemas

Markdown JSON Mode

Prompting-based extraction:
Best for: Models without JSON mode, fallback option

Response Types

Single Object

Arrays of Objects

Use Sequence::of() to extract lists:

Scalar Values

Extract simple types with adapters:

Enums


Streaming

Partial Updates

Get incremental results as they arrive:
Or subscribe to streaming events:

Sequence Streaming

Stream sequence items as they complete:

LLM Providers

Supported Providers

Provider Selection


Schema Definition

Type-Hinted Classes

PHP DocBlocks for Instructions

Attributes for Detailed Control

Dynamic Schemas with Structure


Advanced Features

Context Caching

Reduce costs with cached context (Anthropic):

Custom Prompts

Override default extraction prompts:
The default StructuredPromptRequestMaterializer uses Twig-backed prompt classes. Configure mode-specific prompts with modePromptClasses, retry feedback with retryPromptClass, and deserialization repair with deserializationErrorPromptClass. The legacy inline modePrompts, retryPrompt, and chatStructure settings and RequestMaterializer were removed in 2.7. When prompt classes are insufficient, implement CanMaterializeRequest and inject it through StructuredOutputRuntime::withRequestMaterializer().

Event System

Monitor internal processing:

Debug Mode

See all LLM interactions:
Outputs:
  • Full request payloads
  • Raw LLM responses
  • Validation errors
  • Retry attempts

Framework Integration

Laravel

Symfony

Standalone


Observability

Token Usage

Timing

Event-Based Logging


What’s Next