More accurate handling of LLM errors - #931
Merged
DavidMStraub merged 3 commits intoAug 12, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves how failures from the Pydantic AI agent / model provider are translated into HTTP errors, and adds regression tests to ensure specific exception types map to stable status codes.
Changes:
- Add targeted exception handling in
answer_with_agent()to distinguish provider HTTP errors (502) from transport/API failures (504). - Switch unexpected-error logging to
logger.exception(...)for better traceback visibility. - Add a new pytest suite validating the status-code mapping for common agent/provider failure modes.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
gramps_webapi/api/llm/__init__.py |
Refines exception-to-HTTP-status mapping for LLM agent execution errors. |
tests/test_llm_errors.py |
Adds parametrized tests asserting the expected HTTP status codes for representative LLM/agent exceptions. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
DavidMStraub
requested
a lite review from Copilot
and removed request for
Copilot
August 12, 2026 07:51
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (1)
gramps_webapi/api/llm/init.py:203
httpx.TransportErroris broader than timeouts (it covers connect/protocol/other transport failures), but this handler maps all transport errors to HTTP 504 (gateway timeout). That will misclassify non-timeout upstream failures; consider catchinghttpx.TimeoutExceptionseparately for 504 and using a different status (e.g. 503) for other transport errors.
except (ModelAPIError, httpx.TransportError) as e:
# network failure or timeout talking to the provider
logger.error("Model provider request failed: %r", e)
abort_with_message(504, "The AI model did not respond. Please try again.")
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.