{"record":{"id":"b588cd5b31bdc9c9","repo":"huggingface/smolagents","slug":"argument-has-type-type-arguments-name-but","errorCode":null,"errorMessage":"Argument has type '{type(arguments).__name__}' but should be '{expected_type}'","messagePattern":"Argument has type '(.+?)' but should be '(.+?)'","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/smolagents/tools.py","lineNumber":1412,"sourceCode":"            # Type is valid if it matches, is \"any\", or is null for nullable parameters\n            if (\n                (actual_type != expected_type if isinstance(expected_type, str) else actual_type not in expected_type)\n                and expected_type != \"any\"\n                and not (actual_type == \"null\" and expected_type_is_nullable)\n            ):\n                if actual_type == \"integer\" and expected_type == \"number\":\n                    continue\n                raise TypeError(f\"Argument {key} has type '{actual_type}' but should be '{tool.inputs[key]['type']}'\")\n\n        for key, schema in tool.inputs.items():\n            key_is_nullable = schema.get(\"nullable\", False)\n            if key not in arguments and not key_is_nullable:\n                raise ValueError(f\"Argument {key} is required\")\n        return None\n    else:\n        expected_type = list(tool.inputs.values())[0][\"type\"]\n        if _get_json_schema_type(type(arguments))[\"type\"] != expected_type and not expected_type == \"any\":\n            raise TypeError(f\"Argument has type '{type(arguments).__name__}' but should be '{expected_type}'\")\n\n\n__all__ = [\n    \"AUTHORIZED_TYPES\",\n    \"Tool\",\n    \"tool\",\n    \"load_tool\",\n    \"launch_gradio_demo\",\n    \"ToolCollection\",\n]\n","sourceCodeStart":1394,"sourceCodeEnd":1423,"githubUrl":"https://github.com/huggingface/smolagents/blob/30bb1161095dbae2271e6bc3cc4c219cc3897a57/src/smolagents/tools.py#L1394-L1423","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Convert the value to the declared type before calling (str(), int(), ...)","Update the tool's inputs declaration to match the actual value type, or use 'any'","Ensure the model prompt/description states the expected scalar format"],"exampleFix":"# before\ntool('123')  # input declared as integer\n\n# after\ntool(int('123'))","handlingStrategy":"type-guard","validationCode":"TYPE_MAP = {str: 'string', int: 'integer', float: 'number', bool: 'boolean', list: 'array', dict: 'object'}\ndef check_single(tool, value):\n    expected = list(tool.inputs.values())[0]['type']\n    if expected != 'any' and TYPE_MAP.get(type(value)) != expected:\n        raise ValueError(f'Expected {expected}')\n    return value","typeGuard":"def is_valid_single_arg(tool, value) -> bool:\n    tm = {str: 'string', int: 'integer', float: 'number', bool: 'boolean', list: 'array', dict: 'object'}\n    expected = list(tool.inputs.values())[0]['type']\n    return expected == 'any' or tm.get(type(value)) == expected","tryCatchPattern":"try:\n    tool(value)\nexcept TypeError as e:\n    if 'Argument has type' in str(e):\n        # coerce value to declared type and retry\n        raise","preventionTips":["Document that single-input tools take bare values, not dicts","Normalize model output before invoking the tool"],"tags":["smolagents","tool-calling","type-validation"],"backgroundTag":"argument-type-mismatch","analyzedSha":"30bb1161095dbae2271e6bc3cc4c219cc3897a57","analyzedAt":"2026-08-28T18:52:54.169Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}