Hero Light

What is Instructor?

Instructor is a library that allows you to get structured, validated data from multiple types of inputs: text, chat messages, or images. It is powered by Large Language Models (LLMs).

The library is inspired by the Instructor for Python created by Jason Liu.

Learn More…

Feature Highlights

Instructor is designed to make it easy to process data with LLMs in PHP. Here are some of the key features of the library:

Core features

  • Get structured responses from LLM inference
  • Validation of returned data
  • Automated retries in case of errors when LLM responds with invalid data

Flexible inputs

  • Process various types of input data: text, series of chat messages or images
  • ‘Structured-to-structured’ processing - provide object or array as an input and get object with the results of inference back
  • Demonstrate examples to improve the quality of inference

Customizable outputs

  • Define response data model the way to need: type-hinted classes, JSON Schema arrays, or dynamically define your data shapes with Structures
  • Customize prompts and retry prompts
  • Use attributes or PHP DocBlocks to provide additional instructions for LLM
  • Customize response model processing by providing your own implementation of schema, deserialization, validation and transformation interfaces

Sync and streaming support

  • Receive synchronous or streaming responses
  • Get partial updates & stream completed sequence items


  • Get detailed insight into internal processing via events

Support for multiple LLMs / API providers

  • Use multiple LLM API providers (incl. OpenAI, Anthropic, Cohere, Azure, Groq, Mistral, Anyscale, Fireworks AI, Ollama, OpenRouter, Together AI)
  • Use local models with Ollama

Documentation and examples

  • Learn more from growing documentation and 50+ cookbooks

Instructor in Other Languages

Instructor has been implemented in various technology stacks. Check out implementations in other languages below:

If you want to port Instructor to another language, please reach out to us on Twitter we’d love to help you get started!