huggingface/smolagents · error · InterpreterError

super() needs at least one argument

Error message

super() needs at least one argument

What it means

Bare super() with no arguments requires the interpreter to know the enclosing class (__class__) and the instance (self) from local state. Inside this sandboxed executor, that context is only available for methods defined via class definitions executed in the same interpreter run; otherwise super() with no args is rejected.

Source

Thrown at src/smolagents/local_python_executor.py:891

    kwargs = {}
    for keyword in call.keywords:
        if keyword.arg is None:
            # **kwargs unpacking
            starred_dict = evaluate_ast(keyword.value, state, static_tools, custom_tools, authorized_imports)
            if not isinstance(starred_dict, dict):
                raise InterpreterError(f"Cannot unpack non-dict value in **kwargs: {type(starred_dict).__name__}")
            kwargs.update(starred_dict)
        else:
            # Normal keyword argument
            kwargs[keyword.arg] = evaluate_ast(keyword.value, state, static_tools, custom_tools, authorized_imports)

    if func_name == "super":
        if not args:
            if "__class__" in state and "self" in state:
                return super(state["__class__"], state["self"])
            else:
                raise InterpreterError("super() needs at least one argument")
        cls = args[0]
        if not isinstance(cls, type):
            raise InterpreterError("super() argument 1 must be type")
        if len(args) == 1:
            return super(cls)
        elif len(args) == 2:
            instance = args[1]
            return super(cls, instance)
        else:
            raise InterpreterError("super() takes at most 2 arguments")
    elif func_name == "print":
        state["_print_outputs"] += " ".join(map(str, args)) + "\n"
        return None
    else:  # Assume it's a callable object
        if (inspect.getmodule(func) == builtins) and inspect.isbuiltin(func) and (func not in static_tools.values()):
            raise InterpreterError(
                f"Invoking a builtin function that has not been explicitly added as a tool is not allowed ({func_name})."
            )

View on GitHub (pinned to 30bb116109)

Solutions

  1. Use the two-argument form: super(ClassName, self)
  2. Define the class inside the same executed script so the interpreter tracks __class__ and self
  3. Move the subclass logic outside agent-generated code into a pre-authorized tool

Example fix

# before
class B(A):
    def run(self):
        return super().run()  # context missing
# after
class B(A):
    def run(self):
        return super(B, self).run()
Defensive patterns

Strategy: validation

Validate before calling

# in generated code: avoid bare super() unless inside a method of a class defined in the same block
super(ClassName, self).method()

Try / catch

try:
    evaluate_python(code, ...)
except InterpreterError as e:
    if 'super()' in str(e):
        code = code.replace('super()', f'super({cls_name}, self)'); evaluate_python(code, ...)

Prevention

When it happens

Trigger: Calling super() with zero arguments in a function outside a class body executed by the interpreter, or in a lambda/nested function where __class__/self are not in state.

Common situations: Agent-generated code uses new-style bare super() in a standalone function or static method; the class was defined outside the sandbox so state lacks '__class__' and 'self'.

Related errors


AI-assisted analysis of huggingface/smolagents@30bb116109 (2026-08-28). Data as JSON: /api/errors/7457741310734c1f. Report an issue: GitHub.