fix(core): handle None arguments in parse_tool_call #34242
+83
−7
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.
Description
When an LLM calls a parameter-less tool, some providers return
Noneor an empty string for theargumentsfield instead of valid JSON like"{}". This causedparse_tool_callto raise aTypeErrorbecausejson.loads(None)is not valid.Problem
Solution
Added a check to handle
Noneand empty string arguments by treating them as an empty object{}, allowing parameter-less tools to be parsed correctly.This is a minimal, targeted fix that:
Nonearguments → returns{}""arguments → returns{}Testing
Added 4 new unit tests:
test_parse_tool_call_with_none_arguments- reproduces the original bugtest_parse_tool_call_with_empty_string_arguments- handles empty stringstest_parse_tool_call_with_valid_arguments- ensures normal behavior workstest_parse_tool_call_partial_mode_with_none_arguments- verifies partial mode behaviorAll existing tests continue to pass.
AI Disclosure: This PR was developed with assistance from Claude (AI).
Fixes #34123