{"record":{"id":"c951dbb49f4314cd","repo":"huggingface/smolagents","slug":"argument-key-is-required","errorCode":null,"errorMessage":"Argument {key} is required","messagePattern":"Argument (.+?) is required","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/smolagents/tools.py","lineNumber":1407,"sourceCode":"\n            actual_type = _get_json_schema_type(type(value))[\"type\"]\n            expected_type = tool.inputs[key][\"type\"]\n            expected_type_is_nullable = tool.inputs[key].get(\"nullable\", False)\n\n            # 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":1389,"sourceCodeEnd":1423,"githubUrl":"https://github.com/huggingface/smolagents/blob/30bb1161095dbae2271e6bc3cc4c219cc3897a57/src/smolagents/tools.py#L1389-L1423","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass all required arguments for every key in tool.inputs","Mark genuinely optional inputs with 'nullable': True in the inputs dict","If the argument should have a default, handle defaults in forward() and declare the input nullable","Retest the tool after modifying its inputs schema to ensure callers are updated"],"exampleFix":"# before\ntool(inputs={'query': {...}, 'limit': {'type': 'integer'}}, ...)\ntool(query='cats')  # ValueError: Argument limit is required\n\n# after\ntool(inputs={'query': {...}, 'limit': {'type': 'integer', 'nullable': True}}, ...)\ntool(query='cats')","handlingStrategy":"validation","validationCode":"def ensure_required(tool, arguments):\n    missing = [k for k, s in tool.inputs.items() if k not in arguments and not s.get('nullable', False)]\n    if missing:\n        raise ValueError(f'Missing required args: {missing}')\n    return arguments","typeGuard":"def has_all_required(tool, arguments: dict) -> bool:\n    return all(k in arguments or s.get('nullable', False) for k, s in tool.inputs.items())","tryCatchPattern":"try:\n    tool(**arguments)\nexcept ValueError as e:\n    if 'is required' in str(e):\n        # parse missing key names and supply defaults / re-ask the model\n        raise","preventionTips":["Mark optional inputs nullable: True","Give the model explicit argument descriptions in inputs schemas","Unit-test tools with minimal argument sets"],"tags":["smolagents","tool-calling","missing-argument","validation"],"backgroundTag":"missing-required-argument","analyzedSha":"30bb1161095dbae2271e6bc3cc4c219cc3897a57","analyzedAt":"2026-08-28T18:52:54.169Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}