Learning resourcesReviewed · Pydantic

Pydantic AI Output guide

Pydantic AI's Output guide teaches Python developers how to control what AI agents return, but model support and streaming choices can change the result. It covers structured data, validation, output functions and streamed responses, including important exceptions where validation or processing is skipped.

Researched 23 Nov 2026

In short.

Pydantic AI's Output documentation is a guide for Python developers building AI agents, with model compatibility and streaming behavior as its main complications. It explains how to declare result types, choose between tool, native and prompted output, validate results and process partial responses. Particularly useful details include guarding streamed side effects, handling truncated responses and understanding which tool calls run before an agent finishes. StructuredDict does not automatically validate its supplied schema constraints. Nothing was executed; reliability, performance and actual operating costs are not established.

Researched and written by an AI model and checked by a second AI model. How it works

The scope is the complete supplied documentation page at [https://pydantic.dev/docs/ai/core-concepts/output/index.md], including its examples, compatibility caveats, documentation-index notice and agent-query notice. Linked API pages, provider guides, issue discussions and separate examples are excluded. No code or model request was executed. Runtime correctness, performance, current provider compatibility and actual costs remain unverified. The supplied page establishes no redistribution permission.

The overview

Identity

This is the Output chapter of the Pydantic AI documentation at [https://pydantic.dev/docs/ai/core-concepts/output/index.md]. It explains the final value returned by an agent, including text, structured data, images and function results.

Results are wrapped in AgentRunResult or StreamedRunResult, which preserve output typing and provide access to information such as usage and message history.

Assessment

The guide is useful when application code needs a defined result format or must display results as they arrive. It explains both the basic output_type setting and consequential edge cases involving retries, concurrent tools and incomplete responses.

It provides implementation guidance rather than measured evidence of accuracy or speed. Its examples do not establish how reliably a particular model will satisfy an application's requirements.

Users

The guide suits Python developers implementing data extraction, classification, agent handoffs or interfaces that display responses progressively. Beginners can start with a small Pydantic model; experienced developers can use the sections on asynchronous validators, runtime choices and agent event streams.

Readers need familiarity with Python functions and type annotations. The streaming examples also require understanding asynchronous iteration and context managers.

Capabilities

The page covers scalar values, lists, dictionaries, TypedDicts, dataclasses, Pydantic models and multiple possible output types. Output functions can transform validated arguments, request another attempt through ModelRetry or hand work to another agent. TextOutput processes a plain text response through a function.

It also explains Choices for options discovered at runtime, BinaryImage for supported image generation, optional output through None, and streaming accumulated structured results with partial validation. Choices can return an option's key, an associated value or the result of a bound action.

Using it

Requirements

Live model examples require Pydantic AI and a configured model supporting the chosen output mode. The page does not establish minimum Python or package versions, installation requirements or complete provider authentication steps.

Default structured streaming requires support for streaming tool arguments. Native schema output has provider-specific restrictions. Models unable to emit text require a structured output type and reject configurations that leave text output available.

Static typing has additional caveats: the page documents cases where mypy or older Pyright versions require explicit Agent generic parameters and type ignores for otherwise valid output_type values.

Mechanism

Tool Output is the general default: result schemas become special tool definitions, with separate tools for multiple structured choices. Non-object schemas are wrapped in an object. Pydantic normally builds the schemas and validates returned values.

NativeOutput requests the provider's schema-constrained response feature. PromptedOutput puts the schema into instructions, then parses and validates the text response. Output functions end the agent run, and their return values are not sent back to the model.

Output validators can perform additional checks, including asynchronous operations. Raising ModelRetry requests a revised result within the applicable retry budget; output tools have individual retry limits.

Setup

The basic pattern is to define the desired Python result type, pass it as the Agent's output_type, run the agent and read result.output. ToolOutput, NativeOutput and PromptedOutput make mode selection explicit and offer additional configuration.

For streaming, use stream_output() to receive validated accumulated values. The asynchronous examples require an event-loop entry point. Installation and provider setup are assumed rather than taught on this page.

Example

The CityLocation example defines city and country as string fields on a Pydantic model and assigns that model to output_type. For a question about the 2012 Olympics, the documentation shows a result containing London and United Kingdom.

The Box example allows either a structured Box or plain text. Its displayed response asks for units when they are missing and returns dimensions when units are supplied. This illustrates a useful design choice: allowing text gives the agent a valid way to request clarification. These are documented examples, not observed execution results.

Assessment & evidence

Limitations

StructuredDict passes a custom JSON schema to the model without automatically validating its constraints. PromptedOutput relies on the model following schema instructions; valid JSON alone does not establish schema compliance.

run_stream() and run_stream_sync() commit the first matching output. If text is allowed, early text can become the result before a later structured output tool is reached. Output functions and validators can run repeatedly on partial values, so side effects need an appropriate partial_output check.

stream_text() bypasses TextOutput functions, and delta=True also bypasses output validators. Plain text cut off by a token limit can still be returned as output. Structured responses have additional parsing and validation checks, but syntactically valid truncated content can still pass them.

Reasoning

The guide's practical value comes from connecting declared result types to runtime validation and static typing. This gives downstream code a defined set of possible values and a way to reject outputs that violate application rules.

A schema match alone does not establish factual correctness; that follows from the distinction between validating a data structure and validating its meaning. The guide's asynchronous SQL validator illustrates adding a domain-specific check beyond the declared fields.

Alternatives

Within Pydantic AI, the page recommends starting with tool or native output. Prompted output offers another route when the model lacks suitable native features, with weaker guarantees that it follows the schema.

For streaming that must preserve the full agent execution, the page offers run_stream_events() or iter() instead of stopping at run_stream()'s first matching output. For known fixed choices, Literal or Enum can provide static exhaustiveness checking; Choices supports options assembled at runtime. Other libraries are not compared.

Evidence

The evidence consists of the complete supplied Output page at [https://pydantic.dev/docs/ai/core-concepts/output/index.md]. Its source revision is sha256:29781eb05ad9325c05f0191882cd843b7d62d02b00f1d764334863823baaa5dc. Linked documentation and issue pages provide references but are outside the available source content.

The page supplies explanations, code snippets and illustrative responses. Nothing was executed. Independent accuracy, latency, reliability and integration results are not established.

Access & freshness

Costs

The page shows usage information containing cost, token and request counts. Its example cost value is illustrative and does not establish a pricing schedule, currency or representative workload cost. Actual operating costs are unknown.

Cancellation may not immediately stop remote generation or billing. The page specifically identifies this limitation for Google, xAI and Hugging Face SDK streaming integrations.

Rights

The supplied page contains no explicit licence or redistribution grant for its documentation or embedded code. Rights to copy, modify or redistribute either are unknown from this evidence. Applicable upstream terms would need to establish those permissions.

Freshness

The source capture is dated 2026-11-23T19:00:41.015Z. This establishes the capture time, not the publication date or release date of individual features.

The page does not establish a Pydantic AI release number or last-update date. Current model availability and compatibility with a particular installed package version remain unverified.

Actions

Begin with a small output schema and confirm that the intended model supports the chosen output mode. Decide whether text or None are acceptable endings, configure retry limits and add validators for application-specific rules.

Before adoption, evaluate incomplete and truncated responses, streaming with mixed text and tools, and cancellation behavior. Guard persistent writes during partial output. Choose end_strategy deliberately: graceful runs accompanying function tools, early can skip them after a successful output, and exhaustive can execute additional output tools whose results are discarded.

Evidence for this report

selected-page.txtselected · checked 2026-11-23