huggingface/smolagents · error · InterpreterError
Re-raise is not supported without an active exception
Error message
Re-raise is not supported without an active exception
What it means
The code contains a bare `raise` outside any except block with an active exception. The sandboxed interpreter does not track a current exception, so it cannot re-raise.
Source
Thrown at src/smolagents/local_python_executor.py:1215
static_tools: dict[str, Callable],
custom_tools: dict[str, Callable],
authorized_imports: list[str],
) -> None:
if raise_node.exc is not None:
exc = evaluate_ast(raise_node.exc, state, static_tools, custom_tools, authorized_imports)
else:
exc = None
if raise_node.cause is not None:
cause = evaluate_ast(raise_node.cause, state, static_tools, custom_tools, authorized_imports)
else:
cause = None
if exc is not None:
if cause is not None:
raise exc from cause
else:
raise exc
else:
raise InterpreterError("Re-raise is not supported without an active exception")
def evaluate_assert(
assert_node: ast.Assert,
state: dict[str, Any],
static_tools: dict[str, Callable],
custom_tools: dict[str, Callable],
authorized_imports: list[str],
) -> None:
test_result = evaluate_ast(assert_node.test, state, static_tools, custom_tools, authorized_imports)
if not test_result:
if assert_node.msg:
msg = evaluate_ast(assert_node.msg, state, static_tools, custom_tools, authorized_imports)
raise AssertionError(msg)
else:
# Include the failing condition in the assertion message
test_code = ast.unparse(assert_node.test)
raise AssertionError(f"Assertion failed: {test_code}")View on GitHub (pinned to 30bb116109)
Solutions
- Capture the exception first: except X as e: ... then `raise e` explicitly instead of bare `raise`
- Move the bare raise inside the except block in the same function scope
- Re-raise with raise ExceptionClass(args) if the original exception object isn't available
Example fix
# before
try:
risky()
except ValueError:
log('failed')
finally:
raise # invalid here
# after
try:
risky()
except ValueError as e:
log('failed')
raise e Defensive patterns
Strategy: try-catch
Validate before calling
# always bind and re-raise explicitly in generated code
try:
risky()
except Exception as e:
raise e Try / catch
try:
evaluate_python(code, ...)
except InterpreterError as e:
if 'Re-raise is not supported' in str(e):
# rewrite bare `raise` to `raise e` inside except and retry Prevention
- Never use bare raise outside an except block in the same function scope
- Bind exceptions with `as e` and re-raise explicitly
When it happens
Trigger: A bare `raise;` statement executed when no exception is being handled — e.g. in a finally block, in a nested function called from inside except, or after the except block ended.
Common situations: Agent code wraps `raise` in a helper function intending to propagate; using `raise` inside `finally` to re-raise; refactored except-block code into a function so Python's implicit exception context is lost.
Related errors
- Cannot unpack non-dict value in **kwargs: {type(starred_dict
- super() needs at least one argument
- super() argument 1 must be type
- super() takes at most 2 arguments
- Invoking a builtin function that has not been explicitly add
AI-assisted analysis of huggingface/smolagents@30bb116109 (2026-08-28).
Data as JSON: /api/errors/d51039ba4590aee5.
Report an issue: GitHub.