BerriAI/litellm · error · ValueError
Failed to parse tool call arguments. Error
Error message
Failed to parse tool call arguments. Error: {original_error}. Arguments: {arguments} What it means
The model returned tool call arguments that are not valid JSON, and litellm's repair chain (including splitting concatenated JSON objects) also failed. This is the final raise after all repair attempts, and it includes the original parser error, the tool name, and the raw arguments so you can see exactly what the model emitted.
Solutions
- Retry the request - transient model sloppiness often resolves on the next attempt
- Increase max_tokens so arguments are not truncated mid-JSON
- Switch to a model with reliable JSON tool-call output
- Simplify the tool's parameter schema (fewer and shorter fields)
- Log the arguments from the error text to spot systematic syntax problems and pre-clean them
Example fix
# before: single shot
resp = litellm.completion(model="bedrock/...")
# after: bounded retry on unparseable arguments
for attempt in range(3):
try:
resp = litellm.completion(model="bedrock/...", messages=messages, tools=tools)
break
except ValueError as e:
if "Failed to parse tool call arguments" not in str(e) or attempt == 2:
raise Defensive patterns
Strategy: retry
Try / catch
import litellm
MAX_ATTEMPTS = 3
for attempt in range(1, MAX_ATTEMPTS + 1):
try:
resp = litellm.completion(model=model, messages=messages, tools=tools, max_tokens=4096)
break
except ValueError as e:
if "Failed to parse tool call arguments" not in str(e):
raise
if attempt == MAX_ATTEMPTS:
# log str(e): it contains the raw arguments for debugging
raise
# optional: append a corrective nudge before retrying Prevention
- Set max_tokens generously so tool arguments never truncate mid-JSON
- Prefer models with strong structured-output/tool-calling track records
- Keep tool parameter schemas small and flat
- Log the arguments field from the error - systematic syntax bugs are visible immediately
When it happens
Trigger: Weaker models emitting single quotes, trailing commas, or unquoted keys in arguments; arguments truncated by a max_tokens limit; multiple JSON objects concatenated in one arguments string that do not split cleanly; forced tool_choice with a schema the model cannot satisfy.
Common situations: Small or open-weight models with sloppy JSON output; long tool arguments hitting the token cap; prompts that ask the model to 'call the function' in prose and get malformed output.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- AgentCore: Failed to read/parse JSON response body
- BedrockException - . Enable 'litellm.modify_params=True'…
- is not valid JSON. Please fix or remove it!
- Chat provider: Invalid function argument delta
- Cisco AI Defense API returned a non-JSON response
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/5c31dbd91445ba22.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/litellm_core_utils/prompt_templates/common_utils.py:1801
"Repaired truncated tool call arguments for tool '%s' (%s). Original (%d chars): %.200s%s",
tool_name or "<unknown>",
context or "unknown context",
len(arguments),
arguments,
"..." if len(arguments) > 200 else "",
)
return repaired
error_parts: Final = ["Failed to parse tool call arguments"]
if tool_name:
error_parts.append(f"for tool '{tool_name}'")
if context:
error_parts.append(f"({context})")
error_message: Final = " ".join(error_parts) + f". Error: {original_error}. Arguments: {arguments}"
raise ValueError(error_message) from original_error
def split_concatenated_json_objects(raw: str) -> list[dict[str, Any]]:
"""
Split a string that contains one or more concatenated JSON objects into
a list of parsed dicts.
LLM providers (notably Bedrock Claude Sonnet 4.5) sometimes return
multiple tool-call argument objects concatenated in a single
``arguments`` string, e.g.::
'{"command":["curl",...]}{"command":["curl",...]}{"command":["curl",...]}'
``json.loads()`` fails on this with ``JSONDecodeError: Extra data``.
This helper uses ``json.JSONDecoder.raw_decode()`` to walk the string
and extract each JSON object individually.
ReturnsView on GitHub (pinned to 77b7c6c40c)