fix: add missing JSON error handling in non-beta streaming accumulator#1266
Open
AbdoKnbGit wants to merge 1 commit intoanthropics:mainfrom
Open
fix: add missing JSON error handling in non-beta streaming accumulator#1266AbdoKnbGit wants to merge 1 commit intoanthropics:mainfrom
AbdoKnbGit wants to merge 1 commit intoanthropics:mainfrom
Conversation
793acd3 to
9fcc51b
Compare
Author
|
@claude @karpetrosyan hi can you review this |
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.
Fixes #1265
The beta streaming accumulator (
_beta_messages.py) wrapsfrom_json()in atry-except that gives users a clear, actionable error when the model emits
malformed tool input JSON. The non-beta accumulator (
_messages.py) was missingthe same handler — causing users to see raw jiter errors with no context.
This PR adds the matching try-except to the non-beta path and a test mirroring
the existing beta test.
Changes
src/anthropic/lib/streaming/_messages.py— wrapfrom_json()at L480in a try-except with a helpful error message, matching
_beta_messages.pyL500-510tests/lib/streaming/test_partial_json.py— addtest_partial_json_with_invalid_json_non_beta, mirroring the existing beta testBefore / After
Before — non-beta path, malformed tool JSON:
No context. No mention of tool JSON. Looks like an SDK crash.
After — matches beta behavior:
Test plan
test_partial_json_with_invalid_json_non_betapassesclaude-haiku-4-5