huggingface/smolagents · error · TypeError
Input '{input_name}': when type is a list, all elements must
Error message
Input '{input_name}': when type is a list, all elements must be strings, got {input_content['type']} What it means
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.
Source
Thrown at src/smolagents/tools.py:184
# - Validate name
if not is_valid_name(self.name):
raise Exception(
f"Invalid Tool name '{self.name}': must be a valid Python identifier and not a reserved keyword"
)
# Validate inputs
for input_name, input_content in self.inputs.items():
assert isinstance(input_content, dict), f"Input '{input_name}' should be a dictionary."
assert "type" in input_content and "description" in input_content, (
f"Input '{input_name}' should have keys 'type' and 'description', has only {list(input_content.keys())}."
)
# Get input_types as a list, whether from a string or list
if isinstance(input_content["type"], str):
input_types = [input_content["type"]]
elif isinstance(input_content["type"], list):
input_types = input_content["type"]
# Check if all elements are strings
if not all(isinstance(t, str) for t in input_types):
raise TypeError(
f"Input '{input_name}': when type is a list, all elements must be strings, got {input_content['type']}"
)
else:
raise TypeError(
f"Input '{input_name}': type must be a string or list of strings, got {type(input_content['type']).__name__}"
)
# Check all types are authorized
invalid_types = [t for t in input_types if t not in AUTHORIZED_TYPES]
if invalid_types:
raise ValueError(f"Input '{input_name}': types {invalid_types} must be one of {AUTHORIZED_TYPES}")
# Validate output type
assert getattr(self, "output_type", None) in AUTHORIZED_TYPES
# Validate forward function signature, except for Tools that use a "generic" signature (PipelineTool, SpaceToolWrapper, LangChainToolWrapper)
if not (
hasattr(self, "skip_forward_signature_validation")
and getattr(self, "skip_forward_signature_validation") is True
):View on GitHub (pinned to 30bb116109)
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
Example fix
# before
inputs = {"threshold": {"type": ["number", 3], "description": "limit"}}
# after
inputs = {"threshold": {"type": ["number", "integer"], "description": "limit"}} Defensive patterns
Strategy: type-guard
Validate before calling
def inputs_types_valid(inputs: dict) -> bool:
for spec in inputs.values():
t = spec.get("type")
if isinstance(t, list) and not all(isinstance(x, str) for x in t):
return False
return True Type guard
def inputs_types_valid(inputs: dict) -> bool:
return all(
isinstance(spec.get("type"), str) or (
isinstance(spec.get("type"), list)
and all(isinstance(x, str) for x in spec["type"])
)
for spec in inputs.values()
) Try / catch
try:
MyTool()
except TypeError as e:
if "list, all elements must be strings" in str(e):
MyTool.inputs = {k: {**v, "type": [str(t) for t in v["type"]]} for k, v in MyTool.inputs.items()}
MyTool() Prevention
- Always quote type list entries (strings only)
- Prefer single-string types unless alternatives are needed
- Validate programmatically built inputs dicts before class definition
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Attribute {attr} should have type {expected_type.__name__},
- Attribute output_schema should have type dict, got {type(out
- Input '{input_name}': type must be a string or list of strin
- {e}
- Object is not iterable
AI-assisted analysis of huggingface/smolagents@30bb116109 (2026-08-28).
Data as JSON: /api/errors/3cd0b420298aac2e.
Report an issue: GitHub.