Skip to content
Streak:0Loading your progress…Sign in

Module 12 · Lesson 2 of 2

LLM-as-judge & regression gates

Grade open-ended outputs with a model — carefully — and block bad releases. ~35 min

Lesson notes

LLM judges are useful for open-ended criteria (faithfulness to sources, tone, completeness), but they have biases: position bias (prefers the first option), verbosity bias, and self-preference. Mitigations: grade one criterion at a time with a concrete rubric, ask for reasoning before the verdict, use structured output, swap positions in pairwise comparisons, and calibrate the judge against human labels before trusting it.

A rubric-based judge prompt
JUDGE = """You are grading whether an ANSWER is fully supported by SOURCES.
Score 1 if every factual claim in the answer is supported by the sources.
Score 0 if any claim is unsupported or contradicted.
Think step by step inside <reasoning>, then output <score>0</score> or <score>1</score>."""

Practice

  1. 1. Pairwise judge with position swap

    hard50 XP

    Write parse_verdict(text) -> "A" | "B" | "tie" | None reading the last <verdict>X</verdict> tag (case-insensitive X, tolerate whitespace). Then write compare(question, out1, out2, judge) -> "1" | "2" | "tie" | "inconsistent": call judge(prompt) twice — once with out1 as A, once swapped. If both runs agree on the same underlying output, return it; if both say tie return "tie"; if either verdict is unparseable or they disagree return "inconsistent". Build prompts with make_prompt(question, a, b) (given).

    Ctrl/⌘ + Enter runs the tests · Esc then Tab leaves the editor

  2. 2. CI regression gate

    medium25 XP

    Write gate(baseline, candidate, max_drop=0.02) where each is a dict case_id -> bool (passed). Only compare cases present in both. Return {"ship": bool, "baseline_rate", "candidate_rate" (4dp), "regressions": sorted ids that passed in baseline but fail in candidate, "fixes": sorted ids that newly pass}. Ship only if the candidate pass rate hasn't dropped by more than max_drop and no case tagged critical regressed — critical ids are those starting with "crit:".

    Ctrl/⌘ + Enter runs the tests · Esc then Tab leaves the editor