fix(tool-search): accept whitespace-only tool_call arguments as {}#1174
Merged
Conversation
Follow-up to #1170/#1173. Providers and intermediary gateways can emit not just "" but whitespace-only `arguments` (a stray space or newline from tokenization quirks). Widen the empty-args normalization from an exact `== ""` check to `.strip() == ""` so these also resolve to {} instead of hitting json.loads and surfacing a confusing "not valid JSON" error that the model loops on. json.loads already trims whitespace around a real value, so this only widens the genuinely-empty case and cannot mask a valid payload. Adds a parametrized test covering "", " ", " ", "\n", "\t" and mixed whitespace.
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.
What
Follow-up hardening to #1170.
resolve_underlying_callnormalized only anexact empty string (
arguments == "") to{}; a whitespace-only value(
" ","\n", a stray tab/newline from provider tokenization) still fellthrough to
json.loadsand produced a confusingtool_call 'arguments' is not valid JSONerror that the model loops on.Change
tools/tool_search.py: widen the check fromraw_args == ""toraw_args.strip() == "".json.loadsalready trims whitespace around areal value, so this only widens the genuinely-empty case and cannot mask a
valid payload.
tests/tools/test_tool_search.py: add a parametrized test covering""," "," ","\n","\t", and mixed whitespace.Why now
Independent review of #1170 (two AI advisors) flagged the exact-
""check asfragile against tokenization variants. This closes that gap.
Testing
pytest tests/tools/test_tool_search.py→ all green (incl. 6 new params).ruff checkclean on both files.