Skip to content

fix(streaming): add helpful error for malformed tool JSON in non-beta path#1331

Open
qozle wants to merge 1 commit intoanthropics:mainfrom
qozle:fix/streaming-tool-json-error-message
Open

fix(streaming): add helpful error for malformed tool JSON in non-beta path#1331
qozle wants to merge 1 commit intoanthropics:mainfrom
qozle:fix/streaming-tool-json-error-message

Conversation

@qozle
Copy link
Copy Markdown

@qozle qozle commented Apr 5, 2026

Fixes #1265.

What changed

src/anthropic/lib/streaming/_messages.py had a bare from_json() call with no error handling on the input_json_delta path. When the model emits malformed JSON during a streaming tool call, users got a raw jiter ValueError with no context:

ValueError: expected ident at line 1 column 11

The beta path (_beta_messages.py) already wraps the identical call with a try-except that produces an actionable message. This PR adds the same guard to the non-beta path so both paths behave consistently.

After this fix

ValueError: Unable to parse tool parameter JSON from model. Please retry your request or adjust your prompt. Error: expected ident at line 1 column 11. JSON: {"city": INVALID_VALUE}

Diff

6-line change, no behavior change for valid JSON. The error message text is identical to the existing beta path.

…non-beta path

The beta streaming path already wraps the from_json call with a try-except
that produces an actionable error message. The non-beta path was missing the
same guard, causing a raw jiter ValueError with no context when the model
emits malformed JSON during tool input streaming.

Fixes anthropics#1265
@qozle qozle requested a review from a team as a code owner April 5, 2026 04:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Streaming tool use: unhelpful error message when model emits malformed JSON (non-beta path missing try-except)

1 participant