huggingface/smolagents · error · TypeError
Input '{input_name}': type must be a string or list of strin
Error message
Input '{input_name}': type must be a string or list of strings, got {type(input_content['type']).__name__} What it means
During Tool initialization, smolagents validates the 'inputs' attribute: each input's 'type' must be either a string (e.g. 'string') or a list of strings. If type is any other Python type (int, dict, None, etc.), a TypeError is raised naming the offending type. This guards downstream JSON-schema generation for the LLM.
Source
Thrown at src/smolagents/tools.py:188
)
# 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
):
signature = inspect.signature(self.forward)
actual_keys = set(key for key in signature.parameters.keys() if key != "self")
expected_keys = set(self.inputs.keys())
if actual_keys != expected_keys:View on GitHub (pinned to 30bb116109)
Solutions
- Set the input's type to a string literal like "type": "string"
- If multiple types are allowed, use a list of strings: "type": ["string", "integer"]
- Ensure every entry in self.inputs has a 'type' key at all (a missing key raises KeyError instead)
Example fix
# before
self.inputs = {"text": {"type": None, "description": "..."}}
# after
self.inputs = {"text": {"type": "string", "description": "..."}} Defensive patterns
Strategy: validation
Validate before calling
def valid_input_schema(inputs):
for name, spec in inputs.items():
t = spec.get("type")
if not isinstance(t, str) and not (isinstance(t, list) and all(isinstance(x, str) for x in t)):
return False
return True
assert valid_input_schema(MyTool.inputs) Type guard
from typing import Union
def is_valid_type(t: object) -> bool:
return isinstance(t, str) or (isinstance(t, list) and t and all(isinstance(x, str) for x in t)) Prevention
- Always write input types as string literals ('string', 'integer', ...), never Python type objects
- Add a unit test that instantiates your Tool subclass so validation runs in CI
- Keep a canonical example inputs dict and copy from it
When it happens
Trigger: Defining a Tool subclass (or @tool-decorated function's inputs dict) where an input entry has 'type': None, 'type': 3, or 'type': {'type': 'string'} instead of 'type': 'string' or 'type': ['string', 'integer'].
Common situations: Copying Gradio API descriptions or JSON schemas verbatim into inputs, forgetting quotes around type names, or using numpy/python types instead of string literals.
Related errors
- Input '{input_name}': when type is a list, all elements must
- step_callbacks must be a list or a dict
- You must set an attribute {attr}.
- Attribute {attr} should have type {expected_type.__name__},
- Attribute output_schema should have type dict, got {type(out
AI-assisted analysis of huggingface/smolagents@30bb116109 (2026-08-28).
Data as JSON: /api/errors/6fdba57808aba75b.
Report an issue: GitHub.