{"record":{"id":"6d52f977bad9b652","repo":"huggingface/smolagents","slug":"assertion-failed-test-code","errorCode":null,"errorMessage":"Assertion failed: {test_code}","messagePattern":"Assertion failed: (.+?)","errorType":"exception","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"src/smolagents/local_python_executor.py","lineNumber":1233,"sourceCode":"        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)\n        if item.optional_vars:\n            state[item.optional_vars.id] = enter_result\n\n    try:","sourceCodeStart":1215,"sourceCodeEnd":1251,"githubUrl":"https://github.com/huggingface/smolagents/blob/30bb1161095dbae2271e6bc3cc4c219cc3897a57/src/smolagents/local_python_executor.py#L1215-L1251","documentation":"An assert without a message failed; the interpreter unpar ses the failing test expression and raises AssertionError('Assertion failed: <code>'). This is the agent-written code's own assertion failing.","triggerScenarios":"assert x, assert len(items) > 0, or assert isinstance(v, dict) where the condition evaluates False/None/empty.","commonSituations":"Same as any failed assert: agent self-validates intermediate results (non-empty list, expected type, truthy flag) and the assumption doesn't hold at runtime.","solutions":["Inspect the echoed test code to see exactly which condition failed and debug that value","Add a descriptive message to the assert for future runs","Guard instead: if not cond: raise ValueError(...) or use a default/fallback value"],"exampleFix":"# before\nassert results  # no message\n# after\nassert results, f'expected non-empty results, got {results!r}'","handlingStrategy":"try-catch","validationCode":"if not items:\n    raise ValueError(f'expected non-empty items, got {items!r}')","typeGuard":null,"tryCatchPattern":"try:\n    evaluate_python(code, ...)\nexcept AssertionError as e:\n    # the echoed test code shows exactly which condition failed; fix and retry","preventionTips":["Add messages to asserts so failures are self-describing","Handle edge cases (empty/None) explicitly rather than asserting them away"],"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"}