Suryanand/ Bootcamp
suryanand.com ↗Let's talk
← Evals and observabilityAI guideIntermediate#evals#llm-as-judge#pairwise#rubrics
Frame · ai-engineering / evals-observability / 04-pairwise-and-rubric-grading.mdGuide 052 / 103

Pairwise and rubric grading

Some outputs have no single right answer. A summary, a sales email or a support reply can be good in many ways. For these, the two grading patterns I reach for most are pairwise comparison (show a judge two outputs and ask which is better) and rubric grading (score one output against a list of explicit criteria). They answer different questions, and mixing them up is a common source of confusing eval results.

Why it matters

Absolute scores on open-ended text are noisy. Ask a human or a model to rate a summary from 1 to 10 and you get different answers on different days. Comparisons are easier: people and models are more consistent when asked "is A or B better at X" than "how good is A". That is the insight behind Chatbot Arena and why LangSmith, Braintrust and others support pairwise experiments.

Rubrics fix a different problem. When a stakeholder says "the answer should be accurate, cite sources and stay under 120 words", that is already a rubric. Writing it down makes grading explicit, debuggable and auditable, and it tells you which criterion failed, not just that something did.

Rule of thumb:

  • Pairwise when you are choosing between two versions (prompt v1 vs v2, model A vs model B) and care about relative quality.
  • Rubric when you need an absolute bar a single version must clear, for example in a CI gate.

How it works

Rendering diagram…

Pairwise grading. For each input, generate outputs from both versions. Present them to a judge in random order and ask which better satisfies a specific criterion. Run each pair twice with the order swapped; if the verdict flips, record a tie. Aggregate into a win rate. Positional bias is real and well documented (the MT-Bench paper found it for most judges, and a 2024 systematic study by Shi et al. measured it across 15 judges), so the swap is not optional.

LangSmith exposes this as pairwise experiments, with an evaluate_comparative function that takes two existing experiments and an evaluator, and has a randomize_order option. Their newer docs also show running pairwise evaluation through evaluate() with two experiments.

Rubric grading. Write a short list of criteria, each one a yes or no question. "Is every number in the answer present in the source?" is a criterion. "Is the answer high quality?" is not. The judge returns a verdict per criterion, with reasoning. You can then report per-criterion pass rates, which point straight at what to fix. G-Eval (Liu et al.) is an early, influential paper on structured, criteria-based LLM grading.

Combining them. A practical flow: use pairwise during development to pick the better candidate quickly, then lock that version and use rubric grading in CI to make sure it never drops below the bar.

Reference architecture

Rendering diagram…

Code

A pairwise judge with order swapping and a rubric judge with per-criterion verdicts. Again the model call is abstract.

import json
import random
from collections import Counter

def call_judge(prompt: str) -> str:
    raise NotImplementedError  # your LLM client, temperature 0

PAIRWISE = """Question: {q}

Response 1:
{r1}

Response 2:
{r2}

Which response answers the question more accurately and concisely?
Reply with JSON: {{"reasoning": "...", "winner": "1" | "2" | "tie"}}"""

def pairwise(q: str, a: str, b: str) -> str:
    def ask(r1: str, r2: str) -> str:
        out = json.loads(call_judge(PAIRWISE.format(q=q, r1=r1, r2=r2)))
        return out["winner"]
    first = ask(a, b)                     # A in slot 1
    second = ask(b, a)                    # A in slot 2
    a_wins = (first == "1") + (second == "2")
    b_wins = (first == "2") + (second == "1")
    if a_wins == 2: return "A"
    if b_wins == 2: return "B"
    return "tie"

RUBRIC = [
    "Every number in the answer appears in the source.",
    "The answer cites at least one source ID.",
    "The answer is under 120 words.",
    "The answer does not promise anything the policy does not allow.",
]

RUBRIC_PROMPT = """Source:
{src}

Answer:
{ans}

For each criterion, decide pass or fail.
Criteria:
{criteria}

Reply with JSON: {{"results": [{{"criterion": int, "reasoning": str, "pass": bool}}]}}"""

def rubric(src: str, ans: str) -> dict[int, bool]:
    crit = "\n".join(f"{i}. {c}" for i, c in enumerate(RUBRIC))
    out = json.loads(call_judge(RUBRIC_PROMPT.format(src=src, ans=ans, criteria=crit)))
    return {r["criterion"]: r["pass"] for r in out["results"]}

def win_rate(results: list[str]) -> dict[str, float]:
    c = Counter(results)
    n = len(results)
    return {k: c[k] / n for k in ("A", "B", "tie")}

In practice I also move deterministic criteria (like the word count above) out of the judge and into code, then keep only the criteria that need judgement in the rubric prompt.

Trade-offs and pitfalls

  • Pairwise is relative. A 70 percent win rate over v1 says nothing about whether v2 is good enough to ship. Pair it with an absolute check.
  • Cost doubles (or quadruples). Pairwise with order swapping means two judge calls per input, plus generating outputs from both versions.
  • Ties hide information. Many ties usually means the criterion is too vague or the versions really are equivalent. Look at the reasoning.
  • Rubric bloat. Ten criteria in one prompt degrade judge accuracy. Keep it to a handful, or split into separate judge calls per criterion.
  • Vague criteria. "Professional tone" means different things to different reviewers. Add one passing and one failing example per fuzzy criterion.
  • Transitivity. Pairwise preferences across many versions are not always transitive. If you compare more than two, use a rating system (Elo or Bradley-Terry style) rather than chaining pairwise results.
  • Calibration still applies. Both patterns use judges, so measure agreement with humans on a labelled subset.

Checklist

  • Pairwise runs swap response order and treat flipped verdicts as ties.
  • Win rates are reported with the number of comparisons and ties.
  • Each rubric criterion is a single yes or no question.
  • Deterministic criteria are graded in code, not by the judge.
  • Per-criterion pass rates are shown, not just a total score.
  • The judge prompt and model are pinned and calibrated against human labels.

Further reading

Why this exists README

I learn best by explaining things, so I record the explanations. Everything here is free, with no sign-up. If a lesson helps you ship something, I'd love to hear about it.