{"record":{"id":"4129b35e03419e74","repo":"microsoft/graphrag","slug":"failed-to-parse-arguments-for-function-function","errorCode":null,"errorMessage":"Failed to parse arguments for function '{function_name}': {e}","messagePattern":"Failed to parse arguments for function '(.+?)': (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"packages/graphrag-llm/graphrag_llm/utils/function_tool_manager.py","lineNumber":130,"sourceCode":"                continue\n            tool_id = tool_call.id\n            function_name = tool_call.function.name\n            function_args = tool_call.function.arguments\n\n            if function_name not in self._tools:\n                msg = f\"Function '{function_name}' not registered.\"\n                raise ValueError(msg)\n\n            tool_def = self._tools[function_name]\n            input_model = tool_def[\"input_model\"]\n            function = tool_def[\"function\"]\n\n            try:\n                parsed_args_dict = json.loads(function_args)\n                input_model_instance = input_model(**parsed_args_dict)\n            except Exception as e:\n                msg = f\"Failed to parse arguments for function '{function_name}': {e}\"\n                raise ValueError(msg) from e\n\n            result = function(input_model_instance)\n            tool_messages.append({\n                \"content\": result,\n                \"tool_call_id\": tool_id,\n            })\n\n        return tool_messages\n","sourceCodeStart":112,"sourceCodeEnd":139,"githubUrl":"https://github.com/microsoft/graphrag/blob/f40e9a26ce62ba0b3fef8837d24aafdcc6e6c704/packages/graphrag-llm/graphrag_llm/utils/function_tool_manager.py#L112-L139","documentation":"After resolving a registered function, call_functions json.loads the model-produced arguments and validates them against the function's Pydantic input model. Any JSON parse error or Pydantic validation failure is re-raised as ValueError with the underlying exception chained.","triggerScenarios":"The LLM returns tool arguments that are malformed JSON (truncated output, stray commas) or valid JSON that violates the input model's field types/required fields, e.g. {\"unit\": 5} where a string is expected.","commonSituations":"Low temperature/max_tokens truncation producing invalid JSON, schema drift between the Pydantic model and what the prompt tells the model, models emitting JSON wrapped in markdown fences, or missing required fields.","solutions":["Log the raw tool_call.function.arguments to see what the model actually sent","Loosen or fix the Pydantic input model (Optional fields, correct types) to match realistic model output","Improve the tool description / system prompt with an explicit JSON schema and examples","Increase max_tokens so arguments aren't truncated; strip markdown fences before calling if the model adds them"],"exampleFix":"# before\nclass GetWeatherInput(BaseModel):\n    unit: str  # model sends 5 -> parse error\n\n# after\nfrom typing import Union\nclass GetWeatherInput(BaseModel):\n    unit: Union[str, int] = 'celsius'","handlingStrategy":"try-catch","validationCode":"import json\ndef args_parseable(raw: str, model) -> bool:\n    try:\n        model(**json.loads(raw))\n        return True\n    except Exception:\n        return False","typeGuard":"null","tryCatchPattern":"try:\n    tool_messages = manager.call_functions(response)\nexcept ValueError as e:\n    if 'Failed to parse arguments' in str(e):\n        # re-ask the model with the validation error appended to the conversation\n        ...\n    else:\n        raise","preventionTips":["Give each tool an explicit JSON schema and few-shot example in its description","Set generous max_tokens; strip markdown fences from raw arguments before validation","Use Pydantic models with defaults/Optional for fields models commonly omit or mis-type"],"tags":["function-calling","json","pydantic","llm"],"backgroundTag":"llm-tool-arguments-validation-failed","analyzedSha":"f40e9a26ce62ba0b3fef8837d24aafdcc6e6c704","analyzedAt":"2026-08-27T11:16:29.677Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}