sentry-python icon indicating copy to clipboard operation
sentry-python copied to clipboard

Pydantic AI integration erroneously considers `ToolRetryError` to be unhandled

Open JakobGM opened this issue 1 month ago • 2 comments

How do you use Sentry?

Sentry Saas (sentry.io)

Version

2.47.0

Description

Pydantic AI's internal machinery raises pydantic_ai.exceptions.ToolRetryError when the output of a model does not satisfy the specified output schema. This exception is then caught further up the call-stack by Pydantic AI, which allows the LLM to be provided with the error and try again.

Sentry SDK's PydanticAIIntegration erroneously considers this exception to be unhandled, I think here in _patch_tool_execution(). This type of exception should probably be ignored by Sentry.

If you have access to our Sentry account for debugging purposes, you can take a look at this issue which should not have been an issue in the first place. If not, here are some screenshots:

Screenshots

Image Image

JakobGM avatar Dec 15 '25 09:12 JakobGM

PY-2014

linear[bot] avatar Dec 15 '25 09:12 linear[bot]

Hi @JakobGM,

Thanks for the report and explanation. We will address this and keep you updated.

alexander-alderman-webb avatar Dec 15 '25 09:12 alexander-alderman-webb

Hi @JakobGM,

We added an option to suppress these exceptions, and now report them as handled. Please initialize the integration as follows to stop seeing issues of this kind in your Sentry.

sentry_init(
    ...
    integrations=[PydanticAIIntegration(handled_tool_call_exceptions=False)],
)

alexander-alderman-webb avatar Dec 16 '25 13:12 alexander-alderman-webb