huggingface/smolagents · error · InterpreterError

Cannot unpack non-dict value in **kwargs: {type(starred_dict

Error message

Cannot unpack non-dict value in **kwargs: {type(starred_dict).__name__}

What it means

In a call like f(a=1, **d), the object passed after ** was not a dict, so its keys cannot become keyword arguments. The interpreter only allows dict unpacking for ** in calls.

Source

Thrown at src/smolagents/local_python_executor.py:880

        func = evaluate_ast(call.func, state, static_tools, custom_tools, authorized_imports)
        if not callable(func):
            raise InterpreterError(f"This is not a correct function: {call.func}).")
        func_name = None

    args = []
    for arg in call.args:
        if isinstance(arg, ast.Starred):
            args.extend(evaluate_ast(arg.value, state, static_tools, custom_tools, authorized_imports))
        else:
            args.append(evaluate_ast(arg, state, static_tools, custom_tools, authorized_imports))

    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]

View on GitHub (pinned to 30bb116109)

Solutions

  1. Convert to dict first: f(**dict(x)) or f(**{k: v for k, v in x.items()})
  2. Check type(x) is dict before the call
  3. If it is a JSON string, parse it with json.loads before unpacking

Example fix

# before
result = tool(**params)  # params is a str
# after
import json
if isinstance(params, str):
    params = json.loads(params)
result = tool(**params)
Defensive patterns

Strategy: type-guard

Validate before calling

if not isinstance(params, dict):
    params = dict(params)  # or raise early with a clear message
tool(**params)

Type guard

def is_dict(v) -> bool:
    return type(v) is dict

Try / catch

try:
    evaluate_python(code, ...)
except InterpreterError as e:
    if 'Cannot unpack non-dict' in str(e):
        params = dict(params); ...

Prevention

When it happens

Trigger: f(**x) where x is a list, tuple, string, or custom Mapping non-dict object (e.g. passing a pandas Series or a Mapping subclass).

Common situations: Agent code does f(**df.loc[0]) or f(**json.loads(s)) where JSON failed silently returned non-dict; passing a UserDict/OrderedDict-like custom Mapping (only exact dict passes isinstance in some paths).

Related errors


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