Repository navigation
Description
🔴 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:
- Install
google-adk==1.21.0andlitellm. - Run an ADK flow with LiteLLM where the model emits a function call.
- Ensure
tool_call.function.argumentsis malformed JSON (for example, an unterminated string). - Observe crash/stacktrace at
google/adk/models/lite_llm.pyin_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
fix: handle malformed JSON in tool call arguments gracefully
fix: handle malformed JSON in tool call arguments gracefully
rohityan commentedon Apr 13, 2026
Hi @Huzefa-Lw , can you use the latest adk version and check if the issue still persists.
Huzefa-Lw commentedon Apr 14, 2026
It's working now. Thanks for taking this up!
fix: handle malformed JSON in tool call arguments gracefully
NerdSmith commentedon May 5, 2026
This problem still persists in version 1.32.0
fix: surface MALFORMED_FUNCTION_CALL so on_model_error can recover
fix: surface MALFORMED_FUNCTION_CALL so on_model_error can recover