Skip to content

PydanticAI

PydanticAI is an agent framework built by the team behind Pydantic — the most-downloaded Python validation library. Every tool call input and output is validated against Pydantic models. MCP tools inherit this type safety: the framework generates Pydantic schemas from MCP tool definitions and validates all data flowing through them.


Py
PydanticAI
Pydantic · ai.pydantic.dev
TRANSPORT
Streamable HTTP ✓
PLATFORM
Python · Framework
MCP VIA
MCP Tool Server

Type-Safe MCP Tool Calls

PydanticAI's core principle is that every piece of data entering or leaving an agent should be validated. MCP tool definitions specify parameter schemas — PydanticAI converts these into Pydantic models automatically. If the LLM generates a malformed tool call, the framework catches it before it reaches your server.

Dependency injection is the other standout feature. Your agent tools receive typed dependencies (database connections, API clients, configuration) through DI — no globals, no singletons. Clean, testable code.

Features:

  • Type-safe tools — Pydantic model validation on all inputs and outputs
  • Dependency injection — clean DI for tool dependencies
  • Structured responses — typed agent return values validated by Pydantic
  • Logfire integration — observability through Pydantic Logfire
  • Model-agnostic — OpenAI, Anthropic, Gemini, Ollama, and more
  • Streaming — typed streaming responses with validation
  • Python-first — built by the Pydantic team, idiomatic Python

Python Integration

1. Create a Token

In Vinkius Cloud, go to your server → Connection TokensCreate. Copy the URL.

2. Connect MCP Tools

python
from pydantic_ai import Agent
from pydantic_ai.mcp import MCPServerHTTP

server = MCPServerHTTP(url="https://edge.vinkius.com/{TOKEN}/mcp")
agent = Agent("claude-sonnet-4", mcp_servers=[server])
result = agent.run_sync("check server status")

3. Type-Safe Results

All tool outputs are validated. Structured responses use Pydantic models for downstream processing.


FAQ

How does PydanticAI validate MCP tool calls? It converts MCP tool schemas into Pydantic models and validates all parameters before sending the call.

What is dependency injection in PydanticAI? Tools receive their dependencies (DB connections, configs) through typed DI containers instead of global variables. This makes agents testable.

Does PydanticAI support streaming? Yes. Typed streaming responses with incremental validation as data arrives.

Is PydanticAI free? Open-source under MIT. Logfire observability has free and paid tiers.