Learning resourcesReviewed · Pydantic

Pydantic AI: Advanced Tool Features

Advanced Tool Features is a Pydantic AI guide for Python developers building AI agents; several of its controls, including strict schemas, forced tool choice, returned files and tool search, behave differently across models and providers. It explains rich tool results, argument validation, dynamic tool availability, retries, approval, concurrency and tool search, including how these choices affect message history and prompt caching.

Researched 15 Nov 2026

In short.

Advanced Tool Features is a Pydantic AI reference for Python developers who need more control over agent tools, but provider support and configuration details limit what each feature guarantees. It connects tool results, strict schemas, dynamic availability, failure handling, approval, concurrency and deferred discovery to practical implementation choices. Particularly useful details include preserving approval fields during tool preparation, distinguishing correction requests from failed results, and understanding when tool discovery changes the cached request prefix. Installation requirements, prices, licensing and compatibility with a particular installed release are unknown from this page. No examples were executed.

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

Coverage includes the complete captured selected-page.txt at [https://pydantic.dev/docs/ai/tools-toolsets/tools-advanced/index.md], including its documentation-index and query-parameter notices, examples, provider tables and related-link text. Linked pages, external media, trace destinations and issue contents are excluded. No separate package or dependency files were supplied, and no code or live-provider behaviour was executed or tested. The page supplies no licence terms, installation baseline or package release pin.

The overview

Identity

Advanced Tool Features is a documentation page for function tools in Pydantic AI. A function tool is Python code that an AI model can request the application to call. The page extends basic tool registration into control over arguments, returned content, availability and execution.

The source is [https://pydantic.dev/docs/ai/tools-toolsets/tools-advanced/index.md]. The resource is this guide, rather than the entire Pydantic AI library or its linked documentation.

Assessment

This page is useful when basic tool calling works but an application needs clearer failure handling, approval rules, richer results or a larger tool catalogue. Its strongest contribution is explaining how similar-looking controls differ: schema enforcement is separate from business validation, a failed result differs from a retry request, and hiding a tool definition differs from registering a new tool.

It is an advanced reference with illustrative code, rather than a complete application tutorial. Several examples use controlled models or placeholder operations. They help explain framework behaviour but do not establish production reliability, tool-selection accuracy or performance.

Users

The main audience is Python developers building or maintaining agents whose models call application functions. Familiarity with type hints, function decorators, JSON schemas and basic agent runs makes the examples easier to follow. The page directs readers who need basic tool usage to the separate Function Tools documentation [https://pydantic.dev/docs/ai/tools-toolsets/tools/].

Experienced developers will find details relevant to multimodal tools, MCP integrations, approval flows, asynchronous servers, cross-provider history replay and prompt caching. Readers seeking a ready-made assistant or a no-code setup would still need an application and supporting configuration.

Capabilities

Tools can return values that Pydantic serializes to JSON, plus supported image, document, audio or video content. ToolReturn separates the tool result, additional user-message content, application metadata and names of deferred tools being revealed.

Argument and availability controls include custom JSON schemas, provider-supported strict generation, per-tool preparation, agent-wide preparation and tool_choice settings. Custom argument validators can enforce business rules or request approval before a function executes.

Execution controls cover correction requests, failed results, retries, timeouts, cancellation, parallel calls, sequential barriers and thread executors. Deferred loading and tool search reduce the definitions initially visible to the model. ToolKind and typed message parts let application code recognize tool semantics even when tool names change.

Using it

Requirements

The examples use Python with pydantic_ai and, in some cases, Pydantic models, asyncio, thread executors or typing utilities. Applying a live-model example also requires a compatible model integration. Authentication instructions, installation commands, minimum Python version and required Pydantic AI release are not supplied.

Media handling, strict schemas, forced tool choice and native tool search depend on the model, provider API and model profile. MCP examples additionally assume an available server. TestModel and FunctionModel appear in demonstrations that avoid calls to a real model, but those examples were not executed here.

Mechanism

For ordinary function tools, Pydantic validates model-supplied arguments against the Python signature before execution. Validation errors become retried tool results that the model can use to correct its call. Tool.from_schema is an important exception: the page says it passes arguments as keyword arguments without Pydantic argument validation.

ToolReturn.return_value becomes the tool response, while content is deliberately sent as a separate user message. Metadata is available to the application and is not sent to the language model. Files returned through the ordinary tool-result path may be placed in the tool result, moved to a framed user message or replaced with an unsupported-file note, according to model capabilities.

Per-tool prepare functions run before agent-wide preparation. They modify or omit definitions for the current step. The page recommends modifying the supplied ToolDefinition or copying it with dataclasses.replace, because constructing a fresh definition resets omitted fields, including fields involved in approval.

Tool search reveals deferred definitions through provider-native discovery or a local search tool. Discovery and application-driven availability changes are recorded in message history for replay. Typed tool parts use a namespaced ToolKind identifier and compatible argument or result shapes to recognize tools independently of their names.

Setup

The demonstrated starting point is an Agent with functions registered through decorators, Tool objects or toolsets. Individual registrations can specify preparation, strictness, retry limits, timeouts, argument validation, approval and sequential execution. Agent-wide examples also use capabilities such as PrepareTools and UseThreadExecutor.

For deferred discovery, mark individual tools or a toolset with defer_loading. The page says ToolSearch is then injected automatically; an explicit ToolSearch capability can choose keyword matching, a supported native algorithm or a custom callable. Descriptive names and descriptions provide the searchable information.

A reproducible environment setup is not included. Package installation, credentials, release compatibility and deployment configuration remain to be established for the intended application.

Example

A small example exposes a hitchhiker tool only when an integer dependency equals 42. Its prepare function returns the supplied definition for that value and otherwise omits it. The documentation shows a test-model run with dependency 41 producing no tool calls, followed by a run with dependency 42 making the tool available. These are documented outputs, not independently reproduced results.

A more operational example validates a transfer amount against a dependency limit and requests approval for amounts above 100 unless already approved. The illustrated amount of 500 is within a limit of 1,000, so the example surfaces an approval request. The transfer function itself only returns text; the example does not demonstrate an actual financial transaction.

The screenshot example also needs careful interpretation: its click operation is commented out and its image bytes are placeholders. It illustrates ToolReturn structure, rather than working computer automation.

Assessment & evidence

Limitations

strict=True requests provider enforcement where supported; it is not a universal guarantee. Some schemas may be transformed lossily or have strictness ignored. Defaults differ among OpenAI, Anthropic, Google and Bedrock, and other providers ignore the flag. Support for native JSON-schema output does not itself establish support for strict tool definitions.

Forced tool choice has model and provider restrictions, including interactions with thinking modes. A static 'required' setting or a static list containing no output tool prevents an agent from finishing, so the framework rejects those configurations. On Bedrock Converse, once the history contains a tool call, 'none' cannot stop non-Claude models from calling tools; Claude models get their native 'none' mode.

Retry limits apply per tool, with a documented built-in default of one. ToolFailed leaves that retry budget untouched. The successful-tool-call limit does not bound repeated failures; request_limit is the control the page identifies for bounding repeated failed exchanges.

Agent and per-tool timeouts are enforced through FunctionToolset and do not automatically cover MCP servers, external toolsets or custom toolsets. Cancellation cannot forcibly stop a synchronous worker thread, and side effects can remain even when its eventual result is discarded.

File-origin tags are ordinary prompt text, not proof of provenance. Deferred tools can become hidden again if history processing removes discovery records. Tool search also has discovery overhead, and cross-provider support does not imply identical caching behaviour.

Practical reasoning

The page supports treating tool integration as several separate decisions. Strict generation addresses argument shape; custom validators address application rules; approval determines whether a valid call may proceed; concurrency controls determine whether calls may overlap. Combining these controls deliberately is more useful than expecting one flag to provide all of them.

Two code details deserve attention when adapting examples. Rebuilding a ToolDefinition can discard approval semantics, so preserving its fields matters. Also, the RequireFirstCall example checks for a matching ToolReturnPart without checking its outcome. An application that requires a successful first call would need to distinguish success from retried or failed results.

Alternatives

Within the approaches described, a small tool set used on most turns can remain eagerly loaded and avoid discovery overhead. Deferred search is aimed at larger catalogues or tools spread across domains. On-demand capabilities are presented as an alternative when instructions, settings, hooks and tools should be disclosed together.

For a single model request without an agent loop, the page points to direct model requests. For an open-ended tool universe, it describes CodeMode as exposing callables through one stable run_code tool. The linked implementations are outside this page's evidence, and their suitability is not assessed.

The supplied material does not establish a comparison with other agent libraries or frameworks.

Evidence

The evidence consists of the complete Advanced Tool Features documentation page, including its explanations, embedded Python examples, expected outputs and provider tables. These support an account of documented APIs and caveats, rather than an independent verification of runtime behaviour.

Linked API references, provider documentation, GitHub issues, Logfire traces and sample media were not assessed. No code was executed. Reliability, latency, selection accuracy, cache-hit rates and compatibility with a particular environment remain unassessed.

Access & freshness

Costs

The page supplies no prices for library use, model requests, native tool search, hosting or telemetry. Monetary cost is unknown. It also supplies no measured savings for deferred loading or caching.

Tool search can add a discovery exchange, while retries can add model requests. Cache behaviour depends on how definitions reach the provider. Supporting Anthropic models and first-party OpenAI Responses can preserve the prefix during discovery; other integrations add each discovered definition to the tools array, which invalidates the cached prefix from the tool definitions onward on each discovery turn that reveals a tool. Gemini can still reuse an earlier stable system instruction. These mechanisms explain possible cost differences without establishing an amount.

Rights

The supplied page contains no licence text or explicit reuse terms for its prose or code snippets. Rights for commercial reuse and redistribution are unknown from this evidence. Linked images, documents and other materials have no accompanying permissions in the supplied text.

Freshness

The documentation was captured on 15 November 2026 at 05:18:28 UTC. The supplied text does not establish a publication date, last-update date or matching Pydantic AI package release. The capture date establishes the snapshot's timing, rather than when each feature became available.

Provider and model compatibility tables are sensitive to API changes. The page explicitly labels Gemini's VALIDATED function-calling mode as a preview feature. Current support beyond the captured documentation is unknown.

Next steps

Beginners should first become comfortable with basic function registration and agent runs. Developers adapting these advanced patterns should confirm API availability in their installed release and check the intended model's media, strictness, forced-choice and search support.

For tools that change application state, preserve approval fields, validate arguments before approval and use sequential execution where overlap would be incorrect. Configure appropriate deadlines and request limits, including separate deadlines for external tools. Measure discovery overhead and cache behaviour with the actual provider and workload before relying on efficiency benefits.

Evidence for this report

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