



Python library for extracting structured, type-safe data from Large Language Models with automatic validation, retries, and streaming support. Built on Pydantic with over 3 million monthly downloads.
Instructor is the most popular Python library for extracting structured data from Large Language Models (LLMs), with over 3 million monthly downloads, 11k+ GitHub stars, and 100+ contributors. It patches the OpenAI Python SDK to add a response_model parameter that maps LLM outputs to Pydantic models.
pip install instructor # OpenAI by default
pip install "instructor[anthropic]" # For Claude
pip install "instructor[google-genai]" # For Gemini
import instructor
from pydantic import BaseModel
class User(BaseModel):
name: str
age: int
client = instructor.from_provider("openai/gpt-4o-mini")
user = client.chat.completions.create(
response_model=User,
messages=[{"role": "user", "content": "John is 25 years old"}],
)
print(user) # User(name='John', age=25)
Free and open-source under the MIT license.
Loading more......