How do I evaluate an AI agent using production traces?
Summary
- Query the traces you want with
mlflow.search_traces(), then pass them tomlflow.genai.evaluate()with your scorers and nopredict_fn. MLflow calls this answer-sheet evaluation: it scores outputs your agent already produced instead of running the agent again. - Use production traces twice: score them to measure live quality, and curate representative failures and known-good examples into an evaluation dataset that every new agent version must pass.
- Scorers are LLM judges and code-based checks. MLflow attaches each result to its trace as feedback, so every score stays linked to the execution that produced it.
- For chat agents, tag traces with a session ID so multi-turn judges can score whole conversations. MLflow labels multi-turn evaluation experimental.
- On Databricks, production monitoring (Beta) runs the same registered scorers automatically on a configurable sample of incoming traces.
How do I evaluate an AI agent using production traces?
Treat production traces as both test results and test cases. First, score them in place: query them with mlflow.search_traces() and run mlflow.genai.evaluate() over the result with the scorers you care about, such as safety, relevance or your own guidelines. Then copy the traces that teach you something (failures, edge cases, examples that must keep working) into an evaluation dataset, and run every new version of the agent against it before it ships. Real traffic is a strong test set because it comes from actual user interactions rather than from what a developer guessed users would ask.
What is trace-based evaluation?
An MLflow trace records an agent run end to end: the input, the final output and each intermediate step, such as model calls, tool calls and retrieval. Evaluation runs scorers over traces and attaches a quality assessment to each one.
MLflow's evaluation harness has two modes. In direct evaluation, MLflow calls your app through a predict_fn and traces each new run. In answer-sheet evaluation, you supply pre-computed outputs or existing traces, and MLflow only runs the scorers. Production-trace evaluation is the answer-sheet mode.
A step-by-step workflow
- Capture and tag production traffic. Instrument the agent with MLflow Tracing and tag runs so you can filter later, for example
mlflow.update_current_trace(tags={"environment": "production"}). - Find and score the traces.
import mlflow
from mlflow.genai.scorers import Safety, RelevanceToQuery
traces = mlflow.search_traces(
filter_string="attributes.status = 'OK' AND tags.environment = 'production'",
order_by=["attributes.timestamp_ms DESC"],
)
results = mlflow.genai.evaluate(
data=traces,
scorers=[Safety(), RelevanceToQuery()],
)
- Curate a dataset. Create one with
mlflow.genai.datasets.create_dataset(name="<catalog>.<schema>.<table>")and add traces witheval_dataset.merge_records(traces). You can also select traces in the experiment's Traces tab and choose Add to evaluation dataset from Actions. - Add ground truth where it matters. Records can carry optional
expectationsfor scorers that compare against a known answer. Domain experts can supply them through labeling sessions or review queues (Beta). - Gate new versions. Run
mlflow.genai.evaluate(data=eval_dataset, predict_fn=..., scorers=...)on each candidate with the same scorers, and compare runs. - Monitor continuously. Schedule the scorers against live traffic so regressions surface on their own.
What makes production-trace evaluation trustworthy
| Practice | Why it matters |
|---|---|
| Same scorers in development and production | Scores stay comparable from the first test to live traffic |
| Feedback attached to the trace | Reviewers can open the exact steps behind a low score |
| Failures promoted into a dataset | Fixed bugs become regression tests instead of one-off fixes |
| Ground-truth expectations | Correctness-style judges need a known answer to compare against |
| Sampling by scorer cost | Run critical checks on more traffic and expensive judges on a smaller share |
| Filtered scoring | Spend judge calls on the traces you care about, such as successful production runs |
| Session-level judges | Catch problems, like user frustration, that only show across turns |
How Databricks approaches evaluation with production traces
On Databricks this runs on managed MLflow, where traces can live in Unity Catalog tables and evaluation datasets are stored in Unity Catalog with "built-in versioning, lineage, sharing, and governance", per the dataset guide. Creating a dataset needs CREATE TABLE on the target schema.
Production monitoring (Beta). Production monitoring runs MLflow 3 scorers on a configurable sample of the traces logged to an experiment and attaches results as feedback. You register a scorer and start it with a sampling configuration:
from mlflow.genai.scorers import Safety, ScorerSamplingConfig
safety_judge = Safety().register(name="safety")
safety_judge = safety_judge.start(sampling_config=ScorerSamplingConfig(sample_rate=0.7))
A filter_string on ScorerSamplingConfig limits which traces a scorer sees, using the same syntax as mlflow.search_traces(). For traces stored in Unity Catalog, set a SQL warehouse on the experiment with set_databricks_monitoring_sql_warehouse_id() before you register scorers. The monitoring job runs as the user who registered the first scorer. Custom scorers for monitoring must be @scorer functions registered from a Databricks notebook, with their imports inside the function body.
Conversations. Tag each trace with mlflow.trace.session, and mlflow.genai.evaluate() groups traces by session for multi-turn judges such as ConversationCompleteness and UserFrustration.
FAQs
Do I have to re-run my agent to evaluate production traces?
No. Pass the traces as data without a predict_fn, and MLflow runs only the scorers. Re-running is for testing a new version against a curated dataset.
Can I reuse my production-trace scorers for monitoring?
Usually. The docs warn that if you score answer-sheet traces that differ from your production traces, you may need to rewrite scorer functions before using them in production monitoring.
Can I evaluate traces without writing code?
Yes. In the experiment's Traces tab, select traces, click Actions, choose Evaluate, pick built-in or registered scorers, and click Run scorer.
Is production monitoring generally available?
No. Production monitoring is in Beta on Databricks, and multi-turn evaluation is experimental in MLflow, so its API may change.
The information provided herein is for general informational purposes only and may not reflect the most current product capabilities or configurations.