PydanticAI

PydanticAI Integration

Pass getPydanticAIConfig() to your agent's instrument parameter. Full observability for PydanticAI agents with zero restructuring.

PydanticAI is a Python agent framework built by the Pydantic team, providing type-safe structured outputs, dependency injection, and multi-model support.

zespan.com — pydanticai trace
Zespan trace showing a PydanticAI agent run with tool calls and structured output

Getting Started

1

Install the SDK

Install the Zespan Python SDK alongside pydantic-ai.

bash
pip install zespan pydantic-ai
2

Add the instrumentation config

Call get_pydantic_ai_config() and pass the result to your agent's instrument parameter. All LLM calls, tool uses, and dependency injections are traced.

python
from zespan.sdk import get_pydantic_ai_config
from pydantic_ai import Agent

config = get_pydantic_ai_config(api_key="your-api-key")

agent = Agent(
    'openai:gpt-4o',
    instrument=config,
    system_prompt='You are a helpful assistant.',
)

result = await agent.run('What is the capital of France?')
3

View traces in Zespan

Open Trace Explorer. PydanticAI agent runs appear with the full execution — LLM calls, tool invocations, and structured output parsing.

What's captured automatically

  • Native PydanticAI integration: instrument parameter format matches exactly
  • All PydanticAI model providers: OpenAI, Anthropic, Gemini, Groq, Ollama
  • Tool calls: PydanticAI tool invocations as child spans with arguments and results
  • Structured output: raw model output and Pydantic-parsed result both captured
  • Dependency injection: context visible in traces so you understand how deps shape behavior

FAQ

Does this work with all PydanticAI model providers?

Yes. get_pydantic_ai_config() returns a provider-agnostic config. OpenAI, Anthropic, Gemini, Groq, and Ollama models are all traced.

Can I use this with PydanticAI's structured output mode?

Yes. Both the raw model output and the Pydantic-parsed result are captured in the trace, so you can see schema validation failures as well as successful structured responses.

Start for free — 10K traces/month, no card needed

PydanticAI integration works on all plans including the free tier.

← All integrations