Zum Inhalt springen

Lektion 17 · Evaluation

Scorers and Judges

Choose MLflow scorers: built-in judges, code-based custom scorers and make_judge LLM judges. Learn to calibrate judges against human labels.

A scorer turns the output of an app into feedback, such as pass or fail, a number, or a label with a reason. Good scorers decide whether your evaluation means anything.

Three kinds

Kind How it works Best for
Built-in judge A ready-made LLM judge Common qualities such as relevance or correctness
Code scorer Your Python function Exact rules: format, length, required text
Custom LLM judge Your instructions for a model Nuanced quality in your own domain

Prefer code when the rule can be written precisely. It is fast, cheap and repeatable.

Built-in judges

The documentation lists judges such as RelevanceToQuery, Correctness, Completeness, Safety, Guidelines, RetrievalGroundedness, RetrievalRelevance and ToolCallCorrectness. Some need expectations, such as a reference answer. Others, such as retrieval and tool-call judges, need traces. As of December 2026, the docs say that a few judges, including Safety and RetrievalRelevance, are available only in Databricks managed MLflow. Check the table of predefined judges for current availability.

Code-based scorers

Use the @scorer decorator. Your function may declare any of inputs, outputs, expectations and trace, and take only what it needs.

Python
from mlflow.entities import Feedback
from mlflow.genai.scorers import scorer

@scorer
def has_order_id(outputs) -> bool:
    return "ORD-" in outputs

@scorer
def short_enough(outputs, expectations):
    limit = expectations.get("max_words", 60)
    words = len(outputs.split())
    return Feedback(value=words <= limit, rationale=f"{words} words, limit {limit}")

A scorer may return True or False, "yes" or "no", a number, a Feedback object with a rationale, or a list of Feedback objects with different names.

Custom LLM judges

make_judge (MLflow 3.4.0 and later) builds a judge from instructions:

Python
from typing import Literal
from mlflow.genai.judges import make_judge

tone_judge = make_judge(
    name="tone",
    instructions=(
        "Rate the tone of the reply in {{ outputs }} to the request "
        "in {{ inputs }}. Answer 'good' or 'poor'."
    ),
    feedback_value_type=Literal["good", "poor"],
    model="<provider>:/<model-name>",
)

The instructions must use at least one reserved template variable: {{ inputs }}, {{ outputs }}, {{ expectations }}, {{ trace }} or {{ conversation }}. Your own names such as {{ question }} are rejected. The docs also restrict how conversation combines with the others. Check the custom judges page for your version, including the import path.

Calibrate your judge

A judge is itself a model, and it can be wrong. Before you trust it:

  1. Label 30 to 50 examples yourself, or with colleagues.
  2. Run the judge on the same examples.
  3. Count agreement, and read the disagreements.
  4. Improve the instructions and repeat on new examples.
Python Stand-in: measure agreement between a judge and humans

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Both label lists are made up. Overall agreement looks fine, but the judge misses half of the poor replies. If your goal is to catch bad answers, that second number matters more.

A code scorer in practice

Python Stand-in: rule checks that return a reason

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

A word list is crude: it flags harmless sentences and misses clever ones. Use it as a cheap first check, and read what it flags. For more theory, see LLM as a judge.

An LLM judge can be influenced by the text it grades, including instructions hidden inside an answer. Treat judge results as evidence, not proof, and keep human review for high-stakes cases.

Write good judge instructions

A vague instruction gives inconsistent results. "Rate how good the answer is" leaves "good" undefined. Better instructions:

  • Judge one quality at a time.
  • Define each allowed answer with plain examples of what counts.
  • Say what to do when information is missing or unclear.
  • Ask for a short reason, so that you can check the logic.

For example: "Answer 'good' if the reply states the return window from the context and does not add rules that are not in the context. Otherwise answer 'poor'." Two people reading this should usually reach the same verdict. If they do not, a judge cannot either.

Mind the cost

Every judge call adds cost and time. For large datasets, run cheap code scorers on everything, and run LLM judges on a sample or on rows that fail a cheap check. Check the pricing of your judge model before a large run. Also decide which data you are allowed to send to it.

Test your scorers

A code scorer is code, so test it like code. Write examples that should pass and fail, including tricky cases: empty output, different capitalization, extra spaces, and answers in another language. A scorer that always returns true makes your app look perfect. Include at least one case that you expect to fail, and confirm that it does.

Keep scorers stable

When you change a scorer, old and new results are no longer comparable. Give the new version a new name, or record a version in the metadata. When you compare two app versions, use exactly the same scorers on both, otherwise you may be measuring the change in the scorer. After changing judge instructions or the judge model, repeat your calibration against human labels.

Where humans stay in the loop

Automatic scores help you review more cases than any person could read, but they do not remove the need to read. Set aside time to look at a random sample, including cases that passed. Passing cases can hide problems that no scorer checks, such as an odd tone or a missing warning. When you find one, decide whether it deserves a new scorer, a new test case, or both.

Check your understanding

Quick check · 3 questions

of 3 answered You scored / 3 · perfect!

  1. 1. When is a code-based scorer usually the best choice?

    Code checks are cheap, fast and repeatable for exact rules.
  2. 2. Which template variable would make_judge reject?

    Only reserved variable names are allowed, and question is not one of them.
  3. 3. How do you check whether to trust an LLM judge?

    Agreement with careful human labels measures how well the judge matches your standard.

Summary

  • Scorers can be built-in judges, Python functions or custom LLM judges.
  • @scorer functions return booleans, labels, numbers or Feedback.
  • make_judge instructions use reserved variables only.
  • Calibrate judges against human labels.

Next: Tracing Basics

Dein Fortschritt wird in diesem Browser gespeichert. Kein Konto nötig.