huggingface/smolagents · error · ValueError

Argument {key} is required

Error message

Argument {key} is required

What it means

Raised by validate_tool_arguments when a required input key defined in the tool's inputs schema is missing from the provided arguments dict. Only keys marked 'nullable': True may be omitted. It fires before the tool's forward() runs, guaranteeing all required parameters are present.

Source

Thrown at src/smolagents/tools.py:1407

            actual_type = _get_json_schema_type(type(value))["type"]
            expected_type = tool.inputs[key]["type"]
            expected_type_is_nullable = tool.inputs[key].get("nullable", False)

            # Type is valid if it matches, is "any", or is null for nullable parameters
            if (
                (actual_type != expected_type if isinstance(expected_type, str) else actual_type not in expected_type)
                and expected_type != "any"
                and not (actual_type == "null" and expected_type_is_nullable)
            ):
                if actual_type == "integer" and expected_type == "number":
                    continue
                raise TypeError(f"Argument {key} has type '{actual_type}' but should be '{tool.inputs[key]['type']}'")

        for key, schema in tool.inputs.items():
            key_is_nullable = schema.get("nullable", False)
            if key not in arguments and not key_is_nullable:
                raise ValueError(f"Argument {key} is required")
        return None
    else:
        expected_type = list(tool.inputs.values())[0]["type"]
        if _get_json_schema_type(type(arguments))["type"] != expected_type and not expected_type == "any":
            raise TypeError(f"Argument has type '{type(arguments).__name__}' but should be '{expected_type}'")


__all__ = [
    "AUTHORIZED_TYPES",
    "Tool",
    "tool",
    "load_tool",
    "launch_gradio_demo",
    "ToolCollection",
]

View on GitHub (pinned to 30bb116109)

Solutions

  1. Pass all required arguments for every key in tool.inputs
  2. Mark genuinely optional inputs with 'nullable': True in the inputs dict
  3. If the argument should have a default, handle defaults in forward() and declare the input nullable
  4. Retest the tool after modifying its inputs schema to ensure callers are updated

Example fix

# before
tool(inputs={'query': {...}, 'limit': {'type': 'integer'}}, ...)
tool(query='cats')  # ValueError: Argument limit is required

# after
tool(inputs={'query': {...}, 'limit': {'type': 'integer', 'nullable': True}}, ...)
tool(query='cats')
Defensive patterns

Strategy: validation

Validate before calling

def ensure_required(tool, arguments):
    missing = [k for k, s in tool.inputs.items() if k not in arguments and not s.get('nullable', False)]
    if missing:
        raise ValueError(f'Missing required args: {missing}')
    return arguments

Type guard

def has_all_required(tool, arguments: dict) -> bool:
    return all(k in arguments or s.get('nullable', False) for k, s in tool.inputs.items())

Try / catch

try:
    tool(**arguments)
except ValueError as e:
    if 'is required' in str(e):
        # parse missing key names and supply defaults / re-ask the model
        raise

Prevention

When it happens

Trigger: Calling tool(arguments={'x': 1}) when tool.inputs defines both 'x' and 'y' and 'y' is not nullable; an LLM omitting an argument from its JSON action blob.

Common situations: Model outputs partial tool-call JSON; tool schema updated to add a new required input but callers (or cached prompts) still send the old set; forgetting that nullable must be explicitly set in the schema.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of huggingface/smolagents@30bb116109 (2026-08-28). Data as JSON: /api/errors/c951dbb49f4314cd. Report an issue: GitHub.