{"slug": "your-llm-eval-rubric-is-a-test-fixture-score-it-and-check-grader-agreement-in", "title": "Your LLM Eval Rubric Is a Test Fixture: Score It and Check Grader Agreement in Python", "summary": "A developer published a roughly 150-line standard-library Python approach that treats an LLM eval rubric as a versioned test fixture, scoring a batch of graded outputs and checking inter-grader agreement before producing a GO/NO-GO decision. The method breaks \"good\" into three to five weighted, anchored dimensions plus critical failures, and flags overlapping dimensions by merging any two that score identically on nearly every output. All numbers in the example, a fictional support-ticket summarizer, are explicitly made up.", "body_md": "Every LLM feature ends up answering \"is this output good?\" hundreds of times: in offline evals, in sampled production audits, and every time someone changes a prompt or swaps a model. If the answer depends on who's reading, your eval numbers measure the reviewer as much as the output. Hand that same vague question to an LLM judge and you've automated the noise.\n\nA rubric fixes this, and the useful way to think about it as an engineer is as a **test fixture**: a fixed, versioned scoring spec that every candidate output gets run against. Like any fixture, it can be wrong. The difference is that a broken rubric doesn't throw an error; it just produces scores that two people can't reproduce. This post covers how to build a rubric that holds up, then gives you about 150 lines of standard-library Python that scores a batch of graded outputs, checks whether the graders actually agree, and turns it all into a GO / NO-GO.\n\n**About the numbers:** the rubric, the weights, every grader score, and every threshold below are made-up example data for a fictional support-ticket summarizer. They're picked to make the checks easy to follow, not taken from any real product or study. Replace them with your own before you trust a GO.\n\nBinary pass/fail is tempting because it's easy to collect. It's fine for narrow checks (\"is the output valid JSON?\"), but for anything involving judgment it hides two things you need: *why* an output is weak, and whether a change made things slightly better or slightly worse. A prompt tweak that turns a \"barely acceptable\" summary into a \"good\" one shows up as no change at all in a thumbs-up metric.\n\nA rubric breaks \"good\" into a few separately scored dimensions, each with written anchors, combined by explicit weights, with a short list of critical failures that override everything. That gives you a number you can diff between runs and a breakdown that tells you where to look.\n\nFour parts. The script's `DATA[\"rubric\"]` and `DATA[\"critical_failures\"]` map one-to-one onto them.\n\nDerive them from what the user needs from the output, not from a generic list. Most dimensions come from five families: correctness (faithful to the source), completeness, relevance, format, and tone/safety. Three to five is the useful range: fewer and you lose diagnostic detail, more and graders slow down and dimensions start overlapping.\n\nA cheap overlap test: if two dimensions get the same score on nearly every output, merge them. They're one assertion written twice.\n\n\"1 = poor, 5 = excellent\" is the rubric equivalent of `assert output_is_fine()`. Anchors should describe **observable** features of the output, ideally **countable** ones, and be **specific to the feature**. Write 1, 3 and 5 first (easiest to tell apart), then define 2 and 4 as \"in between\" with one distinguishing detail each.\n\nHere's the fictional summarizer rubric used throughout this post:\n\n| Dimension | Weight | 5 | 3 | 1 | \n|---|---|---|---|---|\n| Faithfulness | 40% | Every statement supported by the thread | One minor unsupported detail; agent would act the same | Unsupported claim that would mislead the next agent | \n| Completeness | 30% | Issue, steps tried, status and next step all present | One of the four elements missing | Two or more missing, or main issue missing | \n| Concision | 15% | Short and to the point | A bit wordy | Far too long | \n| Format | 15% | All four UI labels present and correct | One label missing or mislabeled | Unstructured paragraph the UI can't render | \n\nLook at Concision before reading on. It's deliberately bad, and the script is going to catch it.\n\nFor a summarizer, a fabricated fact is worse than an extra sentence, so Faithfulness carries 40% and Concision 15%. Weights sum to 1.0 (the script refuses to run otherwise), and the overall score is the weighted average. Put the *reason* for each weight in a comment next to it; when someone challenges the rubric in six months, the reasoning is what they'll need.\n\nWorked by hand, a summary scored Faithfulness 5, Completeness 3, Concision 3, Format 5 comes out to:\n\n```\n5*0.40 + 3*0.30 + 3*0.15 + 5*0.15 = 2.00 + 0.90 + 0.45 + 0.75 = 4.10\n```\n\nThat's grader A's score for item T02 in the sample data below.\n\nSome outputs should fail no matter how they average out. A beautifully formatted summary that promises the customer a refund they never asked for is a fail. For the summarizer: an invented promise (refund, credit, timeline), payment card details in the output, or the wrong customer or account. In code terms these are hard assertions that run before the weighted score matters.\n\nKeep the list short and unambiguous. If graders argue about whether something counts as critical, it belongs in a dimension's anchors instead.\n\nSave this as `rubric_score.py` (standard library only, Python 3.8+). It embeds the fictional rubric and ten outputs, each scored independently by two graders, A and B. Pass a JSON file with the same shape to score your own:\n\n```\n# rubric_score.py -- score LLM outputs against a weighted rubric and check grader agreement.\n# The rubric, scores and thresholds below are made-up example data for a fictional\n# support-ticket summarizer. Pass a JSON file with the same shape to score your own.\n\nimport json\nimport sys\nfrom collections import Counter\n\nDATA = {\n    \"rubric\": {\n        \"faithfulness\": {\"weight\": 0.40, \"anchors\": {\n            5: \"every statement supported by the thread\",\n            3: \"one minor unsupported detail; agent would act the same\",\n            1: \"unsupported claim that would mislead the next agent\"}},\n        \"completeness\": {\"weight\": 0.30, \"anchors\": {\n            5: \"issue, steps tried, status and next step all present\",\n            3: \"one of the four elements missing\",\n            1: \"two or more missing, or main issue missing\"}},\n        \"concision\": {\"weight\": 0.15, \"anchors\": {\n            5: \"short and to the point\",\n            3: \"a bit wordy\",\n            1: \"far too long\"}},\n        \"format\": {\"weight\": 0.15, \"anchors\": {\n            5: \"all four UI labels present and correct\",\n            3: \"one label missing or mislabeled\",\n            1: \"unstructured paragraph the UI can't render\"}},\n    },\n    \"critical_failures\": [\"invented_promise\", \"card_details\", \"wrong_customer\"],\n    \"thresholds\": {\"pass_score\": 4.0, \"dimension_floor\": 3.5,\n                   \"min_kappa\": 0.6, \"min_within_one\": 0.9},\n    # Each output was scored independently by two graders (A and B), 1-5 per dimension.\n    \"outputs\": [\n        {\"id\": \"T01\", \"A\": [5, 5, 4, 5], \"B\": [5, 5, 5, 5], \"critical\": []},\n        {\"id\": \"T02\", \"A\": [5, 3, 3, 5], \"B\": [5, 3, 5, 5], \"critical\": []},\n        {\"id\": \"T03\", \"A\": [3, 5, 2, 5], \"B\": [3, 5, 4, 5], \"critical\": []},\n        {\"id\": \"T04\", \"A\": [5, 4, 5, 3], \"B\": [5, 4, 3, 3], \"critical\": []},\n        {\"id\": \"T05\", \"A\": [1, 3, 4, 5], \"B\": [1, 3, 4, 5], \"critical\": [\"invented_promise\"]},\n        {\"id\": \"T06\", \"A\": [5, 5, 3, 5], \"B\": [5, 5, 3, 5], \"critical\": []},\n        {\"id\": \"T07\", \"A\": [4, 3, 5, 1], \"B\": [4, 3, 2, 1], \"critical\": []},\n        {\"id\": \"T08\", \"A\": [5, 5, 4, 5], \"B\": [5, 4, 2, 5], \"critical\": []},\n        {\"id\": \"T09\", \"A\": [5, 4, 3, 5], \"B\": [5, 4, 5, 5], \"critical\": []},\n        {\"id\": \"T10\", \"A\": [3, 3, 5, 3], \"B\": [3, 3, 3, 3], \"critical\": []},\n    ],\n}\n\ndef validate(data):\n    rubric = data[\"rubric\"]\n    total = sum(d[\"weight\"] for d in rubric.values())\n    if abs(total - 1.0) > 1e-9:\n        sys.exit(f\"weights sum to {total:.2f}, expected 1.00\")\n    for o in data[\"outputs\"]:\n        for g in (\"A\", \"B\"):\n            if len(o[g]) != len(rubric) or not all(1 <= s <= 5 for s in o[g]):\n                sys.exit(f\"{o['id']} grader {g}: need {len(rubric)} scores in 1-5\")\n        unknown = set(o[\"critical\"]) - set(data[\"critical_failures\"])\n        if unknown:\n            sys.exit(f\"{o['id']}: unknown critical failure(s) {sorted(unknown)}\")\n\ndef weighted(scores, weights):\n    return sum(s * w for s, w in zip(scores, weights))\n\ndef cohen_kappa(a, b):\n    \"\"\"Unweighted Cohen's kappa for two graders' labels on the same items.\"\"\"\n    n = len(a)\n    observed = sum(x == y for x, y in zip(a, b)) / n\n    ca, cb = Counter(a), Counter(b)\n    expected = sum(ca[k] * cb[k] for k in set(a) | set(b)) / (n * n)\n    if expected == 1:\n        return 1.0\n    return (observed - expected) / (1 - expected)\n\ndef score_outputs(data):\n    names = list(data[\"rubric\"])\n    weights = [data[\"rubric\"][n][\"weight\"] for n in names]\n    t = data[\"thresholds\"]\n    rows = []\n    print(f\"{'ID':<4} {'A':>5} {'B':>5} {'final':>6}  verdict\")\n    for o in data[\"outputs\"]:\n        a, b = weighted(o[\"A\"], weights), weighted(o[\"B\"], weights)\n        final = (a + b) / 2\n        if o[\"critical\"]:\n            verdict = \"FAIL  critical: \" + \", \".join(o[\"critical\"])\n        elif final >= t[\"pass_score\"]:\n            verdict = \"PASS\"\n        else:\n            verdict = f\"FAIL  below {t['pass_score']:.1f}\"\n        rows.append((o, final, verdict.startswith(\"PASS\")))\n        print(f\"{o['id']:<4} {a:>5.2f} {b:>5.2f} {final:>6.2f}  {verdict}\")\n    return names, rows\n\ndef dimension_report(data, names):\n    t = data[\"thresholds\"]\n    outs = data[\"outputs\"]\n    floor_fails, vague = [], []\n    print(f\"\\n{'dimension':<13} {'weight':>6} {'mean':>5} {'exact':>6} {'within1':>8} {'kappa':>6}  flag\")\n    for i, name in enumerate(names):\n        a = [o[\"A\"][i] for o in outs]\n        b = [o[\"B\"][i] for o in outs]\n        mean = (sum(a) + sum(b)) / (2 * len(outs))\n        exact = sum(x == y for x, y in zip(a, b)) / len(outs)\n        within = sum(abs(x - y) <= 1 for x, y in zip(a, b)) / len(outs)\n        kappa = cohen_kappa(a, b)\n        flags = []\n        if mean < t[\"dimension_floor\"]:\n            flags.append(f\"mean < {t['dimension_floor']}\")\n            floor_fails.append(name)\n        if kappa < t[\"min_kappa\"] or within < t[\"min_within_one\"]:\n            flags.append(\"rewrite anchors\")\n            vague.append(name)\n        print(f\"{name:<13} {data['rubric'][name]['weight']:>6.0%} {mean:>5.2f} \"\n              f\"{exact:>6.0%} {within:>8.0%} {kappa:>6.2f}  {'; '.join(flags) or 'ok'}\")\n    return floor_fails, vague\n\ndef main():\n    data = DATA\n    if len(sys.argv) > 1:\n        with open(sys.argv[1], encoding=\"utf-8\") as f:\n            data = json.load(f)\n    validate(data)\n    names, rows = score_outputs(data)\n    floor_fails, vague = dimension_report(data, names)\n\n    t = data[\"thresholds\"]\n    avg = sum(final for _, final, _ in rows) / len(rows)\n    passed = sum(ok for _, _, ok in rows)\n    criticals = sum(bool(o[\"critical\"]) for o, _, _ in rows)\n    print(f\"\\n{passed}/{len(rows)} outputs pass | average {avg:.2f} | critical failures {criticals}\")\n    for name in vague:\n        print(f\"  anchors too vague to trust: {name} -> \"\n              f\"{data['rubric'][name]['anchors']}\")\n\n    gates = [\n        (f\"average >= {t['pass_score']:.1f}\", avg >= t[\"pass_score\"]),\n        (f\"no dimension mean < {t['dimension_floor']}\", not floor_fails),\n        (\"zero critical failures\", criticals == 0),\n        (\"graders agree on every dimension\", not vague),\n    ]\n    print()\n    for label, ok in gates:\n        print(f\"{'PASS' if ok else 'FAIL'}  {label}\")\n    go = all(ok for _, ok in gates)\n    print(f\"\\nLaunch decision -> {'GO' if go else 'NO-GO'}\")\n    return 0 if go else 1\n\nif __name__ == \"__main__\":\n    sys.exit(main())\n```\n\nRun it against the embedded data:\n\n``` bash\n$ python3 rubric_score.py\nID       A     B  final  verdict\nT01   4.85  5.00   4.92  PASS\nT02   4.10  4.40   4.25  PASS\nT03   3.75  4.05   3.90  FAIL  below 4.0\nT04   4.40  4.10   4.25  PASS\nT05   2.65  2.65   2.65  FAIL  critical: invented_promise\nT06   4.70  4.70   4.70  PASS\nT07   3.40  2.95   3.17  FAIL  below 4.0\nT08   4.85  4.25   4.55  PASS\nT09   4.40  4.70   4.55  PASS\nT10   3.30  3.00   3.15  FAIL  below 4.0\n\ndimension     weight  mean  exact  within1  kappa  flag\nfaithfulness     40%  4.10   100%     100%   1.00  ok\ncompleteness     30%  3.95    90%     100%   0.85  ok\nconcision        15%  3.70    20%      30%  -0.08  rewrite anchors\nformat           15%  4.20   100%     100%   1.00  ok\n\n6/10 outputs pass | average 4.01 | critical failures 1\n  anchors too vague to trust: concision -> {5: 'short and to the point', 3: 'a bit wordy', 1: 'far too long'}\n\nPASS  average >= 4.0\nPASS  no dimension mean < 3.5\nFAIL  zero critical failures\nFAIL  graders agree on every dimension\n\nLaunch decision -> NO-GO\n```\n\nThe script exits 1 on NO-GO, so it can gate a pipeline as-is.\n\n**The per-output table.** Each row shows both graders' weighted scores and their mean. Four outputs fail: three on score, and T05 on a critical failure. T05 is the case that justifies having critical failures at all: its 2.65 would fail on score anyway here, but on a slightly better-written version of the same invented refund, the weighted average alone could have let it through.\n\n**The average gate passes, and that's the trap.** The average is 4.01, just over the 4.0 bar. If the rubric only had a weighted score, this batch would ship. Two other gates stop it: one critical failure, and a dimension the graders can't agree on.\n\n**The agreement columns are the point of the exercise.** For each dimension the script reports:\n\nFaithfulness, Completeness and Format look healthy. Concision does not: the graders matched on 2 of 10 outputs, were more than a point apart on 7 of them, and kappa is slightly negative. That's not a grader problem, it's an anchor problem. \"Short and to the point,\" \"a bit wordy\" and \"far too long\" are three opinions, so each grader brought their own definition of short.\n\nThe 0.6 kappa and 90% within-one cutoffs in `thresholds` are example values for this post, not a standard. Pick yours deliberately and write down why, the same way you would a coverage threshold.\n\nWhen a dimension fails the agreement check, rewrite its anchors in countable terms and re-run the same items. For the fictional summarizer, something like this (the word counts are example numbers; use your UI's real limit):\n\n| Concision | Before | After | \n|---|---|---|\n| 5 | Short and to the point | Under 80 words, no repeated facts, no filler sentence | \n| 3 | A bit wordy | 80-120 words, or one repeated fact, or one filler sentence | \n| 1 | Far too long | Over 120 words, or mostly restates the thread | \n\nNow two graders can check the same output and land on the same number, because the anchor tells them what to count. The loop is the same one you'd use for a flaky test: find the dimension with low agreement, look at the specific items where graders were more than a point apart, rewrite the anchor that caused it, and re-score. Twenty to thirty outputs spanning a range of quality is a reasonable size for this calibration pass; ten is only enough for a demo.\n\nTwo variations worth knowing about. Cohen's kappa treats a 4-vs-5 disagreement the same as a 1-vs-5; a *weighted* kappa gives partial credit for near-misses on an ordinal scale, which is why the script also prints within-one. And with more than two graders you'd reach for a multi-rater statistic instead. Either way, the statistic is a pointer to ambiguous anchors, not the goal itself.\n\nOnce human graders agree, you'll want an LLM judge to score larger samples. The script doesn't care who grader B is. Put your best-calibrated human's scores in `A`, the judge's scores in `B`, and run it on the same items: the per-dimension kappa is now a direct measure of whether the judge applies your rubric the way your team does.\n\nA few rules make judges more consistent and easier to audit:\n\n`DATA[\"rubric\"]` dict so the two can't drift apart.\nKeep humans on threshold-setting and on reviewing anything the judge flags as a critical failure.\n\nThe `thresholds` block exists so the launch bar is committed *before* anyone sees the results. Moving the bar after a disappointing run is the eval equivalent of deleting a failing test. Typical gates (values here are illustrative):\n\nIf you score by slice (long threads, ambiguous threads, adversarial inputs), add a gate that no slice falls more than a set margin below the overall average. Averages hide the slice that's failing.\n\nVersion the rubric alongside the prompt and the golden set. Changing an anchor or a weight mid-comparison makes before-and-after scores meaningless, so bump a version and re-score the baseline instead.\n\nIt can't tell you the dimensions are the right ones, that the weights reflect real user cost, or that a high-agreement rubric is measuring something that matters. Two graders can agree perfectly on a useless criterion. It takes the \"can we even trust these scores?\" question off the table so the review can spend its time on \"are we scoring the right things?\"\n\nWriting anchors from scratch is the slow part. The **LLM Eval Rubrics & Golden Dataset Pack** ($19) has 10 rubrics for common LLM tasks (summarization, RAG Q&A, classification, extraction, support chat, code assist, rewriting and tone, agent task completion, content drafting, and safety), each with weighted dimensions, 1-5 anchors, critical failures and two scored examples. It also includes a Golden Dataset Builder spreadsheet with a rater-agreement tab and a GO/NO-GO check, plus nine LLM-as-judge prompts.\n\n👉 [Get the LLM Eval Rubrics & Golden Dataset Pack](https://mjh4ucorp.gumroad.com/l/llm-eval-rubrics-golden-dataset-pack)\n\n*Disclosure: we make and sell that pack. You don't need it for anything in this article. The script above will score outputs and check agreement on its own.*\n\nIf you're still defining what the feature should do, the rubric's dimensions should come straight from the behavior table in your spec. The free AI Feature PRD Template has that table, every section heading, guidance prompts and a pre-filled failure-mode table.\n\n👉 [Get the free AI Feature PRD Template](https://mjh4ucorp.gumroad.com/l/ai-feature-prd-template-free)\n\nA PM-focused version of this guide first appeared on the [AI Spec Kit Substack](https://aispeckit.substack.com/p/how-to-write-an-llm-evaluation-rubric).\n\nWhich dimension in your current rubric would fail an agreement check first? We'd bet on whatever your version of \"concise\" is, but we'd like to hear yours.\n\n*This article was written with the help of AI tools, then reviewed and edited before publishing.*", "url": "https://wpnews.pro/news/your-llm-eval-rubric-is-a-test-fixture-score-it-and-check-grader-agreement-in", "canonical_source": "https://dev.to/aispeckit/your-llm-eval-rubric-is-a-test-fixture-score-it-and-check-grader-agreement-in-python-2kjb", "published_at": "2026-12-02 16:09:16+00:00", "updated_at": "2026-12-02 16:16:26.887554+00:00", "lang": "en", "topics": ["large-language-models", "ai-tools", "developer-tools", "mlops"], "entities": [], "also_reported_by": [], "takeaway": "Treat the rubric as a versioned test fixture: score three to five weighted, observable-anchor dimensions plus critical failures, then check grader agreement and merge any two dimensions that score the same on nearly every output.", "recommendation": {"advice": "Before trusting eval scores, run your rubric through a grader-agreement check and merge dimensions that score identically across nearly every output.", "playbook": "evals-testing", "playbook_url": "https://wpnews.pro/playbooks/evals-testing"}, "alternates": {"html": "https://wpnews.pro/news/your-llm-eval-rubric-is-a-test-fixture-score-it-and-check-grader-agreement-in", "markdown": "https://wpnews.pro/news/your-llm-eval-rubric-is-a-test-fixture-score-it-and-check-grader-agreement-in.md", "text": "https://wpnews.pro/news/your-llm-eval-rubric-is-a-test-fixture-score-it-and-check-grader-agreement-in.txt", "jsonld": "https://wpnews.pro/news/your-llm-eval-rubric-is-a-test-fixture-score-it-and-check-grader-agreement-in.jsonld"}}