Sub topic 1
What an LLM Judge Is and Why Teams Use One
Prerequisites
This chapter assumes you have:
- Basic experience prompting a large language model (LLM).
- Python reading fluency. You do not need to write much, but you should follow short functions and JSON handling.
- A basic idea of an evaluation set, meaning a list of inputs paired with the behavior you expect.
- Elementary statistics: proportions and averages.
Later chapters cover rubric design, biases, and statistics in detail. This one builds the working model that the rest depend on.
The problem: grading open-ended text
Suppose you ship a support assistant that answers questions from a help-center article. You change the prompt and want to know whether answers got better or worse. You have 500 test questions.
For some tasks, grading is easy. If the task is "return the invoice total," you compare the output to the expected number. For open-ended text, there is no single correct string. Two answers can use different words and both be right. Another answer can look fluent and still invent a refund policy.
Classic text-overlap metrics such as BLEU and ROUGE compare word sequences against a reference. They are cheap, but they reward similar wording and miss meaning. Human review catches meaning, but it is slow, costly, and hard to repeat on every code change.
What an LLM judge is
An LLM judge is a language model that you prompt to grade the output of another model or system. You give it three things:
- The material to grade, such as a question, the retrieved context, and the answer.
- A rubric, which is a written statement of what to score and what the scores mean.
- An output format, such as JSON with a score and a short reason.
The judge returns a verdict. You run it over the whole evaluation set and aggregate the verdicts, for example into a pass rate.
The system under test and the judge are separate roles. They can be different models, the same model with different prompts, or even the same model on the same day. Keeping the roles distinct in your head matters, because many pitfalls come from the judge being similar to what it grades.
The last two arrows in the diagram matter most. The judge is not trusted on its own. You compare it with human labels and revise it, and that loop is the subject of later chapters.
A minimal judge
The code below builds a judge prompt, calls a model, and parses the result. The model call is a stub so the example runs without an API key. In real use, you replace call_model with a call to your provider's SDK.
import json
RUBRIC = """Score the answer from 1 to 5 for faithfulness to the context.
1 = contradicts the context; 3 = partly supported; 5 = fully supported.
Judge faithfulness only. Ignore length and writing style."""
def build_prompt(question, context, answer):
return (
f"{RUBRIC}\n\nQuestion: {question}\nContext: {context}\nAnswer: {answer}\n\n"
'Reply with JSON only: {"reasoning": "<one or two sentences>", "score": <integer 1-5>}'
)
def call_model(prompt):
# Stub standing in for a real LLM call.
return '{"reasoning": "The answer matches the context.", "score": 5}'
def judge(question, context, answer):
data = json.loads(call_model(build_prompt(question, context, answer)))
score = data["score"]
if not isinstance(score, int) or not 1 <= score <= 5:
raise ValueError(f"invalid score: {score!r}")
return data
verdict = judge(
"How long do refunds take?",
"Refunds are issued within 5 business days.",
"Refunds take up to 5 business days.",
)
print(verdict["score"], "-", verdict["reasoning"])Three design choices are already visible here:
- The rubric covers one criterion, faithfulness, and tells the judge to ignore others.
- The output is JSON, so code can read it.
- The parser rejects invalid scores instead of accepting them silently. A judge that returns
"score": "great"should fail loudly in your pipeline.
Why teams use judges
Scale and speed
A judge can grade thousands of outputs in minutes. That makes it practical to run an evaluation on every prompt change or model upgrade, the way you run unit tests on every commit.
Cost
Human graders cost more per item and need training and scheduling. A judge call costs a fraction of a cent to a few cents, depending on model and input length. Judges do not make humans free, because you still need human labels to validate the judge, but you need far fewer of them.
Consistency of procedure
Human graders drift, get tired, and interpret rubrics differently. A judge applies the same written rubric every time. Be careful with the word consistent here. The procedure is repeatable, but the verdicts are not guaranteed identical across runs, and the judge can be consistently wrong in a systematic way. Later chapters on variance and bias cover this.
Coverage of fuzzy criteria
Some qualities have no simple programmatic check: whether an answer is faithful to a source, whether a tone is polite, whether a summary omits a key fact. A judge can approximate these checks where regular expressions and string matching cannot.
What a judge measures, and what it does not
A judge measures how a language model, given your rubric, rates an output. That is a proxy for what you actually care about, which is usually what a careful human reviewer would conclude, and ultimately whether users are well served.
The gap between those has consequences:
- The judge score is only as meaningful as its agreement with humans on your task. A score of 4.2 out of 5 means nothing until you know how the judge behaves on known-good and known-bad examples.
- A judge can be good at one criterion and poor at another. Validate per criterion.
- A judge result is an estimate, not a fact. A pass rate computed from 50 items has a wide margin of error.
Common judge setups at a glance
The next chapters go deeper into each of these. For orientation:
| Format | What the judge sees | What it returns | Typical use |
|---|---|---|---|
| Pointwise | One output | A score or pass/fail | Absolute quality checks, regression tests |
| Pairwise | Two outputs for the same input | Which is better | Comparing two prompts or models |
| Reference-based | One output plus a reference answer | Whether it matches the reference | Tasks with a known good answer |
Common mistakes to avoid from the start
- Using a vague rubric such as "rate the quality of this answer." The judge will fill the gaps with its own preferences. Name one criterion and define the score levels.
- Skipping the human check. Without labels, you cannot tell a good judge from a confident one.
- Comparing scores across different judge prompts or models as if they were on one scale. A change to the rubric or the judge model changes what the numbers mean.
- Reporting a single number with no sense of uncertainty. Small evaluation sets produce noisy metrics.
- Using a judge where a deterministic check works. If you can verify a JSON schema or an exact value with code, do that instead.
Summary of the working model
An LLM judge is a prompted model that grades another system's output against a written rubric and returns a structured verdict. Teams use it because it is faster and cheaper than human review and can cover fuzzy criteria. It is a proxy for human judgment, so it needs validation, and the rest of this tutorial covers how it goes wrong and how to check it.
Exercise
Your team wants to evaluate a chatbot's answers for whether they are faithful to a source document, and for whether a returned order ID matches the ID in the database. Which of these two checks should use an LLM judge, which should use a deterministic check, and what must you do before trusting the judge's results?
Show answer
Use an LLM judge for faithfulness, because it is a fuzzy criterion with no simple programmatic test. Use a deterministic check (exact string comparison against the database value) for the order ID, because the correct answer is known and code can verify it exactly. Before trusting the faithfulness judge, compare its verdicts with human labels on a sample of your own data and measure how well they agree.
Exercise
In the minimal judge code, why does parse logic reject a score of 7 or "great" instead of passing it along?
Show answer
Invalid values would silently corrupt the aggregate metric. For example, a string would break averaging, and an out-of-range number would inflate or deflate the mean. Raising an error makes the problem visible so you can fix the prompt, retry, or log the failure.