NOTES / FRAMEWORKS AND SDKS

Pydantic AI

A Python agent framework from the Pydantic team: agents generic over dependencies and output types, validated structured output, and typed dependency injection for testing.

UPDATED 18 NOV 2026#pydantic-ai#python#type-safety#structured-output

The idea

Pydantic AI aims to bring the ergonomics of FastAPI and Pydantic to agent development. Its documentation describes agents as generic in the type of dependencies they accept and the type of result they return, so a support agent for a bank can be typed as an Agent over its dependencies and its output model1.

Diagram: an Agent generic over Deps and Output with typed dependencies, tools receiving a run context, and validated output

Diagram: my own.

What stands out

From the docs1:

  • Validated structured output. The agent must return an output type you define, and Pydantic validates it. Responses can be streamed with validation of streamed structured data.
  • Type-safe dependency injection. Dependencies such as a database connection are passed in through a run context, and the docs note this is useful for unit tests and eval-driven iteration. If a type annotation is wrong, static type checkers catch it.
  • Tools as ordinary functions, with schemas generated from their signatures and typed access to dependencies.
  • Model-agnostic support for many providers.
  • Observability through the project’s Logfire product, or any OpenTelemetry-compatible backend2.

The project also lists evaluation support, MCP integration and graph-based workflows among its features2. Check the current docs for the exact set, since this area moves quickly.

Why types help agents

Agents sit between nondeterministic models and deterministic code, and the boundary is where bugs live. Typed outputs turn “the model returned something odd” into a validation error you can handle by retrying with the message (Structured outputs). Typed dependencies make it easy to fake a database or API in tests, so you can run your agent logic without live calls. That helps building eval sets that run in CI.

Strengths and trade-offs

My assessment:

  • Strengths: clean fit for Python teams who value static typing and testability, strong structured-output story, small mental model.
  • Watch for: it is Python-only; it focuses on the agent and typing rather than on a durable runtime, so for long-lived approval-gated workflows compare with LangGraph; and fast-moving versions mean API drift.
  • Fit: data extraction and typed back-end agents, services that must return validated objects, and teams already using Pydantic or FastAPI.

Tips

  1. Define the output model first; it clarifies what the agent must produce.
  2. Keep tool functions small and typed, and return compact results (Tool design).
  3. Inject dependencies instead of using globals so tests can substitute fakes.
  4. Add output validators for business rules that types cannot express.
  5. Trace runs and keep a regression eval set.

Compare options in Choosing a framework.

Sources

  1. [1]Pydantic AI — PydanticPARAPHRASED
  2. [2]Pydantic AI documentation index — Pydantic, GitHubPARAPHRASED

© Ashish Kumar. All rights reserved. Quoted and cited material belongs to its owners. How I attribute sources.

Product, company and framework names are trademarks of their respective owners. Mentioning them does not imply affiliation or endorsement.