LLM-as-judge without fooling yourself

Rubrics, pairwise comparison, position and length bias, calibration against humans, and when not to use a judge.

Expert about 5 h

The picture

  1. 01

    Rubric

    specific criteria

  2. 02

    Judge

    pairwise, swapped

  3. 03

    Calibrate

    vs human labels

  4. 04

    Bias checks

    position, length

  5. 05

    Use

    trend, not truth

What a judge is

A judge is a model prompted to grade another model's output. It scales evaluation to open-ended tasks where exact match is impossible. It is also a measuring instrument with its own error, and treating it as ground truth is the most common evaluation mistake.

A good rubric

Vague: "Rate the answer quality from 1 to 10." Specific: a few independent criteria, each with anchored levels, and instructions to reason before scoring.

RUBRIC = """You grade a customer-support reply.

Criteria (score each 0, 1 or 2):
- correctness: 2 = every factual claim matches the policy excerpt; 1 = minor omission; 0 = contradicts or invents policy.
- actionability: 2 = states the exact next step; 1 = vague; 0 = none.
- tone: 2 = polite and direct; 1 = acceptable; 0 = rude or evasive.

Policy excerpt:
{policy}

Customer message:
{question}

Reply:
{reply}

First write two sentences of reasoning, then output JSON on the last line:
{{"correctness": 0-2, "actionability": 0-2, "tone": 0-2}}"""

Parse the final JSON line, validate it, and retry if it does not parse. Use temperature 0.

Pairwise comparison with position swapping

Models are better at "which is better, A or B?" than at absolute scores, but they favour whichever answer comes first. Run each pair both ways and count only consistent verdicts.

def judge_pair(question, a, b):
    def ask(x, y):
        out = llm(f"Question: {question}\n\nAnswer 1:\n{x}\n\nAnswer 2:\n{y}\n\nWhich answer is better? Reply with exactly '1', '2' or 'tie'.", 5).strip()
        return out
    first, second = ask(a, b), ask(b, a)
    mapping = {"1": "a", "2": "b", "tie": "tie"}
    v1, v2 = mapping.get(first, "tie"), {"1": "b", "2": "a", "tie": "tie"}.get(second, "tie")
    return v1 if v1 == v2 else "tie"           # inconsistent verdicts count as ties

Biases to expect

  • Position bias: favours the first (or last) answer. Swap and compare.
  • Verbosity bias: prefers longer answers. Add a length criterion, compare length-controlled, or penalise padding.
  • Self-preference: a model rates its own style higher. Use a different model family for judging.
  • Authority and format bias: confident tone and neat markdown score well regardless of correctness.
  • Sycophancy to the reference: if you give a flawed reference, it will agree with it.

Calibrate against humans

Label 50 to 100 outputs yourself, run the judge, and measure agreement, ideally with a chance-corrected statistic.

from sklearn.metrics import cohen_kappa_score, confusion_matrix

human = [h["correctness"] for h in labelled]
model = [judge(h)["correctness"] for h in labelled]
print("kappa", cohen_kappa_score(human, model, weights="quadratic"))
print(confusion_matrix(human, model))

As a rough guide, quadratic-weighted kappa above about 0.6 suggests the judge is usable for trends; much below that, fix the rubric or add human review. Re-check calibration whenever you change the judge model or the rubric.

When not to use a judge

If a program can check it (schema validity, a number matches, the test passes, a citation exists), use the program: it is cheaper, deterministic and unbiased. Use judges for what code cannot see: helpfulness, tone, faithfulness in prose. Keep human review for high-stakes decisions.

Common mistakes

  • Using the same model, same family, to write, answer and judge.
  • Averaging scores from an uncalibrated judge and reporting two decimal places.
  • Changing the judge prompt mid-experiment and comparing scores across the change.

Exercises

  1. Calibrate a judge on 60 labelled items and report kappa and the confusion matrix.
  2. Measure position bias by judging 30 pairs in both orders and counting how often the verdict flips.

You are done when you can…

  • Write a rubric that produces consistent scores across runs
  • Run pairwise judging with position swapping and measure its agreement with humans
  • Name three judge biases and one mitigation for each