TECHNOLOGY

Pydantic AI ToolFailed and ModelRetry send different feedback

In this article
THE QUICK TAKE

Use tool failure feedback to describe the actual outcome, and distinguish terminal reporting from asking the model to repair arguments or regenerate output.

Classify what another attempt could change

A document tool receives an unsupported resource type. Repeating the identical operation cannot make that implementation support it. Pydantic AI’s exception reference provides ToolFailed to report a terminal tool failure to the model. ModelRetry instead asks the model to try again with correction feedback. Choose according to whether the model can usefully change the request, rather than using retry feedback as the universal representation of any unhappy outcome.

Understand what ToolFailed sends back

The reference describes a failed tool result visible to the model without prepended retry or correction instructions. It also does not consume the tool’s retry budget. The model can then adapt its plan to the reported failure. This is not a permanent prohibition preventing the model from selecting that tool again; the documentation recommends run-level usage limits for bounding repeated failures. Keep terminal status of this invocation separate from future tool-selection policy.

Keep feedback retries separate from network recovery

The retry guide distinguishes model correction from transport or SDK recovery. A tool-call correction can change arguments and produce another reasoning turn. A network retry repeats an attempted communication beneath that behavior. If the underlying service is temporarily unavailable, investigate the relevant recovery layer instead of presenting an application-level correction prompt as proof that the same external operation was retried under a transport policy.

Do not reuse the exception blindly in output validation

The output guide explicitly says output validators do not support ToolFailed. There it behaves as an ordinary exception: an appropriate error-processing hook can recover, otherwise the run aborts. Use ModelRetry when an output validator is asking for another output. The same exception name therefore cannot be moved from a tool body into a final-output validator with an assumption that its model-visible failure semantics remain identical.

Show the consumer what remains possible

Return a useful failure explanation, such as unsupported format, without inventing a successful document observation. Task contracts identify acceptable alternatives; tool observations preserve failed and successful evidence separately. The agent may choose another source or explain the gap. A deliberate terminal failure supports that adaptation while avoiding misleading correction instructions for an operation whose unchanged arguments cannot resolve the limitation.

Earn rental income from GPUs

Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.

Explore GPU hosting
← All articles