Evals & LLM-as-Judge

How to actually measure an LLM app - evals & the judge

LLM outputs are non-deterministic and rarely have one right answer, so you can't unit-test them the old way. Evals replace vibes with evidence: curated datasets, deterministic and semantic scorers, and an LLM-as-judge that grades free-form text against a rubric - calibrated against humans and wired into CI so quality never silently regresses.

Golden datasets LLM-as-judge Faithfulness CI regression gates
01 - What

What are LLM evals?

An eval is a repeatable measurement of how well an LLM system does a task: run it over a fixed dataset, score each output with one or more graders, and aggregate into metrics you can track over time. Because outputs are open-ended, scoring often blends deterministic checks (exact match, JSON validity) with semantic and LLM-as-judge grading. The goal is the same as any test suite - catch regressions and prove improvements - but adapted to text that has no single correct string.

πŸ—‚οΈ Dataset (the questions)

A curated set of inputs plus optional references or expected behaviors - golden examples, sampled real traffic, and hand-built edge cases.

πŸ“ Scorers (the graders)

Functions that turn an output into a score: deterministic rules, semantic similarity, task-specific metrics, or an LLM judge with a rubric.

πŸ“Š Report (the verdict)

Aggregated metrics per slice, compared to a baseline, so you can see pass rate, faithfulness, and where quality moved up or down.

The core building blocks

PieceWhat it doesCommon choices
Eval datasetFixed inputs (+ references) to run the system againstGolden set, sampled traffic, synthetic edge cases
Deterministic scorerRule-based pass/fail, cheap and exactExact match, regex, JSON.parse, schema valid
Semantic scorerMeasures meaning-level closeness to a referenceEmbedding cosine, BERTScore, ROUGE
Task-specific scorerMetrics tied to the job (esp. RAG)Faithfulness, answer-relevance, context recall
LLM-as-judgeGrades open-ended text with a rubric or referencePairwise, reference-free, reference-based
Key mental model: an eval is a dataset Γ— scorer pair. The dataset decides what you measure; the scorer decides how. Most failures trace back to a weak dataset or an uncalibrated judge - not the model itself.
02 - Why

Why evals exist

You can't ship what you can't measure. LLM behavior shifts with every prompt tweak, model upgrade, or retrieval change - and it changes silently. Evals turn "seems better" into a number, and stop yesterday's fix from becoming tomorrow's regression.

🎲 Handle non-determinism

The same prompt yields different text each run. Evals average over a dataset so you measure a distribution, not one lucky (or unlucky) sample.

🌫️ No single right answer

Many tasks have many acceptable outputs. Rubric-based judging scores quality and correctness properties instead of demanding one exact string.

πŸ›‘οΈ Catch regressions early

A prompt edit that helps one case can break ten others. Running evals in CI blocks the regression before it reaches users.

πŸš€ Ship with confidence

Comparing candidate versions on the same dataset gives a defensible reason to promote one prompt, model, or retriever over another.

In Plain Terms

Evals explained with analogies

Same idea, four ways to picture it, so it clicks whoever you are.

πŸŽ“ For a student

An eval is the graded exam with an answer key and a rubric. You don't judge a single essay by gut feeling; you run every student against the same questions and mark each one against explicit criteria for full, honest credit.

πŸ‘©β€πŸ’» For a developer

It's a test suite for prose. Deterministic checks are your assertions; the LLM-as-judge is a fuzzy matcher for text that has no one correct string. Wire it into CI and a regression fails the build like any broken test.

🏒 For a professional

Think of a QA reviewer with a scorecard. Instead of spot-checking a few calls by vibe, the reviewer samples a representative set and scores each against the same quality standard, so decisions rest on evidence, not anecdotes.

πŸ‘¨β€πŸ³ Everyday version

Like a cooking competition judge with a rubric card: taste, presentation, technique. The rubric keeps every dish scored the same way, so the winner isn't just whoever plated last or served the biggest portion.

03 - How

How evals work under the hood

Evals run in two settings: offline against a curated dataset (before you ship), and online against sampled production traffic (after you ship). Both feed the same scorers; only the source of inputs differs.

πŸ§ͺ Offline eval harness

Take a fixed dataset, run the system under test on every row, score each output, and diff the aggregate metrics against a stored baseline. Deterministic, reproducible, gate-able in CI.

πŸ“‘ Online (production) eval

Sample live traffic, run reference-free judges and heuristics on real outputs, and track metrics on dashboards. Catches drift and edge cases your dataset never anticipated.

The harness architecture at a glance

Architecture - a dataset flows through the system under test into scorers and a report
flowchart LR
    subgraph Data["πŸ—‚οΈ Eval dataset"]
        G["⭐ Golden set"] --> DS[("πŸ“š Cases + refs")]
        T["πŸ“‘ Sampled traffic"] --> DS
        E["🧨 Edge cases"] --> DS
    end
    subgraph Run["πŸ§ͺ Eval harness"]
        DS --> SUT["πŸ€– System under test"]
        SUT --> OUT["πŸ“ Candidate outputs"]
        OUT --> DET["πŸ“ Deterministic scorers"]
        OUT --> SEM["🧬 Semantic scorers"]
        OUT --> JUD["βš–οΈ LLM-as-judge"]
        DET --> AGG["πŸ“Š Aggregate + slice"]
        SEM --> AGG
        JUD --> AGG
    end
    AGG --> REP["πŸ“ˆ Report vs baseline"]
        

A judge rubric prompt (reference-free scoring)

You are a strict grader. Score the ANSWER on each criterion
from 1-5. Judge only what is written. Do NOT reward length.
Return JSON only.

Criteria:
  - faithfulness:  every claim is supported by CONTEXT (no invented facts)
  - relevance:     the answer addresses the QUESTION directly
  - completeness:  no essential part of the question is ignored

CONTEXT:  {{context}}
QUESTION: {{question}}
ANSWER:   {{answer}}

Respond exactly as:
{"faithfulness": n, "relevance": n, "completeness": n,
 "rationale": "one sentence"}

Notice the guardrails: a fixed scale, "do not reward length" to fight verbosity bias, JSON-only output for deterministic parsing, and a forced rationale so scores are auditable. A judge is only trustworthy once its scores are calibrated against human labels.

04 - Sequence Diagrams

Detailed sequence diagrams

Three views: an offline harness run, an LLM-as-judge scoring one output against a rubric, and a CI pipeline that blocks a deploy on regression.

Diagram 1 - Offline eval run: dataset β†’ system under test β†’ scorer β†’ report
sequenceDiagram
    autonumber
    participant Dev as πŸ‘€ Engineer
    participant Harn as πŸ§ͺ Eval harness
    participant DS as πŸ—‚οΈ Dataset
    participant SUT as πŸ€– System under test
    participant Scr as πŸ“ Scorers
    participant Rep as πŸ“ˆ Report

    Dev->>Harn: run eval(suite, baseline)
    Harn->>DS: load cases + references
    DS-->>Harn: N test rows
    loop for each case
        Harn->>SUT: run(input)
        SUT-->>Harn: candidate output
        Harn->>Scr: score(output, reference)
        Scr-->>Harn: metric values
    end
    Harn->>Rep: aggregate + diff vs baseline
    Rep-->>Dev: pass rate, deltas, failures
        
Diagram 2 - LLM-as-judge: grade one candidate against a rubric and reference
sequenceDiagram
    autonumber
    participant Harn as πŸ§ͺ Harness
    participant Prompt as 🧩 Rubric builder
    participant Judge as βš–οΈ Judge LLM
    participant Cal as 🎚️ Calibration
    participant Store as πŸ—„οΈ Results

    Harn->>Prompt: build(question, answer, reference, rubric)
    Prompt-->>Harn: judge prompt
    Harn->>Judge: grade(prompt)
    Judge-->>Harn: scores + rationale (JSON)
    Note over Harn,Judge: swap A/B order to check position bias
    Harn->>Cal: compare to human labels
    alt agreement below threshold
        Cal-->>Harn: recalibrate rubric
    else judge trusted
        Cal-->>Harn: accept scores
    end
    Harn->>Store: persist scores + rationale
        
Diagram 3 - CI gate: run evals on a PR and block deploy on regression
sequenceDiagram
    autonumber
    participant Dev as πŸ‘€ Developer
    participant CI as πŸ” CI pipeline
    participant Harn as πŸ§ͺ Eval harness
    participant Base as πŸ“Š Baseline metrics
    participant Deploy as πŸš€ Deploy

    Dev->>CI: open pull request
    CI->>Harn: run eval suite on PR build
    Harn-->>CI: candidate metrics
    CI->>Base: compare against threshold
    alt metrics regressed
        Base-->>CI: fail (delta below gate)
        CI-->>Dev: block merge + show diff
    else metrics hold or improve
        Base-->>CI: pass
        CI->>Deploy: promote build
        Deploy-->>Dev: shipped
    end
        
05 - Step by Step

The 0 β†’ 100 flow

From "we have no idea if it's good" to a calibrated judge guarding every deploy - the whole journey in order.

00
Define

Pin down what "good" means

Write down the task and the qualities that matter - correctness, faithfulness, tone, safety. Vague goals produce useless evals.

10
Dataset

Build the golden set

Curate representative inputs with expected answers or behaviors. Start small (30–100 hand-checked cases) but make them count.

20
Enrich

Add real traffic & edge cases

Sample production logs for realistic distribution, then hand-craft adversarial and rare cases the golden set misses.

30
Scorers

Pick metrics per case

Use deterministic checks where an exact/JSON answer exists; semantic similarity for paraphrase; a judge for open-ended quality.

40
Rubric

Write the judge rubric

Define explicit criteria and a scoring scale, forbid length rewards, and demand JSON plus a rationale for auditability.

50
Calibrate

Align the judge to humans

Have humans label a slice, then measure judge–human agreement. Tune the rubric until they correlate; otherwise the judge lies.

60
Debias

Neutralize known biases

Swap A/B order to counter position bias, cap or normalize length, and avoid self-preference by judging with a different model family.

70
Baseline

Run & record the current system

Execute the full suite to get baseline metrics per slice. This frozen snapshot is what every future change is measured against.

80
Gate

Wire evals into CI

Run the suite on every PR and fail the build when key metrics drop below the baseline threshold - a hard regression gate.

90
Monitor

Add online production evals

Sample live outputs, run reference-free judges and heuristics, and dashboard the trends to catch drift the offline set can't.

100
Iterate

Feed failures back in

Promote real failures into the dataset, refine rubrics, and re-baseline. The eval suite compounds in value with every cycle.

Common Pitfalls

Pitfalls & anti-patterns

Most eval failures come from the dataset and the judge, not the model under test. These are the usual culprits.

πŸ”¬ Tiny, unrepresentative set

Ten cherry-picked cases don't cover real traffic. A high pass rate on a toy set proves nothing; the failures you never sampled are exactly the ones that ship to users.

🎭 Judge bias

Judges quietly favor the first option (position), the longer answer (verbosity), and outputs from their own model family (self-preference). Unswapped, un-normalized judging bakes those biases straight into your scores.

🎚️ Uncalibrated judge

A judge nobody checked against humans is a random number generator with a rationale. Without measured judge-human agreement, you don't know whether a "4/5" means anything at all.

🎯 Gaming a single metric

Optimizing one aggregate number invites Goodhart's law: the system learns to win the metric while real quality slips. One score hides regressions in every slice it averages over.

πŸ’§ Data leakage

When eval cases leak into the prompt, few-shot examples, or fine-tuning data, the system is graded on answers it already saw. Scores soar and generalization is an illusion.

πŸ•°οΈ Frozen eval set

An eval that never absorbs new failure modes slowly stops measuring reality. If production surprises never flow back into the dataset, the suite guards yesterday's bugs and misses today's.

How to Measure

How to measure eval quality

Your eval suite is itself a system that needs measuring. These signals tell you whether to trust its verdicts.

MetricWhat it tells youGood sign
Judge-human agreementHow closely the judge tracks human labels (correlation / kappa)High: judge scores can be trusted
Failure-mode coverageWhat share of known failure types the dataset actually exercisesHigh: few blind spots left
Pass rate / score distributionThe shape of results, not just the mean, across slicesHealthy spread, no hidden cliffs
Variance across runsHow much the same input's score wobbles between runsLow: results are stable and reproducible
Regression catch rateFraction of real regressions the suite blocks before releaseHigh: the gate actually protects users
Eval cost & runtimeToken spend and wall-clock time to run the full suiteCheap and fast enough to run every PR
Rule of thumb: calibrate the judge before you trust any score. If judge-human agreement is low, fix the rubric first; a suite built on an uncalibrated judge measures noise no matter how many cases it runs.
06 - Case Studies

Real-world case studies

Three representative patterns showing evals and LLM-as-judge in production-style use.

πŸ”—

1 Β· RAG faithfulness & groundedness evaluation

Pattern: reference-free judge over retrieved context

A team ships a RAG assistant and needs proof that answers stay grounded in the retrieved passages instead of inventing facts.

  • For each answer, a judge checks every claim against the retrieved context and scores faithfulness plus answer-relevance.
  • Context recall is measured separately so a hallucination isn't confused with a retrieval miss.
  • The judge is calibrated against human groundedness labels before its scores gate releases.
βœ… Outcome: Ungrounded answers are caught automatically, and the team can attribute failures to either retrieval or generation instead of guessing.
πŸ’¬

2 Β· Chatbot quality regression suite

Pattern: offline suite as a CI gate

A support chatbot is edited constantly - new prompts, new tools, new model versions - and each change risks silently breaking prior behavior.

  • A golden set of past conversations plus mined failures runs on every pull request.
  • Deterministic checks verify structure and refusals; a rubric judge scores helpfulness and tone.
  • The CI job fails the merge if any key metric drops below its baseline threshold.
βœ… Outcome: Regressions are blocked before merge, so a fix for one intent can no longer quietly degrade ten others in production.
βš”οΈ

3 Β· Pairwise judge ranking of two prompt versions

Pattern: A/B comparison with bias controls

An engineer has two candidate system prompts and needs a defensible answer to "which one is actually better?"

  • Both prompts run on the same dataset; a judge picks the better output pairwise per case.
  • Each pair is judged twice with the order swapped to cancel position bias, and length is normalized.
  • Win rate with confidence intervals decides the promotion - not a handful of cherry-picked chats.
βœ… Outcome: The winning prompt is chosen on a statistically honest win rate, and the debiasing steps keep the judge from favoring the longer or first answer.
07 - Future

Where evals are heading

Evals are moving from occasional spreadsheets to continuous, automated infrastructure that sits at the center of every LLM product.

πŸ€– Agentic & trajectory evals

Scoring not just final answers but the whole tool-using trajectory - did the agent take the right steps, call the right tools, and recover from errors?

🎚️ Auto-calibrated judges

Judges that continuously fit themselves to fresh human labels, reporting their own agreement so you know exactly how far to trust them.

🧬 Synthetic dataset generation

Models that generate targeted edge cases and adversarial inputs to grow coverage far beyond what humans can curate by hand.

βš–οΈ Bias-aware judging by default

Position, verbosity, and self-preference controls baked into judge frameworks - swapped orders, length normalization, cross-family graders.

πŸ“‘ Online evals as observability

Reference-free scoring on live traffic becomes standard telemetry, catching drift the moment it appears rather than at the next release.

πŸ›‘οΈ Safety & policy evals

Dedicated suites for jailbreaks, toxicity, PII leakage, and policy compliance shipping alongside quality metrics as a release requirement.

Bottom line: evals are the test suite of the LLM era. A curated dataset paired with calibrated, debiased scorers - run in CI and in production - is what turns an unpredictable model into a product you can ship and improve with confidence.