MintMCP
August 12, 2026

Pydantic AI: The Agent Framework Explained

Skip to main content

Production AI agents fail silently when LLM outputs don't match expected schemas. A single malformed JSON response at 2 AM can crash an order processing pipeline, corrupt customer records, or trigger cascading failures across dependent systems. Pydantic AI reduces this risk by validating configured structured outputs and retrying failed validation within a configurable retry budget, then raising an error if the output still does not match the schema. For enterprises deploying these agents at scale, the framework handles output validation while MCP Gateway provides the governance layer for secure data access, authentication, and audit trails that production environments require.

This article explains how Pydantic AI works, when to use it, its core capabilities, and how enterprise teams can deploy type-safe agents with proper governance infrastructure.

Key Takeaways

  • Pydantic AI supports validation-first design: if a structured LLM output doesn't match your Pydantic model, it can retry with validation feedback up to the configured retry limit, then raise an error instead of silently passing malformed data downstream
  • The framework reached v1.0 stable in September 2025 and moved to stable V2 in June 2026, built by the team behind Pydantic
  • Multi-provider support spans 20+ LLM providers including OpenAI, Anthropic Claude, Google Gemini, AWS Bedrock, Groq, and Ollama
  • Native MCP support enables agents to connect to external data sources, requiring enterprise governance for production deployments
  • Enterprise gaps exist: no built-in RBAC, audit trails, or compliance tooling; production deployments need a platform layer for governance
  • Practitioner case-study results cite 94% accuracy in document classification and 38% auto-resolution rates in support triage; these are self-reported client examples rather than independent benchmarks
  • Cost structure: framework is free (MIT license); Logfire observability has a free Personal tier, a $49/month Team tier, a $249/month Growth tier, and custom-priced Enterprise plans; hidden costs include LLM tokens and platform layer engineering

Understanding AI Agent Frameworks: What is Pydantic AI?

Pydantic AI is a Python agent framework from the Pydantic team that brings type-safe, structured outputs to AI agent development. Pydantic AI supports both plain-text and structured outputs. When you configure a structured output type, the framework validates the model response before returning it to your application code.

Core Design Principles

  • Structured outputs: Configured structured responses can be validated against Pydantic models or other supported typed output definitions before reaching your application code
  • Dependency injection: Pass database connections, API clients, and user context into tools without global state
  • Async-first architecture: Native async/await support for high-throughput production services
  • Model-agnostic: Works with OpenAI, Anthropic, Google Gemini, AWS Bedrock, Groq, Ollama, and other providers through a unified interface

The framework emerged from real production pain. Teams using LLMs in critical workflows discovered that unstructured outputs caused downstream failures. A customer inquiry classifier returning "urgent" instead of the expected integer urgency score crashes the routing logic. An order processor receiving malformed JSON corrupts the database. Pydantic AI reduces these failure modes by validating configured structured outputs and surfacing failures when the retry budget is exhausted.

For enterprises connecting agents to internal systems, the Model Context Protocol provides the data access layer. Pydantic AI includes built-in MCP support, enabling agents to query databases, access CRM systems, and interact with internal tools. However, production MCP connections often need governance beyond the agent framework itself, including authentication, access control, and audit logging. This is where enterprise MCP gateways can provide a centralized control layer.

Pydantic AI Agents: Examples and Real-World Applications

Type-safe agents deliver measurable business outcomes when deployed against well-defined use cases. The following examples demonstrate how production implementations generate ROI through accuracy improvements and automation gains.

Problem: A legal tech startup classified inbound contracts using keyword matching with 200 rules, with 67% accuracy.

Implementation: Pydantic AI agent with a DocumentClassification output type enforcing type enum, jurisdiction string, risk_flags list, and confidence float. Bedrock Claude Haiku 4.5 as the underlying model.

Results: 94% accuracy, under 2-second processing per document, and automatic human review for confidence scores below 0.8.

E-Commerce Support Triage

Problem: 800-1,200 tickets daily with 40% being standard order status inquiries that consumed agent time.

Implementation: Agent with tools for order lookup, shipping API queries, and CRM history retrieval. TriageResult model enforcing action enum, response_draft, confidence, and escalation_reason. Dependency injection passed customer context per request.

Results: 38% auto-resolution rate, with 96% customer satisfaction on auto-resolved tickets.

CRM Lead Scoring

Problem: Sales agents manually reviewed 200+ leads weekly with inconsistent scoring quality across the team.

Implementation: Agent scoring leads using property interest lookup and market data tools. LeadScore model enforcing score (0-100), tier enum, reasoning string, and recommended_actions list.

Results: Automated scoring on new leads and weekly rescoring of the existing pipeline; the cited source does not report quantified response-time improvements.

These implementations share a pattern: structured output schemas that match downstream system requirements, tools that connect agents to authoritative data sources, and validation logic that prevents malformed outputs from reaching production systems.

Pydantic AI agents become useful when they can access external systems. The tool system lets you turn Python functions into LLM-callable capabilities with automatic argument validation.

Tool Registration Pattern

@agent.tool

async def lookup_customer(ctx: RunContext[Deps], email: str) -> dict:

"""Get customer account details from CRM"""

return await ctx.deps.crm_client.get_customer(email)

The @agent.tool decorator registers the function, and the LLM receives the docstring as the tool description. Arguments are validated against their type hints. The ctx.deps pattern injects your database clients, API connections, and configuration without polluting global state.

MCP Integration for Enterprise Data Access

Pydantic AI includes native MCP support for connecting agents to external data sources through the Model Context Protocol. This enables agents to access databases, SaaS applications, and internal systems through standardized interfaces.

For enterprise deployments, MCP connections require governance infrastructure:

  • Authentication: SSO and identity forwarding to ensure agents act on behalf of authorized users
  • Access control: Tool-level permissions that restrict which data sources each agent or user can query
  • Audit logging: Complete records of every tool call, prompt, and response for compliance
  • Credential management: Secure handling of OAuth tokens and API keys without hardcoding secrets

MintMCP's security governance capabilities address these requirements through centralized policy enforcement and credential brokering. Teams building Pydantic AI agents that connect to sensitive data sources through MCP can use this governance layer to centralize access controls, credential handling, and auditability.

Ecosystem Integrations

The framework connects to durable execution platforms for fault-tolerant long-running workflows:

  • Temporal: Workflow checkpointing with automatic retry and recovery
  • DBOS: Database-backed durable execution
  • Prefect: Workflow orchestration with built-in retry logic
  • Restate: Event-driven durability patterns

Building AI Agents: From Python Libraries to Enterprise Solutions

Getting a Pydantic AI agent running locally takes minutes. Getting it production-ready takes planning.

Basic Setup Sequence

Step 1: Install the framework

pip install pydantic-ai

# Or with AWS Bedrock support

pip install "pydantic-ai[bedrock]"

Step 2: Define your output schema

from pydantic import BaseModel

class CustomerInquiry(BaseModel):

category: str # 'billing', 'support', 'sales'

urgency: int # 1-5

summary: str

Step 3: Create the agent

from pydantic_ai import Agent

agent = Agent(

'anthropic:claude-haiku-4-5',

output_type=CustomerInquiry,

instructions='Classify customer inquiries accurately.'

)

Step 4: Run the agent

result = agent.run_sync('Customer emailed about overcharge')

print(result.output.category) # Type-safe access

Production Considerations

Validation retry management:

The default retry count is 1. In production, set explicit limits where needed and handle failures:

from pydantic_ai import UnexpectedModelBehavior

try:

result = agent.run_sync(user_input, retries=2)

except UnexpectedModelBehavior:

# Route to human review

pass

Monitor result.usage().requests across sample runs. Treat elevated request counts as a signal to review your prompt or schema.

Token cost awareness:

Repeated validation failures can materially increase token usage because each retry adds another model request. Keep tool docstrings under 50 words since they're sent to the LLM on every call.

AWS Bedrock streaming:

Earlier Pydantic AI versions had a Claude-on-Bedrock limitation where structured tool output could arrive as one buffered chunk. That issue has since been closed, and current structured streaming behavior depends on the Claude model and Bedrock configuration.

LLM Agent Frameworks: The Foundation for Advanced AI Agents

Pydantic AI sits in a category of LLM agent frameworks alongside tools like LangChain, LangGraph, and CrewAI. Each framework makes different tradeoffs.

When to Choose Pydantic AI

  • Type-safe outputs are non-negotiable for your use case
  • Your team has Python/FastAPI experience and prefers explicit over implicit
  • You're building agents inside Python services where IDE support matters
  • Output validation failures should be caught at the framework level, not in application code

When to Consider Alternatives

  • You need 700+ pre-built integrations and rapid prototyping (LangChain's strength)
  • You prefer LangGraph's graph-centric orchestration model or its ecosystem for complex stateful workflows
  • Role-based multi-agent orchestration with minimal code (CrewAI's strength)

Framework-Level Gaps for Enterprise

Regardless of which agent framework you choose, the framework itself doesn't provide:

  • Role-based access control (RBAC)
  • Audit trails that meet compliance requirements
  • Multi-tenant deployment with isolation
  • Centralized credential management
  • Shadow AI detection for agents running outside governed infrastructure

These capabilities require a platform layer. For organizations deploying agents that access sensitive data through MCP, MintMCP provides the agent identity and governance infrastructure that frameworks don't include.

Security and Governance in AI Agent Deployments

Pydantic AI validates outputs. It doesn't govern access.

What the Framework Provides

  • Type validation ensuring outputs match schemas
  • Dependency injection for passing credentials without hardcoding
  • OpenTelemetry integration for observability export

What Enterprises Need Beyond the Framework

RequirementFramework CapabilityEnterprise Need
AuthenticationNone built-inSSO, SAML, identity forwarding
Access controlApplication-level onlyTool-level permissions, RBAC
Audit loggingLogfire tracesImmutable compliance records, SIEM export
Credential managementDeveloper responsibilityOAuth brokering, automatic rotation
PII detectionNoneInline DLP, masking
Shadow AINoneOff-gateway activity detection

For teams building enterprise AI agents, the governance layer is as important as the agent framework itself. An agent that can query customer databases needs the same access controls that apply to human users accessing those systems.

MintMCP's approach treats governance as foundational rather than an afterthought. The platform starts from data permissions (SSO, SCIM groups, tool-level policy, audit) and enables agents on top, ensuring agent access is always a subset of an already-governed permission model.

Compliance Considerations

Logfire Enterprise offers SOC 2 Type II audited status and support for HIPAA compliance standards for observability data. However, the agent framework itself and MCP connections require additional governance infrastructure to meet enterprise compliance requirements.

Advanced Governance: Bundles and Enterprise Architecture

Enterprise agent deployments require governance units that bundle permissions, policies, and audit trails together. Manual configuration of separate access rules, credential objects, and logging destinations doesn't scale.

The Bundle Architecture Pattern

MintMCP's Bundle model packages tool access, policy enforcement, and audit logging into single governance units per team or role. Each Bundle ties:

  • SCIM group membership to authorized users
  • Curated MCP server lists to available tools
  • Custom policy rules to enforcement logic
  • Isolated audit trails to compliance records

This abstraction simplifies agent deployment. Instead of configuring access rules, credentials, and logging separately for each agent, administrators define a Bundle once and apply it to teams or agent identities.

Agent Bundles for Non-Human Principals

When agents operate autonomously, they need their own identities. Agent Bundles extend the model to give each deployed agent:

  • Rotatable credentials independent of creator's access
  • Scoped permissions matching the agent's specific function
  • Audit attribution showing exactly what each agent accessed

This addresses a critical enterprise concern: agents running with shared service account keys create audit gaps and security risks. Per-agent identity with scoped credentials enables proper attribution and least-privilege access.

Monitoring and Observability for AI Agents

Production agents require monitoring beyond application-level logging.

Pydantic AI Observability Options

  • Pydantic Logfire: Native OpenTelemetry integration with tiered pricing: Personal is free, Team is $49/month, Growth is $249/month, and Enterprise is custom-priced
  • Third-party export: OpenTelemetry traces export to Datadog, New Relic, or existing observability stacks

Enterprise Monitoring Requirements

For organizations with AI agent security requirements, observability extends beyond traces:

  • Real-time visibility: Watching agent actions as they happen, not after the fact
  • Off-gateway detection: Identifying MCP calls made outside governed infrastructure
  • PII exposure alerts: Flagging when agents access or generate sensitive data
  • Prompt injection detection: Catching attempts to manipulate agent behavior
  • Credential leakage monitoring: Detecting API keys or tokens in agent outputs

MintMCP's Agent Monitor provides this layer through hooks in Claude Code and Cursor, detecting activity that bypasses the gateway entirely. MDM integration enables push of detection policies to developer machines for consistent enforcement.

Metrics to Track

  • result.usage().requests: Average should be low; elevated counts indicate prompt/schema issues
  • Token consumption per tool: Identify expensive operations
  • Validation failure rate: Track recurring failures as a signal to review prompt design, output schemas, or model behavior
  • Response latency by provider: Monitor for degradation

Pydantic AI vs. Agentic AI: Distinguishing Key Concepts

Pydantic AI is an agent framework. Agentic AI is an architectural pattern. Understanding the distinction clarifies where each fits.

Agentic AI Characteristics

  • Autonomous operation with goal-oriented behavior
  • Multi-step reasoning with tool use
  • Memory and context management across interactions
  • Self-correction based on feedback

Pydantic AI's Role

Pydantic AI provides the runtime for building agentic systems with type safety. It handles:

  • Structured communication with LLMs
  • Tool registration and invocation
  • Output validation and retry logic
  • Dependency injection for stateful operations

What Pydantic AI Doesn't Provide

  • Fully managed multi-agent orchestration: Pydantic AI supports agent delegation, programmatic handoffs, and graph-based multi-agent control, while deployment and governance remain separate concerns
  • Persistent memory is available through Pydantic AI Harness, while applications remain responsible for choosing and operating the backing storage and broader memory governance model
  • Enterprise governance (requires platform layer)
  • Voice or channel integration (requires custom development)

The Infrastructure Layer

For enterprises deploying agentic systems, the agent framework is one component. The full stack includes:

  • LLM provider: OpenAI, Anthropic, Google, or others
  • Agent framework: Pydantic AI, LangGraph, or alternatives
  • Data access layer: MCP connections to enterprise systems
  • Governance layer: Authentication, authorization, audit
  • Orchestration layer: Multi-agent coordination, human-in-the-loop

MintMCP positions its MCP Gateway as the governance and data access layer between agent frameworks and enterprise systems, while its Agent Gateway builds on that foundation with agent identities, permissions, memory, and monitoring. Teams using Pydantic AI for type-safe agent development can layer MintMCP's MCP Gateway on top for governed tool and data access, then apply Agent Gateway controls for deployed agent identities and oversight.

Production Deployment: From Framework to Governed Infrastructure

Pydantic AI gives you type-safe agent runtime. Production deployment requires the governance, monitoring, and credential infrastructure that frameworks don't provide.

MCP Gateway for governed data access:

When your Pydantic AI agents connect to internal systems through MCP, MCP Gateway centralizes authentication, tool-level permissions, and audit logging. Instead of embedding database credentials in agent code or managing per-developer OAuth tokens manually, the gateway brokers access through SSO-backed identity, applies tool-level policy, and logs every agent action for compliance. Teams deploy agents with confidence that data access follows the same governance model applied to human users.

Agent Gateway for autonomous agent control:

For agents that operate autonomously, hold memory across sessions, or run as persistent services, MintMCP's Agent Gateway provides the identity, permission, memory, and monitoring layer. Each agent receives its own rotatable credentials, scoped permissions matching its function, and dedicated audit trail. Agent memory is company-owned, versioned, reviewable, and portable, following Git-like principles rather than opaque vendor storage. Real-time monitoring detects off-gateway activity, prompt injection attempts, and PII exposure before they reach production systems.

Why governance matters for AI agents:

The framework validates outputs. The governance layer validates access. Production AI agents need both. MintMCP's approach starts from data permissions and builds agent capabilities on top, ensuring every agent action is a governed, auditable event within an already-secured permission model. This eliminates shadow AI risk, meets compliance requirements, and scales governance across teams without manual credential management or ad-hoc access rules per agent.

Frequently Asked Questions

What Python version does Pydantic AI require and what are the system dependencies?

Pydantic AI requires Python 3.10 or higher. The framework has minimal system dependencies since it's built on Pydantic for validation and httpx for async HTTP. For AWS Bedrock support, install with the bedrock extras: pip install "pydantic-ai[bedrock]". The framework runs on any platform that supports Python, including Linux, macOS, and Windows, with no native code compilation required.

How do validation retries affect token costs and how can I control them?

Validation retries increase token costs because each retry sends the full prompt plus the validation error feedback to the LLM. On repeated schema mismatches, costs can rise because each retry adds another model request. Control this by setting explicit retry limits with the retries parameter (recommend retries=2 for production), monitoring result.usage().requests to identify problematic prompts, refining schemas when request counts are elevated, and catching UnexpectedModelBehavior exceptions to route failures to human review rather than excessive retry loops.

Can Pydantic AI agents maintain state across multiple interactions?

Pydantic AI agents do not automatically persist conversational state between standard agent.run() calls. For multi-turn conversations, you can pass message history explicitly. For persistent state across sessions, Pydantic AI Harness now provides a Memory capability with file, SQLite, and Postgres-backed storage options. Applications can also store conversation history separately or use durable execution integrations such as Temporal, DBOS, and Prefect for workflow state.

How does Pydantic AI compare to using OpenAI's native function calling or Anthropic's tool use?

Pydantic AI adds a provider-agnostic validation and agent-runtime layer on top of native model capabilities. OpenAI Structured Outputs can enforce JSON Schema conformance, and Anthropic supports strict tool use for schema-conformant tool calls. Pydantic AI provides a consistent typed interface, retry and validation behavior, tool registration, dependency injection, and cross-provider abstractions in Python. The tradeoff is additional framework abstraction and, when retries occur, additional token usage in exchange for consistent validation behavior across providers.

What's the migration path from LangChain to Pydantic AI?

Migration involves rewriting agent logic rather than data migration. LCEL chains become typed agents with output_type definitions. Output parsers become Pydantic models. Custom callbacks become tool decorators with dependency injection. Plan for 2-4 weeks per 10 agents of moderate complexity. The main adjustment is moving from LangChain's implicit behavior to Pydantic AI's explicit typing. Teams report the migration is worthwhile when type safety and IDE support are priorities, but LangChain remains better suited for rapid prototyping with its larger integration ecosystem.

MintMCP Agent Activity Dashboard

Ready to get started?

See how MintMCP helps you secure and scale your AI tools with a unified control plane.

Sign up