← Back to tutorials

Pydantic AI vs Instructor: Which is Better for structured LLM outputs? (2026)

Detailed comparison of Pydantic AI and Instructor for structured LLM outputs

Pydantic AI vs Instructor: Which Is Better for Structured LLM Outputs? (2026)

The short version: Instructor is the focused tool for one job — get validated, typed data out of any LLM, with automatic retries when validation fails. Pydantic AI is a broader agent framework that happens to use Pydantic for typed results, adding tools, dependencies, and multi-step agent logic. If you just want "LLM in, validated object out," reach for Instructor. If you're building a typed agent with tools and control flow, Pydantic AI.

Both are built around Pydantic models, so your schema *is* your contract either way.

At a glance

InstructorPydantic AI

ScopeStructured extractionFull agent framework Core ideaPatch the LLM client to return a modelTyped agents with tools + deps Retries on validation errorYes, built-inYes Tools / function callingMinimalFirst-class Provider supportOpenAI, Anthropic, Gemini, local, ...Model-agnostic Best for"Give me a validated object"Building typed agents

Instructor

Instructor patches your existing LLM client so a normal completion call returns a Pydantic instance — and retries automatically if the model's output fails validation.

python
import instructor
from openai import OpenAI
from pydantic import BaseModel

class User(BaseModel): name: str age: int

client = instructor.from_openai(OpenAI()) user = client.chat.completions.create( model="gpt-4o", response_model=User, messages=[{"role": "user", "content": "Extract: Jensen is 61."}], ) print(user.age) # 61, validated

It's minimal, provider-agnostic, and ideal when extraction/classification is the whole task.

Pydantic AI

Pydantic AI (from the Pydantic team) is an agent framework: define an agent bound to a model, give it a typed result, register tools, inject dependencies, and run multi-step logic — all type-checked.

python
from pydantic_ai import Agent
from pydantic import BaseModel

class User(BaseModel): name: str age: int

agent = Agent('openai:gpt-4o', result_type=User) result = agent.run_sync('Extract: Jensen is 61.') print(result.data.age) # 61

The payoff appears when you add tools and control flow — it's an agent runtime, not just an extractor.

How to choose

  • Pure extraction / classification from any provider? Instructor.
  • Smallest possible dependency for "validated output"? Instructor.
  • Building an agent with tools, dependencies, multi-step logic? Pydantic AI.
  • Want typing end-to-end across the agent? Pydantic AI.
  • If you're weighing the schema library itself, see Zod vs Pydantic for AI validation, and for the raw mechanism both rely on, OpenAI Function Calling 完全指南.

    FAQ

    Do both retry on invalid output? Yes. Both re-prompt the model with the validation error so it can correct itself.

    Can Instructor do tools/agents? Minimally. If tools and multi-step logic are central, Pydantic AI is the better fit.

    Are they OpenAI-only? No — Instructor supports many providers; Pydantic AI is model-agnostic.

    Verdict

    It's scope, not quality. Instructor does one thing extremely well: typed, validated output from any LLM with retries — perfect as a small dependency in a larger app. Pydantic AI is what you graduate to when "extract a value" becomes "run a typed agent with tools." Start with Instructor; adopt Pydantic AI when you're building agents.


    *Last updated: June 2026. Verify APIs against the Instructor and Pydantic AI docs.*

    Also available in 中文.