{"record":{"id":"fa51a58c5b81199c","repo":"langchain-ai/langchain","slug":"function-raw-tool-call-function-name-argum","errorCode":null,"errorMessage":"Function {raw_tool_call['function']['name']} arguments:\n\n{arguments}\n\nare not valid JSON. Received JSONDecodeError {e}","messagePattern":"Function (.+?) arguments:\n\n(.+?)\n\nare not valid JSON\\. Received JSONDecodeError (.+?)","errorType":"exception","errorClass":"OutputParserException","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/output_parsers/openai_tools.py","lineNumber":69,"sourceCode":"\n    if partial:\n        try:\n            function_args = parse_partial_json(arguments, strict=strict)\n        except (JSONDecodeError, TypeError):  # None args raise TypeError\n            return None\n    # Handle None or empty string arguments for parameter-less tools\n    elif not arguments:\n        function_args = {}\n    else:\n        try:\n            function_args = json.loads(arguments, strict=strict)\n        except JSONDecodeError as e:\n            msg = (\n                f\"Function {raw_tool_call['function']['name']} arguments:\\n\\n\"\n                f\"{arguments}\\n\\nare not valid JSON. \"\n                f\"Received JSONDecodeError {e}\"\n            )\n            raise OutputParserException(msg) from e\n    parsed = {\n        \"name\": raw_tool_call[\"function\"][\"name\"] or \"\",\n        \"args\": function_args or {},\n    }\n    if return_id:\n        parsed[\"id\"] = raw_tool_call.get(\"id\")\n        parsed = create_tool_call(**parsed)  # type: ignore[assignment,arg-type]\n    return parsed\n\n\ndef make_invalid_tool_call(\n    raw_tool_call: dict[str, Any],\n    error_msg: str | None,\n) -> InvalidToolCall:\n    \"\"\"Create an `InvalidToolCall` from a raw tool call.\n\n    Args:\n        raw_tool_call: The raw tool call.","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/output_parsers/openai_tools.py#L51-L87","documentation":"Raised by parse_tool_call in openai_tools.py when the raw tool call's 'arguments' string fails json.loads (non-partial mode). The message includes the function name, the raw arguments text, and the underlying JSONDecodeError so you can see exactly what the model emitted that was invalid JSON.","triggerScenarios":"Model returns tool_call arguments that are malformed JSON (truncated by max_tokens, unquoted keys, Python-repr dicts); arguments contain raw newlines/control characters while strict=True. Note: None or empty-string arguments are treated as {} and do NOT raise; the partial=True path swallows errors instead.","commonSituations":"Tight max_tokens truncating tool arguments mid-JSON; smaller/local models emitting invalid JSON; strict json.loads rejecting otherwise-usable output with control characters.","solutions":["Raise max_tokens so tool call arguments are not cut off","Use strict=False in the parser (or parse_partial_json-based streaming) to tolerate non-JSON-compliant strings","Catch OutputParserException, log the raw arguments, and retry the model call or repair the JSON"],"exampleFix":"# before\ntool_calls = parse_tool_call(raw_tool_call, strict=True)\n\n# after\ntool_calls = parse_tool_call(raw_tool_call, strict=False)  # tolerate control chars/newlines","handlingStrategy":"try-catch","validationCode":"import json\nargs = raw_tool_call[\"function\"][\"arguments\"]\nif args:\n    try:\n        json.loads(args)\n    except json.JSONDecodeError as e:\n        ...  # repair or drop before calling parse_tool_call","typeGuard":null,"tryCatchPattern":"from langchain_core.exceptions import OutputParserException\ntry:\n    tc = parse_tool_call(raw_tool_call, strict=False)\nexcept OutputParserException as e:\n    invalid = make_invalid_tool_call(raw_tool_call, str(e))  # keep going with an InvalidToolCall","preventionTips":["Use strict=False for lenient JSON parsing","Budget enough max_tokens for full tool arguments"],"tags":["tool-calling","json","output-parsing","openai"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}