Pydantic AIPydantic AI 2.51 · Python 3.10+
Dashboard
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
29 small wins to finish your pathNext lesson →

Pydantic AI logoPydantic AI overview

Pydantic AI is the Pydantic team's agent framework that brings type-checked, validated output to language model apps.

Last updated: 28 Sep, 2026 · Pydantic AI 2.51

It is built by Pydantic, the company behind the Pydantic validation library that many model SDKs already depend on, and it is released under the MIT licence. This course uses pydantic-ai-slim 2.51.0 and builds one program throughout: a support desk agent that looks up orders and asks a person before large refunds.

What Pydantic AI is for

An Agent holds a model, its instructions, its tools and the type of answer you want back. You describe the answer with ordinary Python type hints, and Pydantic checks the model delivered it. When the model gets it wrong, the validation error is sent back to the model to fix, so your code receives a checked object rather than free text.

How an agent runs

You give the agent a prompt; it sends the prompt to the model; the model may ask to call a tool you wrote; the agent runs the tool and sends the result back; the model then writes the final answer. The whole exchange is kept as a list of messages you can print.

One agent run
ticketresultanswererror, try againYour coderun_sync(ticket)Agenttools and output typeThe modeltext or a tool calllookup_orderyour Python functionPydanticchecks the answer
Hover or tap a piece to see what it is and which lesson built it.
Trace a run

Pick one to watch it run, step by step.

What you will build

A support desk agent that sorts a ticket into a typed record, looks an order up with a tool, reads per-run dependencies such as the current customer, retries when validation fails, and stops for human approval before a large refund. Each lesson adds a few lines, runs them and reads the result.

Everything in this course, and where it is going
Your first agentTyped outputTools and dependenciesConversations and controlTesting and evalsa first runrequests and responsesa stand-in modelstructured outputvalidation retriesoutput validatorsfunction toolsdependenciesusage limitsmessage historyapproval before a refundagents calling agentspytestevalsthe ticket desk
Hover or tap a piece to see what it is and which lesson built it.

A Python function as the model

Pydantic AI lets a plain Python function take the place of the model. In FunctionModel: write a stand-in model you write one that sorts tickets by keyword rules, so every answer traces back to a rule you can read and no API key is needed. Real models: providers, keys and model names shows the single line that swaps that function for a hosted model.

Where you use Pydantic AI

  • Turning a model's reply into a validated object your code can trust.
  • Agents that call your Python functions as tools and read per-run context.
  • Flows that retry on bad output and pause for a human before a costly action.
  • Handing work between several agents, or to the tools of an MCP server.

Advantages and limits

  • Advantage: the answer is a checked Pydantic object, so a wrong shape is caught before it reaches your code.
  • Advantage: tools, dependencies, retries, streaming and human approval are part of the framework.
  • Advantage: one model-agnostic API reaches OpenAI, Anthropic, Google, Groq and more.
  • Limit: for a single free-text call with no validation, calling a provider SDK directly is lighter.
  • Limit: you work in terms of typed output and tools, a small shift over ad-hoc string handling.

Prerequisites

Back toAll frameworks

Every expert started right here.