microsoft/graphrag · error · ValueError
Failed to parse arguments for function '{function_name}': {e
Error message
Failed to parse arguments for function '{function_name}': {e} What it means
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.
Source
Thrown at packages/graphrag-llm/graphrag_llm/utils/function_tool_manager.py:130
continue
tool_id = tool_call.id
function_name = tool_call.function.name
function_args = tool_call.function.arguments
if function_name not in self._tools:
msg = f"Function '{function_name}' not registered."
raise ValueError(msg)
tool_def = self._tools[function_name]
input_model = tool_def["input_model"]
function = tool_def["function"]
try:
parsed_args_dict = json.loads(function_args)
input_model_instance = input_model(**parsed_args_dict)
except Exception as e:
msg = f"Failed to parse arguments for function '{function_name}': {e}"
raise ValueError(msg) from e
result = function(input_model_instance)
tool_messages.append({
"content": result,
"tool_call_id": tool_id,
})
return tool_messages
View on GitHub (pinned to f40e9a26ce)
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
Example fix
# before
class GetWeatherInput(BaseModel):
unit: str # model sends 5 -> parse error
# after
from typing import Union
class GetWeatherInput(BaseModel):
unit: Union[str, int] = 'celsius' Defensive patterns
Strategy: try-catch
Validate before calling
import json
def args_parseable(raw: str, model) -> bool:
try:
model(**json.loads(raw))
return True
except Exception:
return False Type guard
null
Try / catch
try:
tool_messages = manager.call_functions(response)
except ValueError as e:
if 'Failed to parse arguments' in str(e):
# re-ask the model with the validation error appended to the conversation
...
else:
raise Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
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
AI-assisted analysis of microsoft/graphrag@f40e9a26ce (2026-08-27).
Data as JSON: /api/errors/4129b35e03419e74.
Report an issue: GitHub.