{"record":{"id":"3cd0b420298aac2e","repo":"huggingface/smolagents","slug":"input-input-name-when-type-is-a-list-all-ele","errorCode":null,"errorMessage":"Input '{input_name}': when type is a list, all elements must be strings, got {input_content['type']}","messagePattern":"Input '(.+?)': when type is a list, all elements must be strings, got (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/smolagents/tools.py","lineNumber":184,"sourceCode":"        # - Validate name\n        if not is_valid_name(self.name):\n            raise Exception(\n                f\"Invalid Tool name '{self.name}': must be a valid Python identifier and not a reserved keyword\"\n            )\n        # Validate inputs\n        for input_name, input_content in self.inputs.items():\n            assert isinstance(input_content, dict), f\"Input '{input_name}' should be a dictionary.\"\n            assert \"type\" in input_content and \"description\" in input_content, (\n                f\"Input '{input_name}' should have keys 'type' and 'description', has only {list(input_content.keys())}.\"\n            )\n            # Get input_types as a list, whether from a string or list\n            if isinstance(input_content[\"type\"], str):\n                input_types = [input_content[\"type\"]]\n            elif isinstance(input_content[\"type\"], list):\n                input_types = input_content[\"type\"]\n                # Check if all elements are strings\n                if not all(isinstance(t, str) for t in input_types):\n                    raise TypeError(\n                        f\"Input '{input_name}': when type is a list, all elements must be strings, got {input_content['type']}\"\n                    )\n            else:\n                raise TypeError(\n                    f\"Input '{input_name}': type must be a string or list of strings, got {type(input_content['type']).__name__}\"\n                )\n            # Check all types are authorized\n            invalid_types = [t for t in input_types if t not in AUTHORIZED_TYPES]\n            if invalid_types:\n                raise ValueError(f\"Input '{input_name}': types {invalid_types} must be one of {AUTHORIZED_TYPES}\")\n        # Validate output type\n        assert getattr(self, \"output_type\", None) in AUTHORIZED_TYPES\n\n        # Validate forward function signature, except for Tools that use a \"generic\" signature (PipelineTool, SpaceToolWrapper, LangChainToolWrapper)\n        if not (\n            hasattr(self, \"skip_forward_signature_validation\")\n            and getattr(self, \"skip_forward_signature_validation\") is True\n        ):","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/huggingface/smolagents/blob/30bb1161095dbae2271e6bc3cc4c219cc3897a57/src/smolagents/tools.py#L166-L202","documentation":"For each entry in Tool.inputs, the 'type' field may be a single string or a list of alternative type strings (e.g. [\"string\", \"integer\"]). If a list is given but contains non-string elements (ints, dicts, None), validate_arguments raises TypeError naming the offending list.","triggerScenarios":"Declaring inputs like {\"threshold\": {\"type\": [\"number\", 3]}} or {\"opt\": {\"type\": [None, \"string\"]}} on a Tool subclass; error raised at instantiation via new_init → validate_arguments.","commonSituations":"Reusing JSON-schema-ish structures where type lists may contain enum values or unquoted literals; programmatic generation of inputs dicts that mixes types; copy-paste where quotes were dropped, making entries ints.","solutions":["Make every element of the type list a string literal (quote numeric or enum values)","If only one type applies, use the plain string form: \"type\": \"number\"","Validate generated inputs dicts in a unit test before registering the tool"],"exampleFix":"# before\ninputs = {\"threshold\": {\"type\": [\"number\", 3], \"description\": \"limit\"}}\n\n# after\ninputs = {\"threshold\": {\"type\": [\"number\", \"integer\"], \"description\": \"limit\"}}","handlingStrategy":"type-guard","validationCode":"def inputs_types_valid(inputs: dict) -> bool:\n    for spec in inputs.values():\n        t = spec.get(\"type\")\n        if isinstance(t, list) and not all(isinstance(x, str) for x in t):\n            return False\n    return True","typeGuard":"def inputs_types_valid(inputs: dict) -> bool:\n    return all(\n        isinstance(spec.get(\"type\"), str) or (\n            isinstance(spec.get(\"type\"), list)\n            and all(isinstance(x, str) for x in spec[\"type\"])\n        )\n        for spec in inputs.values()\n    )","tryCatchPattern":"try:\n    MyTool()\nexcept TypeError as e:\n    if \"list, all elements must be strings\" in str(e):\n        MyTool.inputs = {k: {**v, \"type\": [str(t) for t in v[\"type\"]]} for k, v in MyTool.inputs.items()}\n        MyTool()","preventionTips":["Always quote type list entries (strings only)","Prefer single-string types unless alternatives are needed","Validate programmatically built inputs dicts before class definition"],"tags":["smolagents","tool","inputs","type-error"],"backgroundTag":"tool-inputs-invalid-type","analyzedSha":"30bb1161095dbae2271e6bc3cc4c219cc3897a57","analyzedAt":"2026-08-28T18:52:54.169Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}