{"record":{"id":"96cf4683e5d430c0","repo":"huggingface/smolagents","slug":"cannot-unpack-non-dict-value-in-kwargs-type-st","errorCode":null,"errorMessage":"Cannot unpack non-dict value in **kwargs: {type(starred_dict).__name__}","messagePattern":"Cannot unpack non-dict value in \\*\\*kwargs: (.+?)","errorType":"exception","errorClass":"InterpreterError","httpStatus":null,"severity":"error","filePath":"src/smolagents/local_python_executor.py","lineNumber":880,"sourceCode":"        func = evaluate_ast(call.func, state, static_tools, custom_tools, authorized_imports)\n        if not callable(func):\n            raise InterpreterError(f\"This is not a correct function: {call.func}).\")\n        func_name = None\n\n    args = []\n    for arg in call.args:\n        if isinstance(arg, ast.Starred):\n            args.extend(evaluate_ast(arg.value, state, static_tools, custom_tools, authorized_imports))\n        else:\n            args.append(evaluate_ast(arg, state, static_tools, custom_tools, authorized_imports))\n\n    kwargs = {}\n    for keyword in call.keywords:\n        if keyword.arg is None:\n            # **kwargs unpacking\n            starred_dict = evaluate_ast(keyword.value, state, static_tools, custom_tools, authorized_imports)\n            if not isinstance(starred_dict, dict):\n                raise InterpreterError(f\"Cannot unpack non-dict value in **kwargs: {type(starred_dict).__name__}\")\n            kwargs.update(starred_dict)\n        else:\n            # Normal keyword argument\n            kwargs[keyword.arg] = evaluate_ast(keyword.value, state, static_tools, custom_tools, authorized_imports)\n\n    if func_name == \"super\":\n        if not args:\n            if \"__class__\" in state and \"self\" in state:\n                return super(state[\"__class__\"], state[\"self\"])\n            else:\n                raise InterpreterError(\"super() needs at least one argument\")\n        cls = args[0]\n        if not isinstance(cls, type):\n            raise InterpreterError(\"super() argument 1 must be type\")\n        if len(args) == 1:\n            return super(cls)\n        elif len(args) == 2:\n            instance = args[1]","sourceCodeStart":862,"sourceCodeEnd":898,"githubUrl":"https://github.com/huggingface/smolagents/blob/30bb1161095dbae2271e6bc3cc4c219cc3897a57/src/smolagents/local_python_executor.py#L862-L898","documentation":"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.","triggerScenarios":"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).","commonSituations":"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).","solutions":["Convert to dict first: f(**dict(x)) or f(**{k: v for k, v in x.items()})","Check type(x) is dict before the call","If it is a JSON string, parse it with json.loads before unpacking"],"exampleFix":"# before\nresult = tool(**params)  # params is a str\n# after\nimport json\nif isinstance(params, str):\n    params = json.loads(params)\nresult = tool(**params)","handlingStrategy":"type-guard","validationCode":"if not isinstance(params, dict):\n    params = dict(params)  # or raise early with a clear message\ntool(**params)","typeGuard":"def is_dict(v) -> bool:\n    return type(v) is dict","tryCatchPattern":"try:\n    evaluate_python(code, ...)\nexcept InterpreterError as e:\n    if 'Cannot unpack non-dict' in str(e):\n        params = dict(params); ...","preventionTips":["Always convert Mapping/Series/str payloads to dict before ** unpacking","Validate JSON parse results are objects before unpacking"],"tags":["python-executor","kwargs","type-error","smolagents"],"backgroundTag":"kwargs-unpacking-type-error","analyzedSha":"30bb1161095dbae2271e6bc3cc4c219cc3897a57","analyzedAt":"2026-08-28T18:52:54.169Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}