Skip to main content
Get structured data from LLMs in under 5 minutes.

Prerequisites

Installation

Configuration

Create a .env file in your project root with your API key:

Your First Extraction

Step 1: Define Your Data Structure

Create a PHP class that represents the data you want to extract:

Step 2: Extract Data

Use Instructor to extract structured data from text:

Step 3: Add Validation (Optional)

Use Symfony Validator attributes for automatic validation:
If validation fails, Instructor automatically retries with the LLM, providing error feedback so it can self-correct.

Using Different Providers

Switch providers by constructing StructuredOutput with the runtime you want:

Processing Images

Extract data from images using vision-capable models:

Streaming Responses

Get partial results as they arrive:

Next Steps

You now have the basics. Here’s where to go next:

Common Patterns

Extract Multiple Items

Add Context with System Messages

Set Max Retries


Need help? Check out the Cookbook for 60+ working examples, or open an issue on GitHub.