· 5 min read
Pydantic AI: Type Safety for People Who Actually Ship
The Pydantic team's bet on what an agent framework should have looked like from the start.
If you've shipped any non-trivial Python service in the last three years, Pydantic is already in your dependency tree. It's the validation library FastAPI is built on, the schema layer holding together half of every modern Python codebase, and the reason "parse, don't validate" stopped being a debate and started being default practice. The Pydantic team spent the agent framework boom watching the entire ecosystem get built on a foundation their library was already providing, and they decided to ship the framework they thought everyone else should have shipped first. Pydantic AI is the result, and what makes it interesting is not the new things it adds but the abstractions it refuses to reinvent.
The first thing you notice is that the framework treats Python as the abstraction layer rather than the implementation language. An agent is a Python class whose generic parameters are the dependency type and the result type, instantiated with a model identifier string, a system prompt, and the type signatures. The static type checker knows what your agent returns before any model call runs, and dependencies thread into your tools and result validators through a RunContext parameter the framework constructs for you. There is no DI container, no decorator-based service registration, no separate context-object abstraction layer to memorize. The function signature is the contract, and the contract is enforced at compile time by the same tooling that already polices the rest of your codebase.
Tools follow the same logic. You decorate a regular Python function with @agent.tool, and the function's type hints become the tool schema, the docstring becomes the description the model reads, and the return type becomes the value the model gets back. Pydantic does the schema generation, so anything Pydantic can validate, the tool can accept as a parameter or return as a result. That's the part most other frameworks pretend to deliver and then leak through with a half-finished JSON schema bridge. Here, the same library validating your HTTP request bodies in FastAPI is generating the tool schemas your agent uses, and the same domain models you already wrote become the structured outputs your agent returns. The reuse is real, not aspirational.
The piece I find most underrated is result validation. When the model returns a structured response, Pydantic checks more than the shape. You can attach result validators that run business logic against the parsed result, and if the validator raises, the framework feeds the failure back to the model and asks for another attempt with a structured error describing exactly what went wrong. This is the closest any framework has come to making "if the output is wrong, ask again" a first-class control flow primitive instead of a retry loop you write yourself. Most production agents reinvent this badly the first time, and worse the second. Pydantic AI ships it as a default behavior of the result-typed agent.
The multi-agent story is honest. There is no role-based team-of-agents abstraction in the CrewAI mold and no graph-based orchestration in the LangGraph mold. What you have is the ability to call one agent from inside another agent's tool, with the calling agent's RunContext available to the called one. This is closer to the Unix philosophy of agent composition: a delegating agent is a function that calls another agent, and the orchestration model is whatever you write in Python. For teams that want explicit control flow over implicit framework magic, this lands well. For teams that want a framework to make hierarchy decisions for them, it will feel underdone, and that critique is fair.
Pydantic-evals ships as a separate package, and the design decision is correct. Evaluations are not part of the agent definition; they're a parallel system that exercises agents against datasets, scores results with custom or LLM-graded evaluators, and produces structured reports you can diff between runs. The same Pydantic types you used to define agent results are the types the eval harness understands without any translation layer. The split between framework and eval tool that Mastra closed by bundling, Pydantic AI closes by sharing the type system. Both choices are defensible, and the Pydantic AI version means your eval suite stays portable if you ever swap the framework underneath it.
Observability is where the commercial story lives. The framework has clean OpenTelemetry support, though Logfire is the team's own paid product and the integration is tighter than anything else in the Python ecosystem right now. You point your agent at Logfire and you get traces of every model call, tool invocation, and result validation, threaded through with the same span context as the rest of your service. The free tier is generous enough to use in real projects, and the paid tier is priced like a developer tool rather than an enterprise platform. The honest framing is that Pydantic AI is open source and Logfire is the part that funds the team. If you don't want to send traces to Logfire, OpenTelemetry to your existing collector works without ceremony; if you do, the experience is the cleanest you'll find in this corner of the stack.
Where the framework chafes is exactly where you'd expect a young, opinionated project to chafe. The community tool ecosystem is thinner than LangChain's or LlamaIndex's, which means more integrations you'll write yourself the first time you need them. The MCP support is solid but newer than the rest of the surface, and the patterns for production-scale MCP server orchestration are still settling in this codebase faster than anyone has documented them. The streaming API is excellent for chat-style UIs and slightly awkward for stream-into-result patterns where you want to consume tokens incrementally and return a validated object at the end. None of this is a deal-breaker. All of it is the kind of friction you'd expect from a framework that prioritized correctness over feature surface area, and accepting that trade is the whole point of picking it.
The decision framework lands cleanly. If your service is already Python, already uses Pydantic, and you want an agent framework whose primitives compose with the rest of your codebase instead of fighting it, Pydantic AI is the default I would reach for. If you want a graph-based orchestration model with explicit state machines, LangGraph is the better fit. If you want role-based multi-agent out of the box, CrewAI handles that better. If you want a single framework that bundles workflows, RAG, and evals into one decision, Mastra in TypeScript or one of the heavier Python options will serve you well. Pydantic AI is the framework you pick when you want the agent layer to feel like idiomatic Python rather than a new abstraction stack imported alongside it.
The most interesting thing about Pydantic AI is the question it forces other frameworks to answer. If your validation layer, your serialization layer, your config layer, your API layer, and now your agent layer all run on the same primitive, what does that say about the abstractions other frameworks are charging you to learn? The Pydantic team's bet is that the answer is "less than you've been told." Six months of production teams putting that bet to work is starting to suggest they're right, and the frameworks still selling their own type system instead of using the one already in your dependency tree should probably be paying attention before the next CTO who has to choose between them stops pretending the comparison is close.