Introduction
PydanticAI is a Python agent framework designed to make it less painful to build production-grade applications with Generative AI. It brings the same ergonomic design and developer experience to GenAI that FastAPI brought to web development. Obiguard enhances PydanticAI with production-readiness features, turning your experimental agents into robust systems by providing:- Complete observability of every agent step, tool use, and interaction
- Cost tracking and optimization to manage your AI spend
- Access to 200+ LLMs through a single integration
- Guardrails to keep agent behavior safe and compliant
PydanticAI Official Documentation
Learn more about PydanticAI’s core concepts and features
Installation & Setup
1
Install the required packages
Generate API Key
Create a Obiguard API key with optional budget/rate limits from the Obiguard dashboard.
You can attach configurations for reliability, caching, and more to this key.
3
Configure Obiguard Client
For a simple setup, first configure the Obiguard client that will be used with PydanticAI:
What are Virtual Keys? Virtual keys in Obiguard securely store your LLM provider API keys (OpenAI, Anthropic,
etc.) in an encrypted vault. They allow for easier key rotation and budget management. Learn more about virtual
keys here.
4
Connect to PydanticAI
After setting up your Obiguard client, you can integrate it with PydanticAI by connecting it to a model provider:
Basic Agent Implementation
Let’s create a simple structured output agent with PydanticAI and Obiguard. This agent will respond to a query about Formula 1 and return structured data:F1GrandPrix
object with all fields properly typed and validated:
Advanced Features
Working with Images
PydanticAI supports multimodal inputs including images. Here’s how to use Obiguard with a vision model:Tools and Tool Calls
PydanticAI provides a powerful tools system that integrates seamlessly with Obiguard. Here’s how to create an agent with tools:Obiguard logs each tool call separately, allowing you to analyze the full execution path of your agent, including both
LLM calls and tool invocations.
Multi-agent Applications
PydanticAI excels at creating multi-agent systems where agents can call each other. Here’s how to integrate Obiguard with a multi-agent setup: This multi-agent system uses three specialized agents:search_agent
- Orchestrates the flow and validates flight selections
extraction_agent
- Extracts structured flight data from raw text
seat_preference_agent
- Interprets user’s seat preferences
With Obiguard integration, you get:
- Unified tracing across all three agents
- Token and cost tracking for the entire workflow
- Ability to set usage limits across the entire system
- Observability of both AI and human interaction points
Production Features
1. Enhanced Observability
Obiguard provides comprehensive observability for your PydanticAI agents, helping you understand exactly what’s happening during each execution.Traces provide a hierarchical view of your agent’s execution, showing the sequence of LLM calls, tool invocations,
and state transitions.
2. Guardrails for Safe Agents
Guardrails ensure your PydanticAI agents operate safely and respond appropriately in all situations. Why Use Guardrails? PydanticAI agents can experience various failure modes:- Generating harmful or inappropriate content
- Leaking sensitive information like PII
- Hallucinating incorrect information
- Generating outputs in incorrect formats
- Detect and redact PII in both inputs and outputs
- Filter harmful or inappropriate content
- Validate response formats against schemas
- Check for hallucinations against ground truth
- Apply custom business logic and rules
Learn More About Guardrails
Explore Obiguard’s guardrail features to enhance agent safety.
3. Model Interoperability
PydanticAI supports multiple LLM providers, and Obiguard extends this capability by providing access to over 200 LLMs through a unified interface. You can easily switch between different models without changing your core agent logic: Obiguard provides access to LLMs from providers including:- OpenAI (GPT-4o, GPT-4 Turbo, etc.)
- Anthropic (Claude 3.5 Sonnet, Claude 3 Opus, etc.)
- Mistral AI (Mistral Large, Mistral Medium, etc.)
- Google Vertex AI (Gemini 1.5 Pro, etc.)
- Cohere (Command, Command-R, etc.)
- AWS Bedrock (Claude, Titan, etc.)
- Local/Private Models
Supported Providers
See the full list of LLM providers supported by Obiguard.
Set Up Enterprise Governance for PydanticAI
Why Enterprise Governance? If you are using PydanticAI inside your organization, you need to consider several governance aspects:- Cost Management: Controlling and tracking AI spending across teams
- Access Control: Managing which teams can use specific models
- Usage Analytics: Understanding how AI is being used across the organization
- Security & Compliance: Maintaining enterprise security standards
- Reliability: Ensuring consistent service across all users
Enterprise Features Now Available
Your PydanticAI integration now has:- Departmental budget controls
- Model access governance
- Usage tracking & attribution
- Security guardrails
- Reliability features
Frequently Asked Questions
How does Obiguard enhance PydanticAI?
How does Obiguard enhance PydanticAI?
Obiguard adds production-readiness to PydanticAI through comprehensive observability (traces, logs, metrics),
reliability features (fallbacks, retries, caching), and access to 200+ LLMs through a unified interface. This makes
it easier to debug, optimize, and scale your agent applications, all while preserving PydanticAI’s strong type
safety.
Can I use Obiguard with existing PydanticAI applications?
Can I use Obiguard with existing PydanticAI applications?
Yes! Obiguard integrates seamlessly with existing PydanticAI applications. You just need to replace your client
initialization code with the Obiguard-enabled version. The rest of your agent code remains unchanged and continues
to benefit from PydanticAI’s strong typing.
Does Obiguard work with all PydanticAI features?
Does Obiguard work with all PydanticAI features?
Obiguard supports all PydanticAI features, including structured outputs, tool use, multi-agent systems, and more. It
adds observability and reliability without limiting any of the framework’s functionality.
Can I track usage across multiple agents in a workflow?
Can I track usage across multiple agents in a workflow?
Yes, Obiguard allows you to use a consistent
trace_id
across multiple agents and requests to track the entire
workflow. This is especially useful for multi-agent systems where you want to understand the full execution path.Can I use my own API keys with Obiguard?
Can I use my own API keys with Obiguard?
Yes! Obiguard uses your own API keys for the various LLM providers. It securely stores them as virtual keys,
allowing you to easily manage and rotate keys without changing your code.