huggingface/smolagents · error · ValueError
Input '{input_name}': types {invalid_types} must be one of {
Error message
Input '{input_name}': types {invalid_types} must be one of {AUTHORIZED_TYPES} What it means
smolagents restricts tool input/output types to the AUTHORIZED_TYPES set (string, boolean, integer, number, image, audio, video, any, nullable, etc.). Any input type not in this list raises a ValueError listing the invalid types. This restriction exists because types are serialized into the tool-calling schema presented to the LLM.
Source
Thrown at src/smolagents/tools.py:194
)
# 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:
raise Exception(
f"In tool '{self.name}', 'forward' method parameters were {actual_keys}, but expected {expected_keys}. "
f"It should take 'self' as its first argument, then its next arguments should match the keys of tool attribute 'inputs'."
)
json_schema = _convert_type_hints_to_json_schema(self.forward, error_on_missing_type_hints=False)[View on GitHub (pinned to 30bb116109)
Solutions
- Use only authorized type names: "string", "boolean", "integer", "number", "image", "audio", "video", "any" (check AUTHORIZED_TYPES in smolagents.gradio_ui/tool docs for your version)
- Replace 'str'->'string', 'int'->'integer', 'float'->'number'
- For arbitrary objects use "any"
Example fix
# before
self.inputs = {"a": {"type": "int", "description": "count"}}
# after
self.inputs = {"a": {"type": "integer", "description": "count"}} Defensive patterns
Strategy: validation
Validate before calling
from smolagents.tools import AUTHORIZED_TYPES
invalid = [t for spec in MyTool.inputs.values() for t in ([spec['type']] if isinstance(spec['type'], str) else spec['type']) if t not in AUTHORIZED_TYPES]
assert not invalid, f"Invalid types: {invalid}" Type guard
AUTHORIZED = {"string","boolean","integer","number","image","audio","video","any"}
def uses_authorized_types(inputs: dict) -> bool:
return all(set([s['type']] if isinstance(s['type'], str) else s['type']) <= AUTHORIZED for s in inputs.values()) Prevention
- Memorize the JSON-style names: string/integer/number/boolean, not str/int/float/bool
- Check AUTHORIZED_TYPES in your installed version before using exotic types
- Use 'any' for arbitrary JSON-serializable payloads
When it happens
Trigger: Declaring an input with "type": "str", "type": "float", "type": "file", or any string/list entry not in AUTHORIZED_TYPES when instantiating a Tool subclass.
Common situations: Using Python type names ('str', 'int', 'float') instead of the JSON-style names ('string', 'integer', 'number'); inventing types like 'filepath' or 'image_url' not supported by the library; version changes that add/remove authorized types.
Related errors
- You must set an attribute {attr}.
- Attribute {attr} should have type {expected_type.__name__},
- Invalid Tool name '{self.name}': must be a valid Python iden
- Check {check_function.__name__} failed with error: {e}
- {e}
AI-assisted analysis of huggingface/smolagents@30bb116109 (2026-08-28).
Data as JSON: /api/errors/78c9e0c2777b2bab.
Report an issue: GitHub.