Skip to content

test(litellm): cover the tool call that carries no arguments - #5010

Open
yasumorishima wants to merge 1 commit into
google:mainfrom
yasumorishima:fix/malformed-tool-call-json
Open

test(litellm): cover the tool call that carries no arguments#5010
yasumorishima wants to merge 1 commit into
google:mainfrom
yasumorishima:fix/malformed-tool-call-json

Conversation

@yasumorishima

@yasumorishima yasumorishima commented Mar 26, 2026

Copy link
Copy Markdown

The malformed-JSON handling this PR originally proposed landed in 6e59663 (Close #5896), with better semantics than mine: it dispatches the call with empty arguments so the tool can return a structured error and the model can retry, instead of dropping the call. I have rebased onto that and dropped my source change in favour of it.

What is left is one case that commit did not cover. _parse_tool_call_arguments returns {} for a falsy arguments (src/google/adk/models/lite_llm.py:203-204), so a tool call carrying no arguments is dispatched with empty args and is not reported as malformed. On main the only empty arguments outside that guard is a streaming fixture accumulating a JSON payload split across chunks, and 6e59663's own tests cover the JSONDecodeError path and its streaming equivalent.

The distinction is not visible in the output alone: with the guard removed, "" falls through to except json.JSONDecodeError and still yields {}. The only difference is the warning. So the test asserts the empty args and that nothing was logged as malformed — I checked that removing the guard makes it fail.

Tests only, no source change. pytest tests/unittests/models/test_litellm.py → 422 passed.

🤖 Generated with Claude Code

@rohityan rohityan self-assigned this Mar 26, 2026
@yasumorishima
yasumorishima force-pushed the fix/malformed-tool-call-json branch from c670d6c to 3809fd5 Compare March 26, 2026 17:53
@rohityan rohityan added models [Component] This issue is related to model support needs review [Status] The PR/issue is awaiting review from the maintainer labels Apr 13, 2026
@rohityan

Copy link
Copy Markdown
Collaborator

Hi @yasumorishima , Thank you for your contribution! We appreciate you taking the time to submit this pull request. Your PR has been received by the team and is currently under review. We will provide feedback as soon as we have an update to share.

@rohityan

Copy link
Copy Markdown
Collaborator

Hi @wukath , can you please review this.

@yasumorishima
yasumorishima force-pushed the fix/malformed-tool-call-json branch from a8b3c45 to 9a581fc Compare May 3, 2026 03:56
@yasumorishima
yasumorishima force-pushed the fix/malformed-tool-call-json branch from 4a9e34b to dbe7c09 Compare September 5, 2026 01:03
@yasumorishima yasumorishima changed the title fix: handle malformed JSON in LiteLLM tool call arguments gracefully test: cover tool calls whose arguments are None or an empty string Sep 5, 2026
@yasumorishima
yasumorishima force-pushed the fix/malformed-tool-call-json branch from dbe7c09 to 622103a Compare September 5, 2026 01:29
`_parse_tool_call_arguments` returns `{}` for a falsy `arguments`
(src/google/adk/models/lite_llm.py:203-204), so a tool call that carries no
arguments is dispatched with empty args and is *not* reported as malformed.
Nothing covered that: test_litellm.py has no case with empty arguments outside
a streaming fixture that accumulates a JSON payload split across chunks, and
6e59663 covers the JSONDecodeError path and its streaming equivalent.

The distinction matters because the output alone cannot tell the two apart.
With the guard removed, `""` falls through to `except json.JSONDecodeError`
and still yields `{}` -- the only difference is the warning. So the test
asserts the empty args *and* that nothing was logged as malformed; removing
the guard makes it fail.

The malformed-JSON handling this PR originally proposed landed in 6e59663
(Close google#5896) with better semantics than mine -- dispatch with empty arguments
so the tool can return a structured error and the model can retry, rather than
dropping the call -- so the source change is dropped in favour of upstream's.
@yasumorishima
yasumorishima force-pushed the fix/malformed-tool-call-json branch from 622103a to acfb83a Compare September 5, 2026 02:02
@yasumorishima yasumorishima changed the title test: cover tool calls whose arguments are None or an empty string test(litellm): cover the tool call that carries no arguments Sep 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

models [Component] This issue is related to model support needs review [Status] The PR/issue is awaiting review from the maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[LiteLlm] JSONDecodeError on malformed tool_call.function.arguments still crashes invocation at v2.0.0 (regression of #5008)

2 participants