Katkat

LLM Evaluation and LLM-as-a-Judge

By the Katkat team · Updated · 9 min read

Quick overview

Learn how to build eval sets and rubrics, use an LLM as a judge, spot position and verbosity bias, run pairwise tests, and calibrate scores against humans.

Lesson 22 of 88 · AI Engineering Interview Course

After this lesson you will be able to explain how to build an evaluation set for an LLM feature, write a rubric a judge model can follow, and say where LLM-as-a-judge goes wrong. You will also be able to describe pairwise comparison and show, with numbers, how to check a judge against human labels before trusting it.

Why evaluation comes first

LLM outputs are free text, so "does it work?" has no single test assertion. Without a measurement, every prompt tweak, model swap or retrieval change is a guess. A good eval is a fixed set of inputs, a way to score the outputs, and a number you can compare between versions.

Think of it as three layers:

  • Offline evals run on a fixed set before you ship. They are fast, repeatable and cheap enough to run on every change.
  • Online evals measure real traffic after you ship. See Online Evaluation and A/B Tests for LLM Features.
  • Human review is the slow, expensive ground truth that the other two are checked against.

This lesson focuses on the offline layer and on the judge model that often does the scoring. Component-specific evals are covered in Evaluating a RAG System and Evaluating Agents.

Building an eval set

An eval set is a list of cases. Each case has an input, and usually a reference answer, a list of facts that must appear, or a set of properties the answer must satisfy.

Good sources, roughly in order of value:

  1. Sampled production traffic, with personal data removed. This matches what users actually ask.
  2. Hand-written edge cases: empty input, very long input, ambiguous questions, out-of-scope questions where the right answer is a refusal.
  3. Past failures. Every bug report becomes a permanent regression case.
  4. Synthetic cases generated by a model and then reviewed by a person. They add volume but tend to be cleaner and more uniform than real traffic.

Stratify the set. Tag each case by category (for example billing, how-to, out-of-scope) so you can report a score per slice, not only an average. A change that improves the average can still break one slice badly.

Keep a held-out portion that you do not look at while tuning prompts. If you iterate against the same cases for weeks, you will overfit to them, just as you would with a training set.

How big should it be?

Size decides what differences you can detect. Suppose a prompt passes 80% of 200 cases.

  • Standard error = sqrt(0.8 × 0.2 / 200) = sqrt(0.0008) ≈ 0.028, or 2.8 points.
  • A 95% interval is about ±1.96 × 2.8 ≈ ±5.5 points, so roughly 74.5% to 85.5%.

A new prompt scoring 83% on the same 200 cases is inside that noise. To resolve a 3-point difference reliably you need many more cases, or you should compare both prompts on the same cases and look at per-case wins and losses, which removes much of the case-to-case variance. Also note that model outputs vary run to run, so repeat runs at low temperature if the noise matters.

Choosing a scoring method

MethodGood forCostMain weakness
Programmatic checks (exact match, regex, JSON schema, unit tests on generated code)Anything with a verifiable answerVery lowOnly covers what you can encode
Reference-overlap metrics (BLEU, ROUGE) or embedding similarityRough regression signalLowPoor at judging correctness or tone; paraphrases score badly
LLM judge, pointwise (score one answer)Open-ended quality, groundedness, toneMediumBiases, drift, needs calibration
LLM judge, pairwise (pick the better of two)Comparing two versionsMedium (often 2 calls per pair)Position and length bias
Human reviewGround truth, calibrating the judgeHigh and slowInconsistent between raters without guidelines

The rule of thumb: use a programmatic check whenever one exists, an LLM judge for what remains, and humans to audit the judge. For structured outputs, schema validation comes first; see Getting Reliable JSON and Structured Output.

Writing a rubric

A rubric tells the judge exactly what "good" means. Vague instructions like "rate the quality from 1 to 10" produce noisy, clustered scores. A usable rubric has:

  • One criterion per judgement. Score faithfulness, completeness and tone in separate calls or separate fields. Mixed criteria hide which one failed.
  • A small, anchored scale. Binary pass/fail or a 3-point scale with a written definition for each level is more stable than 1–10.
  • Concrete definitions. For example: "Faithful means every factual claim in the answer is supported by the provided context. One unsupported claim means fail."
  • A few worked examples, including borderline ones.
  • Reasoning before the verdict. Ask the judge to write a short justification and then the label. This tends to improve consistency and gives you something to read when debugging. Request the result in a fixed format so you can parse it reliably.

Where a reference answer exists, give it to the judge. Judging against a reference is an easier task than judging from scratch.

LLM-as-a-judge and its biases

The mechanism is simple: send a second model the input, the candidate output, optionally a reference, and the rubric, then parse its verdict. It scales far beyond human review and costs a fraction as much per item. But the judge is itself a language model with systematic tendencies:

  • Position bias. In pairwise setups, the judge may favour whichever answer appears first (or second), regardless of content.
  • Verbosity bias. Longer, more elaborate answers are often rated higher even when they are not more correct.
  • Self-preference. A judge can rate outputs from its own model family more favourably.
  • Style and confidence bias. Fluent, authoritative, well-formatted answers can beat correct but plain ones.
  • Leniency. Judges tend to pass things; they are often better at confirming good answers than at catching subtle errors.
  • Limited ability on hard tasks. If the judge cannot solve the problem itself (hard maths, deep domain facts), it cannot reliably grade it. Give it a reference.

Mitigations:

  • Randomise or swap order in pairwise tests (next section).
  • Instruct the judge not to reward length, and compare scores against length to check.
  • Use a judge from a different family than the system being tested, when practical.
  • Use a rubric with explicit failure conditions, so the default is not "looks fine".
  • Pin the judge model version, because a silent judge update changes every score. Treat the judge prompt like code; see Versioning and Rolling Out Prompts and Models.

Pairwise comparison

Humans and models are generally better at saying "A is better than B" than at assigning an absolute score. Pairwise comparison is therefore a common way to decide whether a new prompt or model beats the current one.

The procedure:

  1. Run both versions on every case in the eval set.
  2. For each case, ask the judge which answer is better (or tie), using a rubric.
  3. Run it twice, once as (A, B) and once as (B, A).
  4. If the two verdicts disagree, count the case as a tie. If they agree, count the win.
  5. Report win rate with a confidence interval.

Worked example with 100 cases and two judge calls each (200 calls):

  • 60 cases: the same version wins in both orders.
  • 20 cases: the other version wins in both orders.
  • 20 cases: the verdict flips when the order flips, so they count as ties.

The new version's score is (60 + 0.5 × 20) / 100 = 70%. The 20 flips are also a diagnostic: a flip rate of 20% tells you how much of the judge's signal is position noise. If it were 50%, the judge would be close to useless for this task.

The cost of pairwise is that it only ranks two versions against each other. It does not tell you whether either is good in absolute terms, so keep a pointwise pass rate alongside it.

Calibrating the judge against humans

A judge is a measuring instrument, and you calibrate instruments. Take a sample (say 100 cases, sampled across your categories), have people label them using the same rubric, and compare.

Worked example. Humans and the judge each give pass or fail on 100 cases:

Human passHuman fail
Judge pass6218
Judge fail416
  • Agreement = (62 + 16) / 100 = 78%.
  • Judge pass rate = 80%, human pass rate = 66%. The judge overstates quality by 14 points.
  • Precision of a judge "pass" = 62 / 80 = 77.5%.
  • Catch rate for real failures = 16 / 34 ≈ 47%. The judge misses over half of the answers humans failed.
  • Cohen's kappa corrects agreement for chance. Expected chance agreement = 0.8 × 0.66 + 0.2 × 0.34 = 0.528 + 0.068 = 0.596. Kappa = (0.78 − 0.596) / (1 − 0.596) ≈ 0.46, which is only moderate.

Raw agreement of 78% sounds acceptable, but the breakdown shows a lenient judge that hides failures. Next steps would be to read the 18 false passes, tighten the rubric with those as examples, and re-measure on fresh labelled cases. Also check that human raters agree with each other; if they only reach kappa 0.5 between themselves, the judge cannot be expected to do better.

Recalibrate whenever you change the judge model, the judge prompt, or the kind of traffic you evaluate. For changes that matter, the final decision should still involve a human look or an online test; see How Do You Ship a Prompt Change Safely?. The same discipline applies to tuned models, covered in Evaluating Fine-Tuned Models and Catastrophic Forgetting.

How does this come up in interviews?

1. "How would you evaluate a customer-support chatbot before launch?" Build an eval set from sampled past tickets, hand-written edge cases and out-of-scope questions, tagged by category. Use programmatic checks where possible (format, required links, refusal on out-of-scope), and an LLM judge with a rubric for groundedness and helpfulness. Validate the judge against a human-labelled sample, then follow with a limited online rollout.

2. "What are the failure modes of LLM-as-a-judge, and how do you mitigate them?" Name position, verbosity, self-preference, style bias and leniency. Mitigate with order swapping, rubrics with explicit failure conditions, a different-family judge, pinned judge versions, and checking score against length. Finish by saying you measure the judge against human labels rather than assuming it is right.

3. "Your new prompt wins 54% of pairwise comparisons on 100 cases. Ship it?" Not on that evidence alone. With 100 cases the uncertainty is roughly ±10 points, so 54% is statistically indistinguishable from a coin flip. I would check the order-flip rate, look at per-category results, enlarge the set, and read a sample of disagreements before deciding.

4. "How do you know your judge can be trusted?" Label a stratified sample with humans using the same rubric, then compare agreement, kappa, and the confusion matrix, not only accuracy. Look specifically at false passes, since lenient judges hide regressions. Re-run this whenever the judge model or prompt changes.

5. "When would you not use an LLM judge?" When the answer is verifiable by code: exact answers, schema validity, passing unit tests, or citation presence. Also when the judge is weaker than the task requires and no reference answer exists. In those cases use programmatic checks or human review.

Common mistakes

  • Asking for a 1–10 score with no definitions, then treating the average as precise.
  • Trusting a judge without ever comparing it with human labels.
  • Reporting a single average with no confidence interval or per-category breakdown.
  • Tuning prompts against the same cases for weeks with no held-out set.
  • Running pairwise comparisons in only one order.
  • Letting the judge be the same model (or prompt) that produced the answers.
  • Changing the judge model or prompt mid-project and comparing scores across the change.
  • Using a judge for things code can check exactly.
  • Never adding production failures back into the eval set.

Sources and further reading