{"record":{"id":"5c31dbd91445ba22","repo":"BerriAI/litellm","slug":"failed-to-parse-tool-call-arguments-error-origi","errorCode":null,"errorMessage":"Failed to parse tool call arguments. Error: {original_error}. Arguments: {arguments}","messagePattern":"Failed to parse tool call arguments\\. Error: (.+?)\\. Arguments: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/litellm_core_utils/prompt_templates/common_utils.py","lineNumber":1801,"sourceCode":"                \"Repaired truncated tool call arguments for tool '%s' (%s). Original (%d chars): %.200s%s\",\n                tool_name or \"<unknown>\",\n                context or \"unknown context\",\n                len(arguments),\n                arguments,\n                \"...\" if len(arguments) > 200 else \"\",\n            )\n            return repaired\n\n        error_parts: Final = [\"Failed to parse tool call arguments\"]\n\n        if tool_name:\n            error_parts.append(f\"for tool '{tool_name}'\")\n        if context:\n            error_parts.append(f\"({context})\")\n\n        error_message: Final = \" \".join(error_parts) + f\". Error: {original_error}. Arguments: {arguments}\"\n\n        raise ValueError(error_message) from original_error\n\n\ndef split_concatenated_json_objects(raw: str) -> list[dict[str, Any]]:\n    \"\"\"\n    Split a string that contains one or more concatenated JSON objects into\n    a list of parsed dicts.\n\n    LLM providers (notably Bedrock Claude Sonnet 4.5) sometimes return\n    multiple tool-call argument objects concatenated in a single\n    ``arguments`` string, e.g.::\n\n        '{\"command\":[\"curl\",...]}{\"command\":[\"curl\",...]}{\"command\":[\"curl\",...]}'\n\n    ``json.loads()`` fails on this with ``JSONDecodeError: Extra data``.\n    This helper uses ``json.JSONDecoder.raw_decode()`` to walk the string\n    and extract each JSON object individually.\n\n    Returns","sourceCodeStart":1783,"sourceCodeEnd":1819,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/litellm_core_utils/prompt_templates/common_utils.py#L1783-L1819","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before: single shot\nresp = litellm.completion(model=\"bedrock/...\")\n\n# after: bounded retry on unparseable arguments\nfor attempt in range(3):\n    try:\n        resp = litellm.completion(model=\"bedrock/...\", messages=messages, tools=tools)\n        break\n    except ValueError as e:\n        if \"Failed to parse tool call arguments\" not in str(e) or attempt == 2:\n            raise","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"import litellm\n\nMAX_ATTEMPTS = 3\nfor attempt in range(1, MAX_ATTEMPTS + 1):\n    try:\n        resp = litellm.completion(model=model, messages=messages, tools=tools, max_tokens=4096)\n        break\n    except ValueError as e:\n        if \"Failed to parse tool call arguments\" not in str(e):\n            raise\n        if attempt == MAX_ATTEMPTS:\n            # log str(e): it contains the raw arguments for debugging\n            raise\n        # optional: append a corrective nudge before retrying","preventionTips":["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"],"tags":["tool-calling","json","model-output"],"backgroundTag":"invalid-json-tool-call-arguments","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}