Pydantic v2.5 Documentation
website·Indexed Jun 3, 2026
https://pydantic.dev/docs/Official documentation for Pydantic v2.5, a data validation and settings management library. Includes API references for BaseModel, FieldInfo, and pydantic-core, as well as guides on JSON schema generation, custom types, strict mode, and migrations from V1 to V2. Covers integrations with PyCharm, VS Code, Mypy, and Hypothesis.
What's inside Pydantic
- The Logfire Model Context Protocol (MCP) server provides AI assistants with tools to interact with your existing telemetry. Instead of summarizing logs or guessing, it exposes actual telemetry data to the model, allowing it to use sharp tools to anchor debugging in trace IDs, spans, and hard facts. This is particularly useful for debugging flaky integrations, production-only bugs, and performance regressions.
Overview of Pydantic TypeAdapter
A
TypeAdapterprovides a flexible interface for validating and serializing Python types that do not inherit fromBaseModel, such as primitive types, dataclasses, or complex generic types.Note:
TypeAdapterinstances are not types themselves and cannot be used as type annotations for fields.Overview of Pydantic V2 Architecture and Improvements
Pydantic V2 is a major rewrite of the library designed for significant performance gains and improved safety. The core validation logic has been moved to
pydantic-core, a separate package written in Rust usingpyo3.Key improvements include:
- Performance: V2 is significantly faster than V1, with benchmarks showing improvements between 4x and 50x depending on the use case (averaging ~17x faster for common models).
- Strict Mode: A new mode that prevents automatic data coercion. In strict mode, the input must match the exact expected type (e.g., an
intfield will reject the string `
Overview of Pydantic Data Platform Components
Pydantic is developing a data platform consisting of five key components designed to improve developer experience when working with data outside of Python:
- Python Analytics/Observability: A logging and metrics platform with tight Pydantic integration for engineering and business analytics.
- Data Gateway for object stores: A service providing validation, transformation, and cataloging for object stores (e.g., S3) using Pydantic models.
- Data Gateway for data warehouses: Similar to the object store gateway, but integrated with existing data warehouses.
- Schema Catalog: A single source of truth for organization-wide Pydantic schemas, tracking changes and integrating with other tools.
- Dashboards and UI: A managed platform where UI components (forms, tables) and database schemas are defined using Pydantic models in Python.
Overview of Pydantic BaseModel
In Pydantic, models are created by inheriting from theBaseModelclass and defining fields as annotated attributes.BaseModelprovides the core functionality for data validation, serialization, and model management.Overview of Logfire TypeScript SDK packages
The Logfire TypeScript SDK provides observability support (tracing, logs, metrics, and error reporting) for JavaScript and TypeScript applications. The SDK is split into several packages depending on your runtime environment:
logfire: The core, runtime-agnostic manual tracing API. Includes spans, logs, levels, error reporting, sampling helpers, evaluations, and managed variables.@pydantic/logfire-node: For Node.js environments. Configures the OpenTelemetry Node SDK, exporters, automatic instrumentation, logs, and metrics, and re-exports thelogfiremanual API.@pydantic/logfire-browser: For client-side browser applications. Configures browser tracing and re-exports thelogfiremanual API.@pydantic/logfire-cf-workers: For Cloudflare Workers. Instruments workers and forwards spans to Logfire.
Overview of the Pydantic Open Source Fund
Pydantic operates an Open Source Fund as part of its commitment to the Open Source Pledge. The fund commits to investing at least $2,000 per developer per year into open source projects and maintainers. This is separate from the direct costs Pydantic incurs for maintaining its own libraries (such as Pydantic, pydantic-core, Jiter, and FastUI).Overview of Pydantic Experimental Pipeline API
The
_Pipelineclass provides an experimental, abstract representation of a chain of validation, transformation, and parsing steps. It is a generic class_Pipeline[_InT, _OutT]used to build sequential data processing logic.Warning: This API is experimental and subject to change.
Overview of Pydantic AI Native Tools
Native tools are capabilities provided directly by LLM providers and executed on the provider's infrastructure, rather than being custom implementations executed by Pydantic AI. These tools are passed to an agent's
capabilitieslist, wrapped in aNativeToolobject.Supported native tools include:
WebSearchTool: Allows agents to search the web.XSearchTool: Allows agents to search X/Twitter (supported by xAI only).CodeExecutionTool: Enables secure code execution.ImageGenerationTool: Enables image generation.WebFetchTool: Enables fetching web pages.MemoryTool: Enables agent memory usage.MCPServerTool: Enables use of remote MCP servers via the model provider.FileSearchTool: Enables RAG-based searching through uploaded files via vector search.
Overview of Pydantic AI agent framework
Pydantic AI is an AI agent framework released by the Pydantic team. It is designed to work within the Pydantic ecosystem for building agentic systems. It is intended to be used alongside tools like Monty (a Rust-based Python implementation for LLM code execution) to enable faster and safer code execution by LLMs.Introduction to Pydantic AI
Pydantic AI is a Python agent framework designed for building production-grade Generative AI applications. It is built by the Pydantic team and focuses on type safety, model agnosticism, and seamless observability via Pydantic Logfire. Key features include:
- Model-agnostic: Supports OpenAI, Anthropic, Gemini, DeepSeek, Grok, Ollama, and many others.
- Type-safe: Leverages Python type hints for IDE auto-completion and static type checking.
- Extensible: Uses 'capabilities' to bundle tools, hooks, and instructions.
- Observability: Native integration with Pydantic Logfire (OpenTelemetry) for tracing and cost tracking.
- Advanced Patterns: Supports Human-in-the-loop tool approval, durable execution, streamed structured outputs, and graph-based control flows.
Overview of pydantic.json_schema module
The
pydantic.json_schemamodule provides tools to customize and generate JSON Schemas. While this module contains low-level classes likeGenerateJsonSchema, most users should instead use the high-level methods provided by Pydantic models or type adapters:BaseModel.model_json_schema()TypeAdapter.json_schema()