Instructor

Instructor

Structured outputs from LLMs

Coding Dev Framework

What it's used for

Instructor is a library that makes LLMs return structured, validated data by using Pydantic models as output schemas. It eliminates the unreliability of parsing free-text LLM outputs by leveraging function calling, tool use, or JSON mode to get typed Python objects directly.

Key use cases include:

  • Data extraction — pulling structured information from unstructured text (emails, documents, web pages)
  • API response formatting — ensuring LLM outputs match your application's data models
  • Classification — categorizing text with validated enum values
  • Entity extraction — extracting names, dates, amounts, and relationships from text
  • Validation with retries — automatically re-prompting when outputs fail Pydantic validation
  • Streaming structured data — partial object streaming for real-time extraction

Instructor is used by developers who need reliable structured outputs from LLMs in production. Created by Jason Liu, it has become the standard for structured extraction, supporting OpenAI, Anthropic, Google, Mistral, and more.

Available in Python, TypeScript (with Zod schemas), Ruby, Go, and Elixir.

Getting started

  1. Install Instructor:
    pip install instructor
  2. Patch your LLM client and extract structured data:
    import instructor
    from openai import OpenAI
    from pydantic import BaseModel
    
    client = instructor.from_openai(OpenAI())
    
    class User(BaseModel):
        name: str
        age: int
        email: str
    
    user = client.chat.completions.create(
        model='gpt-4o',
        messages=[{'role': 'user', 'content': 'John is 30, email john@example.com'}],
        response_model=User
    )
    print(user)  # User(name='John', age=30, email='john@example.com')
  3. Works with Anthropic, Google, Mistral, and more — see python.useinstructor.com.

Pricing: Instructor is free and open source (MIT). You pay only for the LLM API calls. The library adds minimal overhead to API costs.

No case studies yet

Be the first to share a Instructor case study and get discovered by clients.

Submit a case study

Thought leaders

AI leaders using Instructor

Follow for insights, tutorials, and thought leadership

Related tools in Coding

Need a Instructor expert?

Submit a brief and we'll match you with vetted specialists who have proven Instructor experience.

Submit a brief — it's free