huggingface/smolagents · error · TypeError

Argument has type '{type(arguments).__name__}' but should be

Error message

Argument has type '{type(arguments).__name__}' but should be '{expected_type}'

What it means

The single-argument branch of validate_tool_arguments: when a tool declares exactly one input (arguments passed as a bare value, not a dict), the Python type of that value is checked against the declared JSON Schema type via _get_json_schema_type. A mismatch (other than expected 'any') raises this TypeError.

Source

Thrown at src/smolagents/tools.py:1412

            # 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. Convert the value to the declared type before calling (str(), int(), ...)
  2. Update the tool's inputs declaration to match the actual value type, or use 'any'
  3. Ensure the model prompt/description states the expected scalar format

Example fix

# before
tool('123')  # input declared as integer

# after
tool(int('123'))
Defensive patterns

Strategy: type-guard

Validate before calling

TYPE_MAP = {str: 'string', int: 'integer', float: 'number', bool: 'boolean', list: 'array', dict: 'object'}
def check_single(tool, value):
    expected = list(tool.inputs.values())[0]['type']
    if expected != 'any' and TYPE_MAP.get(type(value)) != expected:
        raise ValueError(f'Expected {expected}')
    return value

Type guard

def is_valid_single_arg(tool, value) -> bool:
    tm = {str: 'string', int: 'integer', float: 'number', bool: 'boolean', list: 'array', dict: 'object'}
    expected = list(tool.inputs.values())[0]['type']
    return expected == 'any' or tm.get(type(value)) == expected

Try / catch

try:
    tool(value)
except TypeError as e:
    if 'Argument has type' in str(e):
        # coerce value to declared type and retry
        raise

Prevention

When it happens

Trigger: Calling a single-input tool with a bare value of the wrong Python type, e.g., passing 42 when the input is declared 'string', or a dict when 'integer' is declared.

Common situations: LLM wrapping a scalar in quotes or an object when the tool expects a number; authors changing a tool's single input type and stale callers passing the old type.

Related errors


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