---
title: How do you govern agents built with Pydantic AI?
url: https://opencontroller.lyzr.com/blog/govern-pydantic-ai-agents
published: 2026-11-13
updated: 2026-11-13
author: Lyzr
---

# How do you govern agents built with Pydantic AI?

**Use Pydantic AI's built-in controls inside each agent: typed outputs, OpenTelemetry traces, per-run usage limits and approval for risky tools. Then add what a framework cannot give you: a registry entry with an owner, a workload identity per agent, model traffic through a gateway, production scoring and a tested way to stop the agent.**

Pydantic AI is an open-source Python framework from the team behind Pydantic. Engineers like it because agents are plain, typed Python. That also makes it easy for agents to appear without anyone in security knowing. This guide covers both sides.

## Which Pydantic AI features help governance?

| Feature | What it does | Governance use |
|---|---|---|
| Typed outputs | Validates the model's output against a schema; retries on failure, then raises `UnexpectedModelBehavior` | Downstream systems never get malformed data |
| Instrumentation | `Agent.instrument_all()` or the `Instrumentation` capability emits OpenTelemetry traces | Audit trail of model and tool calls |
| Logfire integration | `logfire.instrument_pydantic_ai()` sends traces to Pydantic Logfire | Quick start for tracing |
| Usage limits | `UsageLimits` caps a run, for example `request_limit` and `tool_calls_limit`; raises `UsageLimitExceeded` | Stops runaway loops and cost spikes |
| Tool approval | `requires_approval=True` ends the run with `DeferredToolRequests`; resume after a decision | Human review for high-risk actions |
| Model fallback | Tries another model on an API error or failed check | Resilience |
| Durable execution | DBOS, Temporal, Restate, Prefect or Airflow | Long-running agents survive restarts |

## How should you configure a Pydantic AI agent for production?

1. **Define an output type** for every agent that feeds another system. Free text should be the exception.
2. **Turn on OpenTelemetry instrumentation** and send traces to your existing backend, not only a developer's account. Our guide on [exporting agent traces with OpenTelemetry](/blog/export-ai-agent-traces-with-opentelemetry) covers attribute choices and retention.
3. **Set `UsageLimits` on every run.** Pick a request limit and tool-call limit based on the longest legitimate task, plus a margin.
4. **Mark write actions with `requires_approval=True`.** Payments, deletes, emails to customers and permission changes are typical candidates. See [human approval for high-risk agent actions](/blog/human-approval-for-high-risk-ai-agent-actions).
5. **Point the model client at your LLM gateway.** Pydantic AI supports OpenAI-compatible endpoints through a custom base URL, so routing, caching and cost attribution happen in one place. See [routing agents through an LLM gateway](/blog/route-agents-to-internal-models-through-llm-gateway).
6. **Use a workload identity, not a shared API key.** Each deployed agent should authenticate as itself.
7. **Pin the framework version** and review upgrades like any dependency.

## What does Pydantic AI not cover?

A framework controls one agent's code. It does not know about the other agents in your company. The gaps:

- **Inventory.** Nothing registers the agent centrally. Code-first agents are a common source of [shadow AI agents](/blog/how-to-find-shadow-ai-agents).
- **Ownership and review.** No built-in owner, approver or access review.
- **Cross-agent policy.** Limits and approvals live in each codebase, so they drift between teams.
- **Production quality.** Typed outputs check shape, not whether the answer is grounded or on task.
- **Stopping an agent.** Killing a process is not the same as quarantining an agent and revoking its access.

The same pattern applies to other code-first frameworks; compare [governing LangGraph agents in production](/blog/govern-langgraph-agents-in-production).

## How Opencontroller does this

Opencontroller keeps a governed registry of agents, versions, tools and MCP servers, so code-first agents sit next to platform agents. Agent workload identity federation gives each agent its own identity. Lyzr Gateway, the LLM Gateway, exposes OpenAI-compatible endpoints with routing, fallback and retry, caching and cost attribution per agent and per version. LLM judges score production traffic, live groundedness and task-adherence guardrails run in the path, and rogue-agent handling can alert, quarantine or kill. Opencontroller accepts OpenTelemetry data, so existing traces stay useful. Read [what an AI agent control plane is](/blog/what-is-an-ai-agent-control-plane) and [how to govern agents across platforms](/blog/how-to-govern-ai-agents-across-platforms), or [book a demo](https://www.lyzr.ai/book-demo/).

## Frequently asked questions

**Does Pydantic AI support OpenTelemetry?**
Yes, through `Agent.instrument_all()` or the `Instrumentation` capability, with any OpenTelemetry backend.

**Can Pydantic AI pause for human approval?**
Yes. Tools marked `requires_approval=True` end the run with `DeferredToolRequests` until a decision is supplied.

**Can Pydantic AI agents use an LLM gateway?**
Yes. Point an OpenAI-compatible model client at the gateway's base URL.

## Key facts

Pydantic AI is an open-source Python agent framework. Governance-relevant features: typed, validated outputs (failed validation is retried, then raises UnexpectedModelBehavior); OpenTelemetry instrumentation via Agent.instrument_all() or the Instrumentation capability, with logfire.instrument_pydantic_ai() for Pydantic Logfire; UsageLimits per run (for example request_limit and tool_calls_limit) that raise UsageLimitExceeded; deferred tools with requires_approval=True, which end the run with DeferredToolRequests so a human can approve before resuming; model fallback; and durable execution with DBOS, Temporal, Restate, Prefect or Airflow. It supports OpenAI, Anthropic, Gemini, Azure OpenAI, Amazon Bedrock, Google Vertex AI and self-hosted models, and OpenAI-compatible endpoints let you route through an LLM gateway. Framework features do not provide inventory, ownership, cross-agent policy or a kill path. Opencontroller by Lyzr adds these; pricing starts from $250K per deployment per year.

## Related

- [How do you govern LangGraph agents in production?](https://opencontroller.lyzr.com/blog/govern-langgraph-agents-in-production.md)
- [How do you export AI agent traces with OpenTelemetry?](https://opencontroller.lyzr.com/blog/export-ai-agent-traces-with-opentelemetry.md)
- [How do you route AI agents to self-hosted or internal models through an LLM gateway?](https://opencontroller.lyzr.com/blog/route-agents-to-internal-models-through-llm-gateway.md)
- [More on Platform Guides](https://opencontroller.lyzr.com/blog/cluster/platform-guides)
