Learning resourcesReviewed · Pydantic

Pydantic AI Citations Guide

This Pydantic AI guide teaches Python developers to add source citations to AI answers, but the available detail depends on the provider and answer format. It explains how to request, read, display and preserve citations, including limitations involving structured output, tool arguments, streaming and message history.

Researched 23 Nov 2026

In short.

This guide shows Python developers how to use source citations in Pydantic AI, but provider differences limit where citations appear and which text they identify. It documents a shared citation interface across providers while explaining important exceptions for structured answers, tools, streaming and saved conversations. Its practical value is helping developers design citation handling without assuming every provider supplies precise source locations or preserves citations throughout a conversation. Installation requirements, pricing and licensing are not established by this page, and the examples were not executed.

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

Coverage is the complete selected page at [https://pydantic.dev/docs/ai/core-concepts/citations/index.md], including its examples, provider support table, streaming and history guidance, and introductory site notices. Linked documentation, provider references and the documentation index are excluded. The examples were not executed. Runtime behavior, citation accuracy, installed-version compatibility, costs and redistribution rights were not independently established.

The overview

Identity

The resource is the Citations documentation page for Pydantic AI at [https://pydantic.dev/docs/ai/core-concepts/citations/index.md]. It is a technical guide to a framework feature, rather than a standalone citation application.

The page explains how provider-generated citations appear on TextPart.citations and how applications can interpret their sources and locations in an answer. It includes Python examples, a provider support table and guidance for streaming and message history.

Assessment

The guide is useful for developers building answers that show where information came from, especially when supporting multiple model providers. Its strongest material concerns integration details that can otherwise be easy to miss: anchors covering an entire text part, missing anchors, delayed streaming metadata and citation markup entering tool arguments.

It provides enough detail to inform an implementation, but does not demonstrate that cited sources adequately support every generated claim. The page explicitly says a model can still answer without citations. Runtime behavior, citation accuracy and compatibility with a particular installed release were not assessed.

Users

Python developers adding source links or document references to AI answers are the primary audience. Beginners receive a concrete document-question example and an explanation of citation fields; experienced developers receive details about provider annotations, output modes and conversation replay.

The material is particularly relevant to applications that search the web, answer questions about documents or display evidence beside generated text. Developers requiring citations inside typed response fields or through an existing frontend adapter should examine the documented restrictions before choosing an approach.

Capabilities

Pydantic AI exposes citation metadata in a common shape without rewriting the model's answer text. Depending on the provider, citations can refer to web pages, supplied documents or files in a provider's store. Sources can include titles, identifiers and quoted excerpts.

The page covers Anthropic, Amazon Bedrock, Google Gemini API, Google Vertex AI, OpenAI Chat and Responses, OpenRouter and xAI. Support differs substantially: Bedrock citations are documented for documents on Anthropic models; Vertex AI lists Google Search; OpenAI Responses supports file citations as well as web citations.

Saved messages retain citations. Provider-specific details, including information such as Google's confidence scores, remain available in provider_details['citations'], although their structure belongs to the provider and can change.

Using it

Requirements

The examples assume Python code using Pydantic AI and a provider/model combination that supports the relevant citation source. Web and file citations generally require the corresponding native tool; document citations can instead use documents supplied in the prompt.

Some providers require the Citations capability, while others produce citations when their search or fetch tool is enabled. Bedrock text documents must be UTF-8 when citations are enabled, and documents read from S3 are not cited under the documented Bedrock behavior.

The page provides no installation command, minimum Python version, Pydantic AI package version or credential setup. Those prerequisites remain unknown within this resource.

Mechanism

A Citation contains sources and an optional anchor. WebCitationSource supplies a URL. DocumentCitationSource represents other sources and can supply a provider document identifier rather than a local file path. Prompt documents may have neither an identifier nor a title. Source excerpts contain passages the provider quoted as evidence.

ContentCitationAnchor identifies the supported text using character offsets into part.content. MarkerCitationAnchor identifies a marker the model wrote, such as a source link. An absent anchor means the provider did not identify a supported text span; some additional position information may remain in the raw provider details. Anthropic anchors can cover an entire text part rather than an individual claim.

Saving citations does not guarantee that a model receives them on the next turn. The page documents replay of Anthropic web-search citations on compatible clients and OpenAI Responses web/file citations when message IDs are sent. Other citation types, cross-provider history and changed or joined text return as plain text while citation metadata remains in saved messages.

Setup

For document citations, the example imports Citations from pydantic_ai.capabilities and adds Citations() to the Agent's capabilities. It supplies a text document using BinaryContent, then reads citation metadata from TextPart instances in the final response.

For web-search citations, the rendering example enables WebSearchTool through NativeTool. It then distinguishes content anchors, marker anchors and citations without anchors before displaying a source label.

Configuration must follow the provider-specific rules. For example, xAI requires Citations() with a search tool, while Google search citations are enabled through the tool itself. These are documented setup patterns; neither example was executed.

Example

The document example asks how long customers have to return an item and supplies a short policy stating a 30-day return period. The code inspects each text part, loops over its citations and prints excerpts from the first source. The displayed excerpt is an illustrative result in the documentation, not an independently observed execution.

A second example asks a web-search agent about Alberta's tallest mountain and shows how a renderer can associate a citation with supported text, a written marker or an unspecified location. It illustrates why an interface needs a fallback when precise text positions are unavailable.

Assessment & evidence

Limitations

Citations attach to text parts, and answers returned as output-tool arguments cannot carry that citation metadata. The guide recommends text output when citations are needed. NativeOutput and PromptedOutput can have web citations on their JSON text for some providers, but positions refer to the JSON text rather than individual fields.

Anthropic has additional restrictions. With Citations(), structured output is not asked for document citations, and Anthropic rejects citations with NativeOutput. Forcing a tool call in a request containing a document or Web Fetch raises UserError before that request is sent. Voluntary tool calls can receive citation markup inside their arguments; the page reports this in its own smaller-model tests without providing a reproducible test setup here. Direct Anthropic web search, and citation-enabled web fetch, can also introduce markup into structured output independently of Citations().

Anthropic behavior depends on the web-tool version and whether results reach the model through direct tool calls or code execution. Results read through code execution are uncited under the documented conditions. On xAI, enabling citations changes the model's text to include markers and conflicts with calling the structured-output tool, so Citations() does not request them for structured output.

Streaming metadata can arrive after the text it describes, so the guide advises reading citations from the final response. On xAI, an answer followed by a tool call can receive no citations. The AG-UI adapter does not send citations to the frontend; the Vercel AI adapter preserves them when the frontend holds message history.

Provider metadata also limits presentation. OpenRouter supplies no anchors, Google Search URLs are redirect links and titles may be only domains. OpenRouter's Perplexity Sonar models already search and reject an explicitly supplied web-search tool. OpenAI annotation types beyond the normalized citations may require openai_include_raw_annotations.

Reasoning

The common citation interface reduces differences in how an application reads metadata, but the documented provider variations mean it cannot guarantee equally precise attribution. A whole-part anchor or missing anchor gives less information about an individual claim than a specific supported text span.

A practical inference is that displaying a citation should be treated as showing attribution, not proving the answer correct. The page warns that sources grouped into one citation may copy each other, so source count does not measure support quality.

Conversation history adds another distinction: retaining a citation in storage does not necessarily let the model inspect its source later. The guide explicitly warns that a follow-up about a numbered source may require supplying the source again or retrieving it.

Alternatives

The page links to provider-specific documentation, including Anthropic citations [https://platform.claude.com/docs/en/build-with-claude/citations] and OpenAI web search [https://platform.openai.com/docs/guides/tools-web-search]. These are possible sources of provider detail, but their contents are outside this resource's assessed scope.

Within Pydantic AI, the documented choices include enabling native tools, adding Citations() where required, using text output when citations matter, or leaving the capability off for agents whose tool arguments could be affected. The page does not compare competing frameworks or establish which approach is best for a particular application.

Evidence

The evidence consists of the complete documentation page at [https://pydantic.dev/docs/ai/core-concepts/citations/index.md], including its examples, provider table and operational caveats.

Behavioral statements come from this documentation. Linked API references and provider pages were not assessed. No code was executed, no provider requests were made and no citation accuracy or application behavior was tested.

Access & freshness

Costs

The page gives no prices, usage allowances, tool charges, quotas or rate limits. It does not establish whether a particular setup is free or what a representative request would cost.

Any cost estimate for a chosen model and search, fetch or file tool remains unknown from this evidence.

Rights

The page contains no license or redistribution terms for the documentation or code examples. Permission to redistribute those materials is not established by this evidence.

The page also does not establish reuse rights for documents or excerpts returned through citations. It warns that excerpts can contain material from documents supplied by the application, which matters when deciding what to display or retain.

Freshness

The documentation snapshot was captured on 2026-11-23 at 16:28:25.730 UTC. This establishes the snapshot's acquisition time, not the date the described behavior was last verified.

The page gives no publication date, last-update date or Pydantic AI release number. It names particular Anthropic web-tool versions and example model identifiers, but their availability and compatibility with a chosen deployment were not independently established.

Actions

Choose the provider, source type and answer format together. If citations are essential, start with the guide's text-output approach and confirm the selected provider's documented tool and capability requirements. Establish installation compatibility and pricing separately.

Build citation display around the final response. Handle content anchors, marker anchors and absent anchors, and provide labels when document identifiers or titles are missing. Inspect citation URLs, titles and excerpts before displaying or logging them, especially when excerpts may contain supplied documents.

For Anthropic workflows, check tool arguments that will be shown or sent to people for citation markup. For saved answers, clear both citations and provider_details['citations'] after editing text: the guide warns that an edit preserving text length can escape automatic detection.

When users ask follow-up questions about a source, make the source available again if its content is absent from the model's history. Before relying on a frontend integration, establish whether it actually transports the citation metadata required by the interface.

Evidence for this report

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