huggingface/smolagents · warning · InterpreterError
This is not a correct function: {call.func}).
Error message
This is not a correct function: {call.func}). What it means
evaluate_call only accepts callables reached via ast.Call, ast.Lambda, ast.Attribute, ast.Name, or ast.Subscript expressions; any other func node shape raises InterpreterError. It is a defensive structural check on the AST, not a runtime type error (the paren and period in the message are cosmetic).
Source
Thrown at src/smolagents/local_python_executor.py:833
set_value(elem, value[i], state, static_tools, custom_tools, authorized_imports)
elif isinstance(target, ast.Subscript):
obj = evaluate_ast(target.value, state, static_tools, custom_tools, authorized_imports)
key = evaluate_ast(target.slice, state, static_tools, custom_tools, authorized_imports)
obj[key] = value
elif isinstance(target, ast.Attribute):
obj = evaluate_ast(target.value, state, static_tools, custom_tools, authorized_imports)
setattr(obj, target.attr, value)
def evaluate_call(
call: ast.Call,
state: dict[str, Any],
static_tools: dict[str, Callable],
custom_tools: dict[str, Callable],
authorized_imports: list[str],
) -> Any:
if not isinstance(call.func, (ast.Call, ast.Lambda, ast.Attribute, ast.Name, ast.Subscript)):
raise InterpreterError(f"This is not a correct function: {call.func}).")
func, func_name = None, None
if isinstance(call.func, ast.Call):
func = evaluate_ast(call.func, state, static_tools, custom_tools, authorized_imports)
elif isinstance(call.func, ast.Lambda):
func = evaluate_ast(call.func, state, static_tools, custom_tools, authorized_imports)
elif isinstance(call.func, ast.Attribute):
obj = evaluate_ast(call.func.value, state, static_tools, custom_tools, authorized_imports)
func_name = call.func.attr
if not hasattr(obj, func_name):
raise InterpreterError(f"Object {obj} has no attribute {func_name}")
func = getattr(obj, func_name)
elif isinstance(call.func, ast.Name):
func_name = call.func.id
if func_name in state:
func = state[func_name]
elif func_name in static_tools:View on GitHub (pinned to 30bb116109)
Solutions
- Ensure executed code uses standard call syntax (name, attribute, subscript, call or lambda as the callee)
- If generating ASTs, keep call.func within the five supported node types
- Execute source strings via evaluate_python/evaluate_script rather than custom ASTs
Defensive patterns
Strategy: validation
Validate before calling
import ast
for node in ast.walk(ast.parse(code)):
if isinstance(node, ast.Call) and not isinstance(node.func, (ast.Call, ast.Lambda, ast.Attribute, ast.Name, ast.Subscript)):
raise ValueError('unsupported call target in AST') Try / catch
from smolagents.local_python_executor import InterpreterError
try:
evaluate_python(code)
except InterpreterError as e:
if 'not a correct function' in str(e):
raise SyntaxRestriction(str(e)) from e Prevention
- Execute plain source strings rather than custom ASTs
- Keep callee expressions in standard forms (name, attribute, subscript, call, lambda)
- Validate generated ASTs before handing them to the executor
When it happens
Trigger: Practically unreachable from normal Python source since the grammar only produces those node types for callees; fires only with hand-constructed/mutated ASTs (e.g. calling evaluate_ast directly with an exotic call.func node).
Common situations: Programmatic AST generation feeding the executor; AST transformers/optimizers that replace the callee with an unexpected node type.
Related errors
- Unary operation {expression.op.__class__.__name__} is not su
- Unsupported AnnAssign target in class body: {type(target).__
- AugAssign not supported for {type(target)} targets.
- Operation {type(expression.op).__name__} is not supported.
- Forbidden access to module: {result.__name__}
AI-assisted analysis of huggingface/smolagents@30bb116109 (2026-08-28).
Data as JSON: /api/errors/23eba2897be24e20.
Report an issue: GitHub.