Skip to content

[LiteLlm] JSONDecodeError on malformed tool_call.function.arguments crashes run before callbacks can recover #5008

Closed

Description

@Huzefa-Lw

🔴 Required Information

Please ensure all items in this section are completed to allow for efficient
triaging. Requests without complete information may be rejected / deprioritized.
If an item is not applicable to you - please mark it as N/A

Describe the Bug:
When ADK parses tool calls from a LiteLLM response, it uses strict JSON parsing in google/adk/models/lite_llm.py (json.loads(tool_call.function.arguments or "{}")).
If the model returns malformed or truncated JSON in tool_call.function.arguments, ADK throws JSONDecodeError and fails the invocation.

Steps to Reproduce:

  1. Install google-adk==1.21.0 and litellm.
  2. Run an ADK flow with LiteLLM where the model emits a function call.
  3. Ensure tool_call.function.arguments is malformed JSON (for example, an unterminated string).
  4. Observe crash/stacktrace at google/adk/models/lite_llm.py in _message_to_generate_content_response.

Expected Behavior:
ADK should gracefully handle malformed tool argument JSON from the model (e.g., recoverable model error path and retry/fallback) instead of hard-failing the run.

Observed Behavior:
Invocation/workflow fails with JSONDecodeError while parsing tool call arguments, e.g.:
JSONDecodeError: Unterminated string starting at: line 1 column 2 (char 1)

Environment Details:

  • ADK Library Version (pip show google-adk): 1.21.0
  • Desktop OS:** macOS (Darwin 25.2.0)
  • Python Version (python -V): Python 3.12.11

Model Information:

  • Are you using LiteLLM: Yes
  • Which model is being used: OpenAI-compatible model via LiteLLM (configured via app settings as vat_llm_model)

🟡 Optional Information

Providing this information greatly speeds up the resolution process.

Regression:
Observed before and after upgrade; still reproducible on 1.21.0.

Logs:

File ".../google/adk/models/lite_llm.py", line 1057, in _message_to_generate_content_response
    args=json.loads(tool_call.function.arguments or "{}"),
File "/usr/local/lib/python3.12/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
File "/usr/local/lib/python3.12/json/decoder.py", line 354, in raw_decode
    obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Unterminated string starting at: line 1 column 2 (char 1)

Screenshots / Video:
N/A

Additional Context:
Tool-level callbacks/plugins do not help for this specific case because the failure happens in LiteLLM response parsing before tool execution callbacks run.

Minimal Reproduction Code:

from types import SimpleNamespace
from google.adk.models.lite_llm import _message_to_generate_content_response

tool_call = SimpleNamespace(
    type="function",
    id="call_1",
    function=SimpleNamespace(
        name="demo_tool",
        arguments='{"a":"unterminated'
    ),
)

message = {
    "role": "assistant",
    "content": None,
    "tool_calls": [tool_call],
}

# Raises JSONDecodeError in ADK parser
_message_to_generate_content_response(message)

How often has this issue occurred?:

  • Once / Rare

Activity

  1. added
    models
    on Mar 26, 2026
  2. added theissue type on Mar 26, 2026
  3. added 2 commits that reference this issue on Mar 26, 2026
    7368414
    1519a4d
  4. self-assigned this
    on Apr 13, 2026
  5. rohityan commented on Apr 13, 2026

    @rohityan
    Collaborator

    Hi @Huzefa-Lw , can you use the latest adk version and check if the issue still persists.

  6. added
    request clarification
    on Apr 13, 2026
  7. Huzefa-Lw commented on Apr 14, 2026

    @Huzefa-Lw
    Author

    It's working now. Thanks for taking this up!

  8. added a commit that references this issue on May 3, 2026
    fd71504
  9. NerdSmith commented on May 5, 2026

    @NerdSmith

    This problem still persists in version 1.32.0

  10. removed
    request clarification
    on May 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

models

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions