Favicon of Instructor

Instructor

An LLM data extraction library that validates outputs with Pydantic, retries failed responses and supports local backends including Ollama and vLLM.

Screenshot of Instructor website

Instructor is a library for developers who need to turn text into structured data using an LLM. Its focus is extraction, with typed outputs that applications can use and validation rules that check the model's responses.

  • Structured extraction: Python developers can use Pydantic schemas to extract simple records, lists or nested objects, including custom rules for individual fields.
  • Validation and retries: The library checks responses against the expected schema and retries failed extractions with the validation error as feedback.
  • Streaming: Applications can receive partial objects and list items before the model finishes its response.
  • Provider portability: A shared interface supports local backends and cloud providers, with synchronous and asynchronous calls plus Python type inference and IDE autocompletion.

Local inference works through Ollama, llama-cpp-python or vLLM. Cloud connections include OpenAI, Anthropic, Google, Mistral, Cohere and DeepSeek; requests sent through those connections go to the chosen provider.

Instructor is open source under the MIT license. Implementations are available in Python, TypeScript, Go, Ruby, Elixir and Rust. Its extraction workflow doesn't provide the richer agent runtime features that the project directs users to PydanticAI for.

Similar to Instructor