fix(runtime): distinguish request parse errors from handler JSON errors#472
Merged
Merged
Conversation
The broad try/except around _handle_invocation caught json.JSONDecodeError from both request.json() (inbound payload) and the user's handler logic, reporting both as "Invalid JSON in request" with HTTP 400. This misled engineers into debugging caller payloads when the root cause was downstream application/model-output parsing. Narrow the JSONDecodeError and UnicodeDecodeError catches to only cover request body parsing. Handler-raised exceptions now fall through to the generic Exception handler (HTTP 500) with an accurate error message. Constraint: Runtime contract returns 4xx for request-level errors only Rejected: Catch handler JSONDecodeError separately with 422 | no precedent in runtime contract Confidence: high Scope-risk: narrow Not-tested: Streaming handlers that raise JSONDecodeError mid-stream
Contributor
✅ No Breaking Changes DetectedNo public API breaking changes found in this PR. |
Hweinstock
reviewed
May 12, 2026
Contributor
Hweinstock
left a comment
There was a problem hiding this comment.
nice fix! Is it possible to verify this with a unit test or even better an integ test?
Contributor
Author
Note on CIThe All relevant checks pass: Test (runtime), Test Python 3.10–3.13, Compat (runtime), Lint and Format. |
cf66a03 to
7351c78
Compare
Contributor
lint failing, otherwise LGTM. Thanks for adding the test! |
Ensures that a JSONDecodeError raised inside the user's handler returns HTTP 500 (application error), not HTTP 400 "Invalid JSON" which misleadingly implies the inbound request payload was malformed.
7351c78 to
040b523
Compare
Hweinstock
approved these changes
May 12, 2026
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.
Summary
json.JSONDecodeError(e.g., parsing model output)JSONDecodeError/UnicodeDecodeErrorcatches to only coverrequest.json()parsingResolves V2192037347 — customer reported AgentCore runtime surfaces misleading error classification for downstream application JSON parsing errors.
Test plan
JSONDecodeErrorpreviously returned 400 "Invalid JSON"JSONDecodeErrornow returns 500 with actual error