{"record":{"id":"802b521835ea2946","repo":"huggingface/smolagents","slug":"msg","errorCode":null,"errorMessage":"{msg}","messagePattern":"\\{msg\\}","errorType":"exception","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"src/smolagents/local_python_executor.py","lineNumber":1229,"sourceCode":"            raise exc from cause\n        else:\n            raise exc\n    else:\n        raise InterpreterError(\"Re-raise is not supported without an active exception\")\n\n\ndef evaluate_assert(\n    assert_node: ast.Assert,\n    state: dict[str, Any],\n    static_tools: dict[str, Callable],\n    custom_tools: dict[str, Callable],\n    authorized_imports: list[str],\n) -> None:\n    test_result = evaluate_ast(assert_node.test, state, static_tools, custom_tools, authorized_imports)\n    if not test_result:\n        if assert_node.msg:\n            msg = evaluate_ast(assert_node.msg, state, static_tools, custom_tools, authorized_imports)\n            raise AssertionError(msg)\n        else:\n            # Include the failing condition in the assertion message\n            test_code = ast.unparse(assert_node.test)\n            raise AssertionError(f\"Assertion failed: {test_code}\")\n\n\ndef evaluate_with(\n    with_node: ast.With,\n    state: dict[str, Any],\n    static_tools: dict[str, Callable],\n    custom_tools: dict[str, Callable],\n    authorized_imports: list[str],\n) -> None:\n    contexts = []\n    for item in with_node.items:\n        context_expr = evaluate_ast(item.context_expr, state, static_tools, custom_tools, authorized_imports)\n        enter_result = context_expr.__enter__()\n        contexts.append(context_expr)","sourceCodeStart":1211,"sourceCodeEnd":1247,"githubUrl":"https://github.com/huggingface/smolagents/blob/30bb1161095dbae2271e6bc3cc4c219cc3897a57/src/smolagents/local_python_executor.py#L1211-L1247","documentation":"An assert statement failed and included a custom message (assert cond, msg); the interpreter evaluates msg and raises AssertionError with it. This is the agent-code's own assertion failing, not an interpreter bug.","triggerScenarios":"assert 1 == 2, 'sanity check failed' or assert result is not None, 'API returned nothing' where the condition evaluates falsy.","commonSituations":"Agent code self-checks LLM/tool outputs and asserts non-None, correct type, or expected value; validation assertions on parsed JSON; asserting a file exists after a download step.","solutions":["Read the custom message to identify which check failed and fix the upstream data/logic","Replace assert with explicit if not cond: raise ValueError(...) for better control","Make assertions robust to legitimate edge cases (e.g. allow empty results if valid)"],"exampleFix":"# before\nassert resp['status'] == 'ok', 'bad status'\n# after\nif resp.get('status') != 'ok':\n    raise ValueError(f\"unexpected status: {resp.get('status')}\")","handlingStrategy":"try-catch","validationCode":"if not (resp and resp.get('status') == 'ok'):\n    raise ValueError(f\"bad response: {resp!r}\")","typeGuard":null,"tryCatchPattern":"try:\n    evaluate_python(code, ...)\nexcept AssertionError as e:\n    # read the custom msg, fix upstream data/logic, retry\n    ...","preventionTips":["Prefer explicit if/raise over assert for validating external data","Include descriptive messages in every assert"],"tags":["python-executor","assert","validation","smolagents"],"backgroundTag":"assertion-failed","analyzedSha":"30bb1161095dbae2271e6bc3cc4c219cc3897a57","analyzedAt":"2026-08-28T18:52:54.169Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}