Pydantic in, Pydantic out, no drama.
Spoiler: the single most useful LLM library in production right now is a 1,000-line wrapper around response_model.
The Setup
Instructor patches your existing OpenAI (or Anthropic, or Mistral, or Gemini) client so chat.completions.create takes a Pydantic model and returns an instance of it. No new SDK to learn, no rewrite, no migration ticket.
pip install instructor openai
# Works the same with anthropic, mistralai, etc.The Money Pattern
Patch the client, pass a response_model, and your endpoint returns a typed object instead of a string you have to interrogate. Validation runs automatically, retries are built in, and the error messages actually tell you what went wrong.
import instructor
from openai import OpenAI
from pydantic import BaseModel, Field
class ClaimVerdict(BaseModel):
severity: str = Field(description="minor | moderate | severe")
payout_aud: float
notes: str
client = instructor.from_openai(OpenAI())
verdict = client.chat.completions.create(
model="gpt-4o-mini",
response_model=ClaimVerdict,
messages=[{"role": "user",
"content": "Claim 4821: cracked skylights, dented roof, 4217."}],
max_retries=2,
)
print(verdict.severity, verdict.payout_aud)The Catch
It leans on function calling under the hood, so smaller open-source models without solid tool support can wobble. Anthropic and OpenAI are rock solid; a 3B model running on your laptop might need Outlines instead. Pick the right tool per environment.
The Verdict
Instructor is the rare LLM library where the API never surprises you and the failure mode is "your Pydantic model was wrong." That's it. That's the whole pitch. The internet collectively lost its mind over it for a reason — it's the one that just works.