How to See an Exception in an MLflow Trace
A trace is most useful when something goes wrong: it shows which step failed and why. When a function traced with @mlflow.trace raises an exception, MLflow marks its span as an error and keeps the exception's details. This guide makes one step fail twice, once inside a function that handles the error and once on its own, with real output from MLflow 3.18.0.
How MLflow Records an Exception
There's nothing to add to your code: @mlflow.trace does it. The mlflow.trace reference: "Any exception raised within the function will set the span status to ERROR and detailed information such as exception message and stacktrace will be recorded". MLflow's manual tracing guide adds that the details "will be included within Events of the partially completed span".
Two things decide what you see:
- The span of the function that raised the exception is marked as an error.
- The trace as a whole is marked as an error only if the exception leaves the outermost traced function. If a traced function higher up catches it, the trace stays OK, with the failed step marked inside it.
Prerequisites
- uv and Python. This guide uses uv 0.13.10 with Python 3.15.2.
Step 1: Create a Project with MLflow
uv init --bare --python 3.15 tracing-examples
cd tracing-examples
uv add mlflow
This installs MLflow 3.18.0. Don't call the project mlflow or mlflow-tracing: those are names of packages MLflow needs, and uv then installs an old MLflow or fails to build pyarrow.
Step 2: Start the Tracking Server
In a second terminal, in the same folder:
uv run mlflow server --port 8080
Leave it running. How to Start an MLflow Tracking Server on Your Computer explains each line it prints.
Step 3: Write the Script
share splits a bill between people, and fails with ZeroDivisionError when there are none. split_bill calls it and turns that error into None. The script runs both cases:
import mlflow
mlflow.set_tracking_uri("http://127.0.0.1:8080")
mlflow.set_experiment("trace-exceptions")
@mlflow.trace
def share(total: float, people: int) -> float:
return round(total / people, 2)
@mlflow.trace
def split_bill(total: float, people: int) -> float | None:
try:
return share(total, people)
except ZeroDivisionError:
return None
print(split_bill(90.0, 0))
try:
share(90.0, 0)
except ZeroDivisionError as error:
print("Couldn't share the bill:", error)

split_bill(90.0, 0)makessharefail insidesplit_bill, which catches the error.share(90.0, 0)on its own fails with nothing traced around it; the script'stryblock, which isn't traced, catches the error.
Step 4: Run It
uv run trace_exception.py
2026/12/03 08:15:38 INFO mlflow.tracking.fluent: Experiment with name 'trace-exceptions' does not exist. Creating a new experiment.
None
Couldn't share the bill: division by zero
2026/12/03 08:15:38 INFO mlflow.tracing.export.async_export_queue: Flushing the async trace logging queue before program exit. This may take a while...

Tracing didn't swallow the exception: in both cases it reached the code that catches it, as it would without MLflow.
Step 5: Compare the Two Traces
Open http://127.0.0.1:8080, click trace-exceptions, then Traces:

The older trace, from split_bill, is OK: its output is null, the None that split_bill returned. The newer one, from share on its own, is an Error with no output. Open the OK trace:

The trace says Success, because split_bill handled the error, but the share span under it is red: that step failed. Click share; its Events tab opens:

The event holds the exception: exception.message is division by zero and exception.type is ZeroDivisionError. Below them, exception.stacktrace holds the full traceback. Now open the Error trace:

Here share is the only span and nothing traced caught its exception, so the whole trace is marked Error, with the same exception in the span's Events.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
| Looking only at the trace's state | A trace can be OK while a step inside it failed | Look for red spans in the tree |
| Catching the exception inside the traced function itself | The span stays OK, with no exception event: the decorator never sees the error | Let the error leave the function, or catch it one traced level up, as split_bill does |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| The trace is OK but a span is red | A traced function higher up caught the exception | Open the red span's Events tab to see the error |
| The trace is marked Error | The exception left the outermost traced function | Open the red span's Events tab, then fix or handle the error |
| A failed step has no exception event | The function caught its own exception | Check the function's try blocks |
FAQ
Does tracing stop my exception from reaching my code?
No. In the run above, the ZeroDivisionError reached the script's own try block and printed its message, exactly as it would without MLflow.
What output does a failed span have?
None: the function never returned. The Error trace's output is empty, and the failed share span's output is null.
Where's the traceback?
In the same event, under exception.stacktrace, below the message and type.
Conclusion
When share raised ZeroDivisionError, MLflow marked its span red and recorded the message and type in its Events tab. Inside split_bill, which caught the error, the trace stayed OK with the failed step visible. On its own, the failure marked the whole trace as an Error.
Additional Resources
- Manual Tracing — automatic exception handling.
- mlflow.trace — what the decorator records when a function fails.
- Span concepts — span status and events.
