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

  1. Log the raw tool_call.function.arguments to see what the model actually sent
  2. Loosen or fix the Pydantic input model (Optional fields, correct types) to match realistic model output
  3. Improve the tool description / system prompt with an explicit JSON schema and examples
  4. 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

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

Related errors


AI-assisted analysis of microsoft/graphrag@f40e9a26ce (2026-08-27). Data as JSON: /api/errors/4129b35e03419e74. Report an issue: GitHub.