In short.
Tool Output Limits is a guide for Python developers keeping large tool results from filling Pydantic AI agent conversations, but full recovery depends on working storage and retrieval. It documents a capability that reduces results once before they persist in conversation history. The default stores results of at least 10,000 characters and substitutes a preview, falling back to truncation if writing fails. Configurable truncation and model summaries provide other tradeoffs. The page supplies detailed configuration guidance, but no measured token savings, latency results, or validation of answer quality.
Researched and written by an AI model and checked by a second AI model. How it works
Covers the complete documentation page at [https://pydantic.dev/docs/ai/harness/tool-output-limits/index.md], including its examples, API reference, 0.x compatibility notice, storage security notes, and edge cases. Linked source files, the documentation index, version policy, and related capability pages are excluded. Installation compatibility, licensing, provider pricing, and model availability are not established. No code was executed, and storage, retrieval, fallbacks, durable replay, performance, and savings were not tested.
The overview
Identity
The resource is the Tool Output Limits documentation page at [https://pydantic.dev/docs/ai/harness/tool-output-limits/index.md]. It teaches configuration of ToolOutputLimits, a Python capability supplied by Pydantic AI Harness and attached to a Pydantic AI Agent through its capabilities.
A tool result is data returned by a function the agent calls, such as a file reader or command runner. This guide covers handling results large enough to dominate the model's conversation context, through explanations, configuration examples, storage details, and an API reference.
Assessment
The guide is useful for agents that encounter large files, verbose logs, or substantial JSON results. It explains the recurring cost of retaining those results in conversation history and provides concrete controls for deciding what remains visible to the model.
Its strongest contribution is the detail around recovering stored output and handling failures. Storage failures, inaccessible spill files, and earlier truncation by another tool can prevent complete recovery. Runtime reliability, answer quality, and actual savings have not been assessed.
Users
The primary audience is Python developers building agents with Pydantic AI. Beginners need familiarity with Python imports, agent configuration, and tools that return data; the examples assume an existing model and agent environment.
Experienced developers get controls for individual tools, structured and binary returns, token-based thresholds, metadata preservation, custom storage, and durable execution. These details are particularly relevant when file readers and command runners share an agent.
Capabilities
Truncate keeps the beginning, end, or both ends of text within a character budget. Spill stores the full received payload and gives the model a handle, preview, and structured-data shape sketch. Summarize replaces output with a model-generated summary. Truncation and summarization lose information; successful spilling preserves the received payload.
Size bands choose the action with the largest qualifying threshold. Per-tool settings replace global bands for named tools, a tool filter controls which tools are affected, and Passthrough explicitly leaves matching output unchanged. Optional ANSI stripping and structured-data serializers affect the text measured and reduced.
Stored output can be retrieved in bounded slices or searched for literal substrings. The capability also preserves tool metadata and attached files while reducing eligible data and textual content.
Using it
Requirements
Use requires a Python environment with compatible Pydantic AI and Pydantic AI Harness packages, an Agent configuration, and tools producing results. The page does not establish minimum Python or package versions or provide installation commands.
The default spill store needs a workspace. A run configured to spill without an available workspace fails at startup; a read-only workspace causes writes to fail and invokes the configured fallback. LocalFileOverflowStore provides host temporary-directory storage for runs without a workspace. Custom stores must implement asynchronous write and read methods.
Successful recovery also requires retrieval tools that can access the chosen store. Summarize requires an available model, inherited from the running agent by default or explicitly configured.
Mechanism
ToolOutputLimits intercepts successful results in after_tool_execute. It reduces each result once, allowing the reduced form to persist as a ToolReturnPart in history. ToolReturn.return_value and model-visible textual content are measured separately and receive distinct spill handles when needed.
Thresholds use characters by default. With over_tokens enabled, they use estimated tokens or a supplied tokenizer. Truncate.max_chars remains a character limit regardless of the threshold unit, and includes retained text and omission markers.
Structured returns use compact JSON by default. The indented_json and json_lines serializers introduce useful line boundaries for retrieval; json_lines supports paging lists by record. Serialization also changes measured size and can therefore change which band applies. Raw binary returns spill verbatim.
With durable execution, built-in spill writes and model summaries are journaled so replay can reuse recorded results. Custom summarization callables can run again during replay, and custom stores should tolerate repeated writes to the same key.
Setup
For workspace storage, the page adds LocalWorkspace('.') and ToolOutputLimits() to an Agent's capabilities. With no bands supplied, results of at least 10,000 characters use Spill with a Truncate fallback. The default store writes under .pydantic-ai-harness/tool-output/ in the workspace.
Configure bands for different output sizes, per_tool for different tool behaviors, and tool_filter to limit coverage. Actions can chain fallbacks through then, such as summarization followed by spilling followed by truncation.
For storage outside the run workspace, configure a WorkspaceOverflowStore with its own workspace backend or use LocalFileOverflowStore. Check retrieval permissions and retention settings alongside the reduction configuration.
Example
The Shell example sets the command runner's native output cap to 100,000 characters. For run_command results reaching 20,000 characters, it stores the output with a fallback that keeps up to 4,000 characters from the end. Results reaching 4,000 but remaining below 20,000 characters use that tail truncation directly.
The example sets global bands to an empty list, so these reductions apply only to run_command. The tail strategy can retain an exit-code trailer when it fits. Storage preserves only what Shell returns: content already removed by Shell's native cap cannot be recovered.
Assessment & evidence
Limitations
Truncate and Summarize keep no full copy; their markers direct the model to rerun the original tool. Truncating structured output can produce invalid JSON. Very small truncation budgets can omit the marker, and reserving tail lines does not guarantee an oversized control trailer survives.
Spills remain for the workspace's lifetime and are not pruned by this capability. LocalFileOverflowStore keeps files indefinitely unless cleanup_after is configured. Its stable root supports later access by the same user rather than isolation between store instances; the documented ownership checks differ between POSIX and Windows.
When FileSystem replaces the dedicated retrieval tools, its access rules can make spill files unreadable. Without its search tools, spills become unsearchable, and its reader lacks the dedicated reader's byte slicing and from_end options. The replacement decision does not account for denied paths.
Dedicated retrieval responses are capped at 50,000 characters. Search uses literal substrings, with context capped at 10 lines and matches at 200 per call. Long lines may require byte-based paging, whose cut UTF-8 characters can appear as replacement characters.
Tool errors and ModelRetry bypass this hook, attached files remain intact, and oversized non-text content can remain unreduced with a warning. Durable execution engine payload limits still apply to output included in journaled operations. This capability therefore does not establish a universal cap on conversation size.
Reasoning
Spill is the strongest documented option when later access to the full received result matters, provided storage and retrieval remain available. Truncation suits outputs where a chosen portion, such as the end of a build log, is sufficient. Summarization trades an extra model request and potential omission for a shorter account.
Choose thresholds and serializers together: pretty-printed JSON can cross a threshold that compact JSON would not, while record-per-line output makes retrieval more useful. Character counts and estimated token counts do not guarantee that the entire conversation fits a model's context window.
Alternatives
The page distinguishes compaction, which compresses or drops context already in history, from reducing tool results when they arrive. It also identifies ClampOversizedMessages as a control for oversized model responses.
Shell's native max_output_chars provides an earlier limit on command output. Its position matters: content it removes never reaches ToolOutputLimits. The guide recommends keeping that native cap above the relevant ToolOutputLimits thresholds. These comparisons are supported only by descriptions on this page.
Evidence
The evidence is the complete Tool Output Limits page at [https://pydantic.dev/docs/ai/harness/tool-output-limits/index.md], including explanations, Python configuration examples, edge cases, and an API reference. It directly supports the stated defaults, retrieval limits, storage behavior, and failure paths as documented behavior.
The page contains no empirical benchmark or measured comparison of token usage, latency, or task accuracy. Linked implementation files and related documentation are outside the available evidence, so they do not independently corroborate the descriptions.
Access & freshness
Costs
Package pricing, model-provider rates, storage charges, and total operating cost are unknown from this page. Truncate and Spill make no model calls for the reduction itself; storage, retrieval, and subsequent agent requests still consume resources.
Built-in Summarize makes an additional model request. Its tokens and request count are included in the run's ctx.usage, and it inherits the agent's model unless overridden. Reducing repeatedly transmitted output may lower later context usage, but the page provides no measured savings or break-even calculation.
Rights
The page links to implementation source at [https://github.com/pydantic/pydantic-ai/tree/main/src/pydantic_ai_harness/pydantic_ai_harness/tool_output_limits/], but supplies no license grant for the documentation or implementation. Redistribution rights and applicable reuse terms are unknown from the available evidence.
Freshness
The documentation capture is dated 25 November 2026. The page does not identify an exact package release or page-update date, so compatibility with a particular installed release remains unknown.
Its version notice warns that APIs may change between minor releases while Pydantic AI Harness is on 0.x, with deprecation warnings and release-note migration guidance. The linked version policy and release information are outside the available evidence.
Actions
Before adoption, confirm the imports and configuration against the installed release, choose a writable store, verify that retrieval tools can access its handles, and set an appropriate retention period.
Choose bands according to which information each tool must preserve. Keep Shell's native output cap above spill thresholds, and consider json_lines for tools returning lists of records.
Validate representative outputs before relying on the configuration, including storage failures, denied retrieval paths, long-line paging, and summary usage accounting. Measure actual context usage and answer quality to determine whether the chosen reductions help the application.
