Evaluation and Monitoring · Topic 1 of 2
Evaluating Agents with MLflow Scorers and SME Feedback
Databricks GenAI Engineer: mlflow.genai.evaluate, tracing, judges needing ground truth, custom scorers, SME feedback and picking an LLM by metrics.
- 5 min
mlflow.genai.evaluate(data, predict_fn, scorers)runs the agent and scores every row.- Correctness and RetrievalSufficiency need expectations; safety, relevance, groundedness and guidelines do not.
- Traces show retriever, LLM and tool spans, so they locate the failing step.
What it is
Before an agent goes live you measure it. MLflow 3 runs the agent over an evaluation dataset with mlflow.genai.evaluate, records a trace of every step, and applies scorers that grade each answer.
Scorers are either built in LLM judges (correctness, safety, groundedness and more) or custom scorers you write. Subject matter experts add the human signal that judges and datasets are built from.
How it works
Tracing
A trace records each span of a request: retriever calls with the chunks returned, LLM calls with prompts and token counts, tool calls and latency. Turn it on with autologging for your library, such as mlflow.langchain.autolog(), or decorate your own functions with @mlflow.trace.
Traces are how you debug a bad answer. If the retrieved chunks do not contain the fact, fix retrieval; if they do and the answer is still wrong, fix the prompt or the model.
Running an evaluation
from mlflow.genai.scorers import Correctness, RelevanceToQuery, Safety, Guidelines
data = [{"inputs": {"question": "What is Delta Lake?"},
"expectations": {"expected_facts": ["open table format", "ACID transactions"]}}]
results = mlflow.genai.evaluate(
data=data, predict_fn=lambda question: agent.invoke(question),
scorers=[Correctness(), RelevanceToQuery(), Safety(),
Guidelines(name="polite", guidelines="The answer must be polite.")])
predict_fn is called with the keys of inputs as arguments. Each row gets a score and a written rationale from every scorer, and the run shows aggregates you can compare across versions.
Judges that need ground truth
| Judge | Asks | Needs ground truth |
|---|---|---|
| Correctness | Does the answer match the expected facts or response? | Yes |
| RetrievalSufficiency | Did the retrieved context contain the expected facts? | Yes |
| RelevanceToQuery | Does the answer address the question? | No |
| RetrievalRelevance | Are the retrieved chunks relevant to the question? | No |
| RetrievalGroundedness | Is the answer supported by the retrieved context? | No |
| Safety | Is the answer free of harmful content? | No |
| Guidelines | Does the answer follow your natural language rules? | No |
Ground truth lives in expectations, as expected_facts or expected_response. Judges without ground truth can also run on live traffic, which has no expected answers.
Custom scorers
When no built in judge measures what the business needs, write a code based scorer with the @scorer decorator. It may read inputs, outputs, expectations and the trace, and returns a bool, a number, a yes or no string, or a Feedback object.
from mlflow.genai.scorers import scorer
@scorer
def cites_source(outputs) -> bool:
return "[source:" in str(outputs)
Use code for checks a rule can decide (format, length, a required field, latency from the trace). Use a Guidelines judge for criteria that need judgment, written in plain language.
Incorporating SME feedback
| Tool | What experts do | What you get |
|---|---|---|
| Review App chat | Chat with the agent and rate answers | Feedback on fresh conversations |
| Labeling session | Label selected traces against label schemas | Feedback and expectation labels on real traces |
A label schema of type expectation captures the correct answer, which becomes ground truth in your evaluation dataset. A schema of type feedback captures a rating or a category, which shows where the agent fails and what guidelines to write. Reviewers must be provisioned in the Databricks account and need edit access to the experiment.
Choosing an LLM by metrics
Run every candidate model through the same evaluation dataset and scorers, then compare quality scores with latency and token cost from the traces. Pick the smallest model that meets the quality bar; move up in size only when a measured metric fails.
Architecture matters too. A reasoning model can raise correctness on multi step questions at the price of latency and tokens, while a smaller instruction tuned model often matches it on simple extraction.
How the exam asks about this
- "There is no labeled dataset yet; check that answers are on topic and safe." Use RelevanceToQuery and Safety, which need no ground truth.
- "Every answer must end with a ticket number in a fixed format." Write a custom code scorer with
@scorer. - "Domain experts must correct answers so the team can build a test set." Run a labeling session with an expectation label schema.
What to remember for the exam
mlflow.genai.evaluate(data, predict_fn, scorers)runs the agent and scores every row.- Correctness and RetrievalSufficiency need expectations; safety, relevance, groundedness and guidelines do not.
- Traces show retriever, LLM and tool spans, so they locate the failing step.
- Code scorers use
@scorer; plain language criteria use Guidelines. - SME expectation labels become ground truth; feedback labels guide fixes.
- Compare models on the same dataset; choose the smallest one that passes.
Do not pick a model from a public leaderboard alone. Only your own evaluation dataset and scorers show how it performs on your documents and questions.
Common mistakes
Running Correctness without expectations. It compares against expected facts or an expected response. Without them it cannot score, so use judges that need no ground truth.
Fixing the prompt when retrieval failed. If RetrievalSufficiency or the trace shows the fact was never retrieved, no prompt change will help. Fix chunking, embeddings or filters.
Treating SME comments as one off fixes. Feed their labels into the evaluation dataset and guidelines. Then every later version is tested against what the experts taught you.
Check yourself
Which built in judges require ground truth?
Correctness and RetrievalSufficiency, because both compare against expected facts or an expected response in the expectations.
When should you write a custom code scorer instead of using a judge?
When a rule can decide the result, such as a required format, field or length, so plain code is cheaper and fully consistent.
How do SME labels improve an agent?
Expectation labels become ground truth in the evaluation dataset, and feedback labels show failures that guide prompt, retrieval or guideline fixes.
Topic 1 of 2 in Evaluation and Monitoring
Test yourself on Evaluation and Monitoring
The full Databricks Generative AI Engineer Associate question bank has 600 questions, with timed practice exams and an explanation for every answer.
This study guide is independent and is not affiliated with, endorsed by, or sponsored by Databricks. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.