Skip to content

Fix unhandled JSONDecodeError in AnthropicClient tool call parsing#69

Open
hobostay wants to merge 1 commit into
antoinezambelli:mainfrom
hobostay:fix/anthropic-json-error
Open

Fix unhandled JSONDecodeError in AnthropicClient tool call parsing#69
hobostay wants to merge 1 commit into
antoinezambelli:mainfrom
hobostay:fix/anthropic-json-error

Conversation

@hobostay
Copy link
Copy Markdown

Summary

  • json.loads(args) in _convert_messages was called without a try/except when parsing tool call arguments
  • Malformed JSON in arguments would raise an unhandled json.JSONDecodeError, crashing the inference loop with an unhelpful traceback
  • Wrap in try/except and fall back to empty dict on parse failure, consistent with LlamafileClient's handling

Impact

  • Without this fix, malformed tool call arguments from upstream systems would crash the entire inference loop instead of producing a recoverable error

Test plan

  • Verify malformed JSON in tool call arguments doesn't crash the client
  • Verify valid JSON arguments still parse correctly
  • Run existing test suite

🤖 Generated with Claude Code

`json.loads(args)` in `_convert_messages` was called without a
try/except. If the upstream system passes malformed JSON in tool call
arguments, this raises an unhandled `json.JSONDecodeError` that
propagates as an uncaught exception, crashing the inference loop with
an unhelpful traceback instead of a recoverable error.

Wrap in try/except and fall back to empty dict on parse failure,
consistent with how LlamafileClient handles the same case.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.

1 participant