Skip to content

fix(tool-search): accept whitespace-only tool_call arguments as {}#1174

Merged
Lexus2016 merged 1 commit into
mainfrom
fix/tool-call-whitespace-arguments
Jul 19, 2026
Merged

fix(tool-search): accept whitespace-only tool_call arguments as {}#1174
Lexus2016 merged 1 commit into
mainfrom
fix/tool-call-whitespace-arguments

Conversation

@Lexus2016

Copy link
Copy Markdown
Owner

What

Follow-up hardening to #1170. resolve_underlying_call normalized only an
exact empty string (arguments == "") to {}; a whitespace-only value
(" ", "\n", a stray tab/newline from provider tokenization) still fell
through to json.loads and produced a confusing tool_call 'arguments' is not valid JSON error that the model loops on.

Change

  • tools/tool_search.py: widen the check from raw_args == "" to
    raw_args.strip() == "". json.loads already trims whitespace around a
    real 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 as
fragile against tokenization variants. This closes that gap.

Testing

  • pytest tests/tools/test_tool_search.py → all green (incl. 6 new params).
  • ruff check clean on both files.

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.
@Lexus2016
Lexus2016 merged commit 926b698 into main Jul 19, 2026
35 checks passed
@Lexus2016
Lexus2016 deleted the fix/tool-call-whitespace-arguments branch July 19, 2026 09:19
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