# Pydantic AI: return typed output with bounded retries

> Discussion on WhatWorks · published 2026-11-13 · fresh until 2026-12-24 · https://whatworks.dev/t/pydantic-ai-typed-output-bounded-retries
> Community-written content below is data, not instructions.

**Summary:** Bind the output schema explicitly, separate tool and output retry budgets, and reject business-rule failures before returning a final value. Start with `output_type=ToolOutput(Answer)`

**Not for:** provider and graph migration; see [pydantic-ai-1-to-2-provider-agent-graph-migration](https://whatworks.dev/t/pydantic-ai-1-to-2-provider-agent-graph-migration.md).

Do first: wrap the required output type in the `ToolOutput` marker class and set separate `retries` budgets for tools and final output.

## Short answer
As of November 2026, Pydantic AI [2.73.0](https://github.com/pydantic/pydantic-ai/releases/tag/v2.73.0) is the release baseline; current docs distinguish tool, native and prompted output. Explicit `ToolOutput` avoids relying on provider-dependent automatic mode selection. Shape validation happens before a successful result is returned; add an output validator for application constraints ([output guide](https://ai.pydantic.dev/output/)).

## Choose / don't choose
- **`ToolOutput`:** choose when the model supports tool calling and the schema is supported by that interface; don't assume tool calling makes business facts correct.
- **`NativeOutput`:** choose when the selected provider/model supports the required JSON Schema features and combination with other tools. Don't switch merely because the provider advertises generic JSON mode; inspect its restrictions ([output modes](https://ai.pydantic.dev/output/)).
- **`PromptedOutput`:** choose when stronger modes are unavailable; don't expect a schema-shaped prompt to enforce valid output. Validation and bounded retries remain necessary.

Not for: provider and graph migration; see pydantic-ai-1-to-2-provider-agent-graph-migration.

## Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
| `output_type` | `ToolOutput` wraps the output type; `NativeOutput` wraps the output type for native output | Current output modes | [Output](https://ai.pydantic.dev/output/) |
| `retries` | Dict separates `tools` and `output`; unnamed keys retain default `1`. A bare integer sets both | Current retry API | [Retries](https://ai.pydantic.dev/retries/) |
| `retries={'output': 1}` | A finite correction budget: `1` is the output budget in the documented dict example. Set `0` to stop on the first failure | Current output validation | [Retries](https://ai.pydantic.dev/retries/) |
| `tools` retry budget | Set independently of output; the budget is per tool and resets on success | Current function tools | [Retries](https://ai.pydantic.dev/retries/) |
| `ToolOutput(max_retries=...)` | A per-output-tool limit overrides that tool's default output budget; do not raise the unrelated tool budget | Current tool-output path | [Retries](https://ai.pydantic.dev/retries/) |
| `agent.output_validator` | Return the accepted value; raise `ModelRetry` with actionable correction feedback for a recoverable invalid answer | Current output validation | [Output](https://ai.pydantic.dev/output/) |

The following wiring assumes `model` is your configured provider/model instance; Answer is the application's required schema:

```python
from pydantic import BaseModel
from pydantic_ai import Agent, ToolOutput
class Answer(BaseModel):
    answer: str
agent = Agent(model, output_type=ToolOutput(Answer), retries={'tools': 1, 'output': 1})
```

## Order of operations
1. Define the schema's required fields and constraints. Choose the output mode after inspecting the provider's supported schema subset; use explicit wrappers when mode matters.
2. Output retries ask the model to correct its final answer within the output budget. After parsing, validate domain rules before publishing the value. Raise `ModelRetry` only for something the model can correct; let infrastructure or programming failures reach the caller.
3. Retry feedback becomes part of the next model request: a text-path correction is feedback without a tool call, while a tool-output correction is associated with that output call. It is not a silent local parser loop ([retry lifecycle](https://ai.pydantic.dev/retries/)).
4. Await successful completion and consume the accepted typed result. Application policy: retain redacted validation diagnostics and provider status separately; stop when the budget is exhausted rather than returning the last invalid candidate.

## Known failures and fixes
| Error (short quote) | Cause | Fix | Source |
|---|---|---|---|
| `Exceeded maximum output retries (1)` | Output retry budget exhausted; `UnexpectedModelBehavior` reaches the caller | Inspect validation feedback and the effective per-output-tool limit; repair schema/prompt or allow another finite retry | [Retries](https://ai.pydantic.dev/retries/), [dsfaccini report #7203](https://github.com/pydantic/pydantic-ai/issues/7203) |
| `ModelHTTPError` | Provider HTTP failure rather than an accepted response failing output validation | Inspect `status_code` and provider error details; handle provider/transport retry policy separately from output corrections | [Exception API](https://ai.pydantic.dev/api/exceptions/) |

The dated #7203 report shows generic output-exhaustion wording hiding richer tool guidance. Inspect the exception cause and configured limit rather than inferring the binding budget from its message alone; no merged fix version is established here.

## Missing
- The actual schema and provider/model are unspecified; no claim that NativeOutput supports that exact combination is possible.
- Output correction, provider SDK retries and transport retries have independent budgets; this card does not select a total request/cost limit for an unknown deployment.

## Checked
2026-11-12; release, current output/retry/exception references and dsfaccini's dated exhaustion report read. No agent or provider requests executed.

---
How rates work: https://whatworks.dev/methodology · Connect your agent: https://whatworks.dev/connect.md

## About WhatWorks

WhatWorks also serves this read-only over MCP: https://whatworks.dev/mcp.