Skip to main content

How do I use LLM-as-a-judge to evaluate an AI agent?

Summary

  • LLM-as-a-judge uses a language model to score an agent's outputs, or its full execution trace, against criteria you define, so you can grade open-ended answers without reading every one by hand.
  • Give each quality criterion its own judge, run the judges over a fixed evaluation dataset, and compare agent versions on the same judges and data before you ship a change.
  • On Databricks, MLflow provides built-in judges such as RelevanceToQuery, RetrievalGroundedness, Safety and Correctness, plus make_judge() for custom criteria and trace-based judges that inspect tool use.
  • Check judges against expert labels, then call align() to tune a judge to that feedback. MLflow uses the MemAlign optimizer by default.
  • The same scorers can run on live traces through MLflow production monitoring, which is in Beta.

How do I use LLM-as-a-judge to evaluate an AI agent?

Turn your definition of a good answer into explicit criteria, give each criterion its own judge, and run the judges over a fixed evaluation dataset every time the agent changes. Then check the judges against human labels and align them before you trust their scores. On Databricks, MLflow 3 evaluation packages this workflow: built-in and custom judges, mlflow.genai.evaluate() to run them, alignment from expert feedback, and the same scorers on production traces.

What is LLM-as-a-judge?

An LLM judge is a scorer that prompts a language model to assess an agent's behavior and return a structured verdict, such as pass or fail, a category or a number. It's the practical way to grade outputs with no single correct string: relevance, tone, groundedness, or whether the agent picked the right tool. Deterministic checks, such as exact matches or format validation, still belong in code. A judge is only as good as its instructions and its agreement with your reviewers, which is why alignment matters.

Key decisions when you design judges

Decision Options Guidance
What the judge sees Inputs and outputs, expected answers, or the full trace Use the full trace when the question is about tool use or multi-step behavior
Ground truth With or without expectations Correctness-style judges need expected answers; relevance and safety judges don't
Output format Pass/fail, categories or a numeric score List the exact allowed values in the instructions
Scope One turn or a whole conversation Use multi-turn judges for conversational agents
Judge model The default judge model or one you choose Trace-based judges need a model you specify
Trust Raw judge or aligned judge Align against expert labels before you rely on scores

How to do it on Databricks with MLflow

1. Start with built-in judges. MLflow's built-in judges cover common dimensions: RelevanceToQuery, RetrievalRelevance, RetrievalGroundedness, RetrievalSufficiency, Safety and Correctness, plus ToolCallCorrectness and ToolCallEfficiency for agents that call tools. Guidelines judges pass or fail natural-language rules you write, such as style or policy requirements. Multi-turn judges such as ConversationCompleteness and UserFrustration score a whole conversation.
2. Write custom judges for your own criteria. make_judge() takes a name, instructions and an output type. Instructions can use only four template variables: {{ inputs }}, {{ outputs }}, {{ expectations }} and {{ trace }}.

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

correctness_judge = make_judge(
    name="answer_correctness",
    instructions=(
        "Given the request in {{ inputs }}, decide whether the response in "
        "{{ outputs }} matches the expected answer in {{ expectations }}. "
        "Return 'correct' only if the response conveys the same facts as the "
        "expected answer. Otherwise, return 'incorrect'."
    ),
    feedback_value_type=Literal["correct", "incorrect"],
)

Field-based judges like this one run on the default judge model. Trace-based judges read {{ trace }} and explore it to check tool selection, parameters and multi-step workflows, and they need an explicit model argument.
3. Run the judges over an evaluation dataset. Pass the dataset, a predict_fn that calls your agent, and a list of scorers to mlflow.genai.evaluate():

import mlflow
from mlflow.genai.scorers import RelevanceToQuery

results = mlflow.genai.evaluate(
    data=eval_data,
    predict_fn=predict_fn,
    scorers=[RelevanceToQuery(), correctness_judge],
)

Each row produces a trace annotated with feedback from every judge. Rerun the same dataset and judges against the next agent version to see what changed.
4. Align judges with human feedback. Have domain experts review and correct judge assessments, and log their feedback under the judge's exact name. Then call align() with those traces. Without an explicit optimizer, MLflow uses MemAlign and returns a new, aligned judge. The docs say "You can achieve reasonable alignment with at least 10 traces, but 50-100 traces yield better results." Alignment isn't supported for multi-turn judges.
5. Keep judging in production. Production monitoring (Beta) runs the same scorers on a configurable sample of incoming traces in an MLflow experiment and attaches the results as feedback. You register a scorer and start it with a sampling configuration, so development and production share one definition of quality.

FAQs

Which model powers a Databricks LLM judge?

By default, a Databricks-hosted LLM designed for GenAI quality assessments. You can change it with the model argument, in the <provider>:/<model-name> format.

Do I need ground truth to use LLM judges?

Not for every judge. RelevanceToQuery, Safety and RetrievalGroundedness work from inputs and outputs, while Correctness, RetrievalSufficiency and ToolCallCorrectness need expected answers.

Can a judge evaluate an agent's tool calls?

Yes. ToolCallCorrectness and ToolCallEfficiency check whether tool calls are correct and free of redundancy, and custom trace-based judges can read the full trace to verify multi-step behavior.

When is a code-based scorer the right choice?

Use code for deterministic checks such as exact matching, format validation or performance metrics. Use an LLM judge when the criterion needs judgment.

The information provided herein is for general informational purposes only and may not reflect the most current product capabilities or configurations.