Skip to content

Parse and display exceptions in a more user-friendly way #1535

@marmor7

Description

@marmor7

Description

We're using pydantic-ai and just started using logfire as well.

When an agent run receives an error from the provider, logfire would parse the error and display at the top of the Exception Traceback the exact issue like:

pydantic_ai.exceptions.ModelHTTPError: status_code: 400, model_name: gpt-5-mini, body: {'message': 'Input tokens exceed the configured limit of 272000 tokens. Your messages resulted in 382581 tokens. Please reduce the length of the messages.', 'type': 'invalid_request_error', 'param': 'messages', 'code': 'context_length_exceeded'}

This is great as you immediately see and understand what the issue was.

However if you're using FallbackModel (which we do across all our agents), the red summary at the top shows:

pydantic_ai.exceptions.FallbackExceptionGroup: All models from FallbackModel failed (2 sub-exceptions)

which doesn't mean anything, and you need to dig into the massive dump at the bottom to find the cause.

Same goes for the retry mechanism, e.g. for non-provider exceptions, the red summary at the top shows:

pydantic_ai.exceptions.UnexpectedModelBehavior: Tool 'documents_analyzer' exceeded max retries count of 1

which is again meaningless and you have to find the cause yourself.

would be nice to see the underlining issue ("context_length_exceeded") in all 3 cases.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions