# Pydantic AI

> A type-safe Python agent framework that brings the FastAPI feeling to building apps with LLMs

- Category: Agents & Automation / Agent Frameworks & Builders
- Language: Python
- Licence: MIT
- Repository: https://github.com/pydantic/pydantic-ai
- Website: https://ai.pydantic.dev
- Canonical page: https://ai-tldr.dev/tools/pydantic-ai/

## In short

Pydantic AI is a Python agent framework built by the team behind Pydantic Validation, the validation layer used inside many popular LLM libraries and SDKs. It applies the same type-hint-driven, ergonomic design that FastAPI brought to web development to the job of building applications and workflows with generative AI. It sits in the Agent Frameworks & Builders category of the Agents & Automation tools and is open-source, written in Python and licensed MIT.

## Overview

Pydantic AI is a Python agent framework built by the team behind Pydantic Validation, the validation layer used inside many popular LLM libraries and SDKs. It applies the same type-hint-driven, ergonomic design that FastAPI brought to web development to the job of building applications and workflows with generative AI.

It is aimed at Python developers who want predictable, type-checked results from language models instead of loosely structured text. You define an agent with a model and the structure you expect back, and Pydantic validates the model's output against your types, moving a class of errors from runtime to write-time.

Within the agent-frameworks category, Pydantic AI sits among general-purpose frameworks for building agents. It is model-agnostic, supporting a wide range of models and providers (OpenAI, Anthropic, Gemini, and many others), and integrates with Pydantic Logfire and OpenTelemetry for observability.

## What it does

- Type-safe by design: outputs are validated against your Python types, surfacing errors at write-time with full IDE auto-completion support.
- Model-agnostic: works with most major models and providers (OpenAI, Anthropic, Gemini, DeepSeek, Cohere, Mistral, and many more), with custom-model support when a provider is not built in.
- Structured, streamed outputs: stream structured results continuously with validation as data is generated.
- Built-in evals: systematically test and evaluate the accuracy of the agentic systems you build, and track performance over time.
- Standards support: integrates Model Context Protocol (MCP), Agent2Agent (A2A), and UI event-stream standards for tools, interop, and interactive apps.
- Observability: integrates with Pydantic Logfire and any OpenTelemetry-compatible backend for tracing, debugging, and cost tracking.

## Getting started

Install the package from PyPI, then define a minimal agent. The README's full quickstart is clipped, so the snippet below is a minimal, safe starting point based on the README's own Agent example; see the official docs for full details.

1. Install Pydantic AI

   Install from PyPI with pip. Pydantic AI is published as the pydantic-ai package.

```bash
pip install pydantic-ai
```

2. Define and run a minimal agent

   Create an Agent with a model string, then run it. Set the relevant provider API key (here, ANTHROPIC_API_KEY) in your environment first.

```python
from pydantic_ai import Agent

agent = Agent('anthropic:claude-opus-4-8')

result = agent.run_sync('What is Pydantic AI?')
print(result.output)
```

3. Read the documentation

   The full quickstart, model/provider setup, structured outputs, tools, and evals are documented at ai.pydantic.dev.

## When to use it

- Extracting validated, structured data from language-model responses so downstream code can rely on typed fields instead of parsing free text.
- Building production agents and multi-step workflows that need consistent, type-checked behavior across model and provider changes.
- Writing model-agnostic LLM code that can switch between providers (OpenAI, Anthropic, Gemini, and others) without rewriting application logic.
- Adding observability and evals to an agentic system to debug behavior and track accuracy and cost over time.
