Evaluation & AI Quality Engineering
Create representative datasets, layered metrics, calibrated judges, agent trajectory evals, red teaming, regression gates, and production feedback loops.
Learning objectives
By the end of this chapter, you should be able to:
- Translate product value and failure consequences into component, end-to-end, safety, and operational quality criteria — and into an explicit release decision.
- Build a versioned, representative golden set with provenance, grouped splits, and contamination controls, and explain why public benchmark scores overstate capability on your task.
- Apply the RAG triad and a layered evaluation pyramid: deterministic checks first, calibrated LLM judges for semantics, humans for ground truth and high-risk ambiguity.
- Evaluate agents on terminal state, step correctness, tool-call accuracy, trajectory efficiency, and
pass^kreliability — not just final prose. - Name and mitigate LLM-judge failure modes: position bias, verbosity bias, self-preference, and judge-targeted prompt injection.
- Design CI release gates, a red-team program, and online experiments (shadow, interleaving, canary with guardrail metrics) that fail closed.
- Compare open-source and managed evaluation tooling on AWS and GCP, and run an eval-driven development loop your team actually follows.
1. Quality is a decision system, not a score
An evaluation system exists to make decisions: continue iterating, merge a change, canary it, expand rollout, roll back, investigate a slice, or escalate a risk. Start by writing the decision and the consequence of a false pass or false fail. Only then choose metrics and thresholds. A single “quality score” cannot represent correctness, evidence use, safety, latency, cost, and user value without hiding important trade-offs.
flowchart TD
P["Product outcome"] --> E["End-to-end task success"]
P --> C["Component quality (retrieve / generate / tools)"]
P --> I["Hard invariants (auth / schema / policy / citations)"]
P --> G["Operations (latency / cost / errors / recovery)"]
E --> D["Release decision: ship / canary / hold / rollback"]
C --> D
I -->|"any failure blocks"| D
G -->|"guardrails"| D
Build a quality tree
For an enterprise policy assistant, the top outcome might be “authorized users resolve policy questions accurately and quickly.” Decompose it into: relevant current evidence retrieved; answer claims supported; citations resolvable; uncertainty handled; unauthorized information never disclosed; correct escalation on ambiguous or high-risk questions; and acceptable latency/cost. Attach at least one measure and one failure example to each leaf.
| Criterion | Measure | Decision role |
|---|---|---|
| Required evidence is present | Recall@k / evidence coverage | Diagnose retriever and packer |
| Claims follow evidence | Human or calibrated claim-level faithfulness | Generation quality gate |
| Answer resolves task | Task-specific rubric / execution success | End-to-end comparison |
| Tenant boundary holds | Deterministic adversarial test | Non-negotiable release blocker |
| User experience is timely | p50/p95/p99 end-to-end and stage latency | Guardrail / capacity decision |
| Economics are viable | Cost and tokens per successful task | Route/rollout decision |
2. Engineer the dataset before the evaluator
A golden set is a versioned collection of inputs, expected properties, metadata, and judgments. “Golden” means reviewed, traceable, and stable enough for comparison — not perfect or frozen. Every serious platform (LangSmith, Langfuse, Vertex AI, Bedrock) is organized around this object; if your dataset is an untracked spreadsheet, no tool downstream can save you.
Four complementary sources
- Curated core: expert-written canonical and boundary cases.
- Production traces: privacy-reviewed samples of common, failed, costly, uncertain, and novel interactions.
- Adversarial cases: injection, leakage, malformed input, unavailable tools, contradictory sources, and no-answer examples.
- Synthetic expansion: reviewed, provenance-labeled paraphrases or rare combinations; a supplement, never proof of representativeness.
Each record should include a stable ID, input, reference evidence or expected behavior, rubric, risk, source/provenance, created/reviewed dates, language, tenant/data class, intent, difficulty, and applicable evaluators. Preserve an immutable raw trace reference separately when allowed. Redact or synthesize sensitive values before placing cases in developer-visible stores. Split by how data can leak: group by source document, user/thread, template, or time so near-duplicates never cross development, validation, and sequestered test splits. Repeated optimization makes validation data de facto training data; preserve a final untouched set. Version everything that changes meaning — dataset, judgments, rubrics, corpus/parser/retrieval, prompt/model/tools, evaluators, sampling, environment — with hashes and a changelog. A score without dataset and evaluator versions is not reproducible evidence.
Benchmark contamination: why public leaderboards mislead
Public benchmarks (MMLU, HumanEval, GSM8K and successors) circulate on the open web, which means they leak into pretraining corpora. The GSM1k study (arXiv:2405.00332) rebuilt grade-school math problems of matched difficulty from scratch and found some model families dropped by double-digit accuracy points versus their GSM8K scores — evidence of memorization, not reasoning. For an interview, the takeaway is a posture: treat vendor benchmark claims as marketing until reproduced on your task distribution, and treat any public test set as presumptively contaminated.
- Private, post-cutoff data — author fresh cases from your own domain; prefer material created after the model's training cutoff.
- Canary strings — embed unique GUIDs (the BIG-bench convention) in eval files so future contamination is detectable.
- Overlap checks — run n-gram and embedding-similarity dedup between eval items and any corpus you fine-tune on.
- Rotation — refresh sequestered sets on a schedule; retire items once they have influenced many decisions.
3. The evaluation pyramid and the RAG triad
Component scores localize defects; end-to-end scores reveal interactions. Retrieval recall can rise while excess context harms answers; correct tool selection can still carry invalid arguments. Layer evaluators by cost and coverage: cheap deterministic checks run on everything, calibrated model judges on samples, expert humans on a small stratified slice that continuously re-anchors the judges.
flowchart TD
A["Every output: deterministic checks (schema, citations, execution, policy)"] --> B["Every experiment: component metrics (recall@k, nDCG, tool accuracy)"]
B --> C["Sampled: calibrated LLM judges (faithfulness, relevance, rubric scores)"]
C --> D["Small stratified sample: expert human review + adjudication"]
D -->|"labels recalibrate judges"| C
D -->|"new cases join the golden set"| A
The RAG triad, by name
The industry-standard decomposition (popularized by TruLens and mirrored in Ragas, Vertex, and Bedrock metric catalogs) scores three edges of the query–context–answer triangle. Use the names — interviewers listen for them — but always state the rubric behind each, because tools define them differently.
| Triad edge | Question it answers | Typical failure it isolates |
|---|---|---|
| Context relevance (query ↔ context) | Is the retrieved evidence actually about the question? | Retriever/ranker pulls plausible but off-topic chunks |
| Faithfulness / groundedness (context ↔ answer) | Is every material claim supported by the supplied evidence? | Generation hallucinates beyond or against the context |
| Answer relevance (query ↔ answer) | Does the response address the user's actual request? | Faithful summary of evidence that dodges the question |
Faithfulness and correctness differ: an answer can repeat stale evidence faithfully, or be correct yet unsupported. Evaluate both, plus completeness and citation correctness separately — a faithful answer can still omit the decisive policy exception. Complement the triad with retrieval-stage metrics (precision@k, recall@k, MRR, nDCG, evidence coverage after packing) and answer-stage checks (instruction adherence, appropriate abstention). Chapter 4 covers the retrieval mechanics; here your job is choosing which edge a metric belongs to so a regression routes to the right owner.
Deterministic output checks first
Use exact match for known classifications, JSON Schema for structure, parsers/compilers for code or queries, executable tests for calculations, database comparisons for extraction, and policy engines for allowed actions. A deterministic checker is cheaper, faster, repeatable, and easier to debug than a model judge whenever the property is mechanically decidable. Reaching for an LLM judge to validate JSON is a junior tell.
4. Agent evaluation: trajectories, tools, and pass^k
Agents (chapter 5) break response-only evaluation because quality lives in a trajectory of decisions with real side effects. Grade three distinct things and keep them separate: did the world end in the correct state (task completion), were the individual decisions right (step correctness), and was the path economical (trajectory efficiency). An agent can reach the right terminal state through a wasteful or policy-violating path, and it can execute every step plausibly while never finishing the job.
flowchart LR
T["Task instance"] --> R["Agent run: plan, tool calls, observations"]
R --> F["Final-state check: is the environment state correct"]
R --> S["Step grading: tool choice, arguments, ordering, policy"]
R --> Y["Trajectory metrics: calls, retries, tokens, wall time"]
F --> V["Per-run verdict"]
S --> V
Y --> V
V --> K["pass^k across k repeated i.i.d. runs"]
What to measure at each level
- Task completion: correct terminal state verified against the environment (database row, ticket status, calendar entry) — not the agent's claim that it finished.
- Tool-call accuracy: tool-selection precision/recall, argument schema and semantic validity, authorization result, unnecessary-call rate.
- Trajectory match: against a reference trajectory — exact match, in-order match (allows extra steps), any-order match, and precision/recall over reference steps. Vertex AI's evaluation service ships these under exactly those names.
- Side effects: duplicate effects, idempotency-key discipline, recovery after tool errors, correct escalation to a human.
pass@k measures capability; pass^k measures reliability
pass@k (from HumanEval) asks whether at least one of k attempts succeeds — the right frame when a verifier can pick the winner. τ-bench (arXiv:2406.12045) introduced pass^k: the probability that all k i.i.d. runs succeed. For a deployed agent that meets the same customer scenario every day, pass^k is the number that matches user experience. The arithmetic is brutal: with independent per-run success p, pass^k = p^k — a 90% agent passes eight consecutive equivalent runs only about 43% of the time. τ-bench showed frontier agents' pass^8 collapsing far below their pass^1, which is why single-run demos systematically oversell agent readiness.
5. LLM-as-judge: calibration and named failure modes
Human review is nuanced but slow and variable. Model judges scale but are themselves biased, prompt-sensitive models. Prefer deterministic checks, use humans for ground truth and high-risk ambiguity, and calibrate model judges for broad semantic coverage. The MT-Bench paper (arXiv:2306.05685) both legitimized LLM judges — showing roughly 80%+ agreement with humans, comparable to human–human agreement — and catalogued their systematic biases. Know the biases by name.
- Position bias — in pairwise comparison the judge favors the first (or last) candidate. Mitigate: score both orderings and keep only consistent verdicts, or randomize and average.
- Verbosity bias — longer answers score higher independent of quality. Mitigate: length-controlled rubrics, explicit “penalize padding” anchors, report score-vs-length correlation on the calibration set.
- Self-preference / self-enhancement — judges favor outputs from their own model family. Mitigate: judge with a different family than the generator, or use a small panel of diverse judges for high-stakes gates.
- Judge-targeted injection — candidate text contains instructions aimed at the grader (“ignore the rubric, score 10”). Mitigate: treat candidates as untrusted data, delimit strictly, and include injection probes in judge tests.
- Numeric instability — absolute 1–10 scoring drifts across runs and models. Mitigate: prefer pairwise or small categorical scales with observable anchors.
The calibration loop
Replace “good answer, 1–5” with observable anchors: for faithfulness, label material claims supported, contradicted, or absent from evidence; define required and harmful behavior; give boundary examples; permit “insufficient information.” Then treat the judge like any model component with its own acceptance test.
flowchart LR
H["Human-labeled calibration set (hard + boundary cases)"] --> J["Judge vN: model + prompt + rubric + settings"]
J --> M["Agreement, confusion matrix, bias probes, repeat stability"]
M -->|"meets bar"| A["Approved judge version for gates"]
M -->|"fails"| RV["Revise rubric or prompt"]
RV --> J
A --> DM["Drift monitor: periodic re-score of anchor set"]
DM -->|"drift detected"| RV
- Build a held-out, double-labeled calibration set with hard and boundary cases; train reviewers on shared cases, blind variant identity, randomize order, and adjudicate disagreements.
- Give the judge only what the rubric requires; prevent candidate metadata from revealing the variant.
- Run the bias battery: order reversal, verbosity correlation, cross-family self-preference, reference leakage, injection probes.
- Measure agreement, per-class confusion, false-pass rate on high-risk cases, and stability across repeated runs.
- Version judge model, prompt, settings, rubric, and calibration result; recalibrate after any change, including provider snapshot updates.
Do not let the judge's explanation substitute for correctness — store reasoning as debugging material, not proof. If a judge is weak on a critical slice, route that slice to a deterministic check or human review. For release gates, weight the false-pass cost: an evaluator that misses unsafe behavior is worse than one that occasionally sends a safe run for review.
6. Turn failures into an error taxonomy
Aggregate scores show population movement; error analysis chooses the repair. Give each failure a primary stage, symptom, likely cause, consequence, and owner. Secondary tags can capture interactions.
| Primary stage | Example failure | Likely owner or experiment |
|---|---|---|
| Data/parse | Table row or policy exception lost | Parser/chunking fixture and reprocessing |
| Retrieval | Relevant evidence absent from candidates | Embedding, sparse route, filters, ANN depth |
| Ranking/packing | Evidence found then dropped or truncated | Fusion, reranker, dedupe, token allocation |
| Generation | Unsupported claim despite sufficient evidence | Prompt/model/grounding control |
| Tool/control | Wrong tool, invalid argument, repeated effect | Schema, policy, state machine, idempotency |
| Safety/privacy | Injection obeyed or cross-tenant disclosure | Authorization boundary and incident response |
| Operations | Timeout, cost cap, stale version, failed fallback | Budgets, capacity, recovery, routing |
| Evaluation | Label/rubric/judge is wrong | Adjudication and evaluator recalibration |
Slice before celebrating, and inspect paired deltas
Choose slices from risk and plausible causes: intent, language, policy regime, tenant/data class, document type, exact identifier, multi-hop, no-answer, tool, route, cohort, and age. Report counts and uncertainty; define critical slices before the experiment. Then list paired improvements and regressions per case: equal means can hide replacing harmless style errors with one security failure. Inspect the largest negative deltas and every invariant violation; track severity and consequence.
7. Release gates that tolerate variability, not regressions
CI compares immutable baseline and candidate configurations on a pinned dataset/evaluator suite. Record environment and inspectable responses when policy permits. Invalidate caches for every changed prompt, model, retrieval, or tool dimension.
flowchart LR
CH["Change: prompt, model, retrieval, or tool"] --> SM["Smoke suite: fast, includes all high-risk cases"]
SM --> INV["Hard invariants: 100% required"]
INV -->|"any failure"| BL["Block + per-case diff report"]
INV --> RG["Paired regression vs pinned baseline + critical slices"]
RG -->|"delta beyond budget"| BL
RG --> GD["Guardrails: p95 latency, cost per success"]
GD -->|"breach"| BL
GD --> CN["Shadow, then canary"]
CN -->|"gates hold 48h"| RP["Ramp"]
def release_decision(base, candidate):
hard_fail = any(candidate[name] != 1.0 for name in (
"tenant_isolation", "schema_valid", "no_duplicate_effect"
))
quality_drop = candidate["task_success"] < base["task_success"] - 0.02
slow = candidate["p95_ms"] > 1.10 * base["p95_ms"]
costly = candidate["cost_per_success"] > 1.15 * base["cost_per_success"]
return "block" if hard_fail or quality_drop or slow or costly else "canary"
# Thresholds above are illustrative; derive real gates from product risk.
Hard invariants require every applicable case to pass. Comparative metrics need both absolute floors and allowable deltas. Critical slices need their own gates. Cost and latency are guardrails. Treat missing evaluator output as a failure or explicit “inconclusive,” never as a pass. Keep a small smoke suite on every change and a larger suite on scheduled runs or release candidates, while ensuring high-risk cases remain in the fast gate.
Account for stochastic and sampling uncertainty: use paired comparisons and report intervals via paired bootstrap; inspect discordant binary outcomes; repeat a stratified subset to estimate run-to-run variance. Never average away safety failures, and weigh practical — not only statistical — significance.
8. Online experimentation and the offline–online loop
Offline datasets provide controlled repeatability; production provides distribution reality. Instrument traces with application, prompt, model, retrieval, tool, evaluator, and release versions plus safe outcome metadata. Sample common traffic randomly for prevalence, and oversample rare/high-risk signals for discovery — but keep the weighting explicit: a risk-enriched review queue cannot estimate population quality without correcting its sampling design.
flowchart LR
DS["Versioned golden set"] --> OF["Offline experiment"]
OF --> CI["CI release gate"]
CI --> SH["Shadow / interleave / canary"]
SH --> PR["Production traffic"]
PR --> TR["Traces + online scores + user signals"]
TR --> SP["Random + risk-weighted sampling"]
SP --> AJ["Human adjudication"]
AJ --> DS
Experiment designs that fit GenAI
Classic A/B testing works but is sample-hungry, and GenAI quality deltas are often small relative to outcome noise. Two adaptations matter. First, interleaving: at the retrieval/ranking layer, blend results from two rankers in the same session (team-draft interleaving) and score which side earns the click or citation — within-session comparison removes between-user variance and reaches significance with a fraction of the traffic. For full generations, the analogue is paired preference: run both variants on the same prompt (one served, one shadowed) and collect judge or human preferences on the pairs. Second, guardrail metrics as stop rules: predefine p95 latency, cost per session, refusal rate, safety-flag rate, thumbs-down rate, and escalation-to-human rate with automatic stop thresholds, monitored sequentially — you are not waiting for the primary metric to go wrong before pulling an unsafe variant. Randomize by user or session, never by request, to avoid within-user contamination and inconsistent experiences.
- ShadowRun the candidate on mirrored traffic with no user exposure; diff outputs, latency, and cost offline.
- Interleave / paired preferenceWithin-session comparison at the ranking layer, or judged preference on shadowed generation pairs.
- Canary 5%Real exposure gated on guardrail metrics with automatic stop rules and a rollback owner.
- RampPromote when primary and guardrail gates hold for a predefined window; keep the holdback for measurement.
Production signals are evidence, not ground truth. Feedback, completion, abandonment, reformulation, escalation, citation clicks, and corrections are each confounded: clicks reflect position; silence may mean abandonment or satisfaction. Calibrate proxies against reviewed traces before trusting them in a decision, and never expose an unsafe variant merely to gain statistical power.
9. Red teaming and adversarial evaluation
Safety testing is a program, not a checklist pass. Build adversarial cases from actual input surfaces — user text, retrieval, tools, files, connectors, memory, tenant data — using the OWASP GenAI LLM Top 10 as the threat catalog and the NIST Generative AI Profile to structure governance, then translate both into system-specific executable tests.
Test the full threat path
- Prompt injection: direct user instructions and indirect instructions embedded in retrieved pages, documents, tool output, or memory.
- Sensitive information: secrets, PII, hidden prompts, credentials, and private records requested directly or inferred through side channels.
- Tenant isolation: IDs from another tenant, mixed-index candidates, cached responses, trace views, and shared memory.
- Unsafe tool use: unauthorized tool, excessive scope, altered action after approval, malicious URL/arguments, duplicate effect, ambiguous timeout.
- Policy behavior: refusal consistency, over-refusal on benign requests, safe alternatives, correct human escalation.
- Robustness: malformed encoding, extreme length, empty/contradictory evidence, unavailable dependencies, partial streaming.
Measure attack success rate (ASR) per surface, sensitive-data disclosure, unauthorized-action rate, false refusal, escalation precision/recall, time to detection, and recovery behavior. Automated red teaming — attacker LLMs mutating seed attacks, tools like promptfoo's red-team mode or Bedrock Guardrails test suites — expands coverage cheaply, but manually validate what the generator missed, and keep a sequestered attack pool so defenses are not tuned to the public probes. Every successful attack becomes a permanent regression case: the red team feeds the golden set. Hard security boundaries must be enforced deterministically outside the model and pass every applicable test — chapter 11 covers the runtime enforcement side.
Protect the evaluation system itself. Datasets and traces contain your most revealing failures: apply minimization, access control, encryption, retention/deletion, tenant partitioning, and audit. Treat candidate text as untrusted judge input; sandbox code evaluators with minimal permissions; send production content to external eval services only under an approved data contract.
10. Tooling landscape and eval-driven development
Choose tools by data model and exit path, not dashboards: can it represent your datasets, ground truth, evaluator provenance, versions, and CI integration — and can you export everything if you leave? Keep manifests and deterministic evaluators portable regardless of platform.
| Open-source tool | Center of gravity | Questions before adopting |
|---|---|---|
| Ragas | RAG triad + agent metric library | Do its judge prompts and definitions correlate with your domain humans? |
| promptfoo | Config-driven CI evals + automated red teaming | Does declarative YAML cover your trace-level assertions? |
| DeepEval | pytest-style unit tests for LLM outputs | Who calibrates the built-in judges against your labels? |
| Arize Phoenix | OTel-native tracing + eval on traces, self-hostable | Does your OpenTelemetry convention match its semantics? |
| Langfuse | Traces, datasets, scores, annotation queues; self-host option | Deployment operations, retention, export, feature parity across versions? |
| LangSmith | Datasets, experiments, human/code/model/pairwise evaluators | Framework coupling, hosting/data policy, cost at trace volume? |
AWS
- Bedrock Evaluationsmodel + RAG evaluation jobs; LLM-as-judge and human workflows
- SageMaker Clarify / fmevalfoundation-model evaluation, bias and toxicity checks
- Bedrock Guardrailsonline policy enforcement + grounding checks the evals must mirror
- CloudWatchguardrail metrics, canary alarms, rollback triggers
Google Cloud
- Vertex AI Gen AI evaluation servicepointwise/pairwise judges, RAG and agent trajectory metrics
- Vertex AI Experimentsrun/version comparison and lineage
- Model Armorinjection screening the adversarial suite should exercise
- BigQuery + Cloud Monitoringtrace analytics, slice dashboards, stop-rule alerts
Custom Python + pytest
Maximum transparency and exact product contracts; you build dataset UI, annotation, and trace joins yourself. Right for hard invariants and small teams with strong opinions.
OSS library + observability platform
Ragas/DeepEval metrics over Phoenix or Langfuse traces; self-hostable for data-residency constraints. Right when you need trace-level evals and control the stack.
Managed cloud service
Bedrock Evaluations or Vertex eval service; lowest setup cost, native IAM and data governance, judge models on tap. Right when the workload already lives on that cloud and export paths are verified.
Eval-driven development as a culture
The highest-leverage practice is procedural, not technical: write the eval before the fix. A reported failure becomes a reproducing case (plus a neighborhood of variants) before anyone touches the prompt; the change merges only when the new cases pass and the gate holds. Complement that with: no prompt/model change without an experiment link in the PR; domain experts — not only engineers — own rubrics; a weekly error-analysis review that walks new taxonomy entries; and an explicit eval compute budget (teams commonly spend a meaningful fraction of inference spend on evaluation — treat it as an engineering line item, not overhead; exact ratios are product-specific). One current-events note: as checked on 2026-08-04, OpenAI's docs schedule the legacy Evals platform for read-only status in late 2026 in favor of Datasets — a reminder not to design a durable eval program around any surface with a published retirement date.
Interview playbook
Use QUALITY to answer an evaluation-system design prompt:
- Q — Question and consequence: Which release/product decision, and what does a false pass cost?
- U — User distribution: traffic, important slices, risks, and no-answer/edge behavior.
- A — Artifacts and annotations: dataset sources, provenance, rubric, splits, versions, contamination controls, privacy.
- L — Layers of measures: deterministic, component (RAG triad, tool accuracy), end-to-end, human, calibrated judge, safety, operations.
- I — Inspect errors: paired deltas, taxonomy, severity, slices, uncertainty, and evaluator failures.
- T — Threshold and trial: hard invariants, regression gates, shadow/interleave/canary with guardrail stop rules, rollback.
- Y — Yield feedback: production sampling, adjudication, new cases, red-team regressions, ownership, change cadence.
Common traps
- Choosing metrics before defining the product decision and failure cost.
- Using one aggregate judge score with no rubric, calibration, bias battery, or slice analysis.
- Quoting public benchmark scores as evidence of task fitness — contamination makes them upper bounds at best.
- Grading agents on final prose while ignoring terminal state, side effects, and
pass^kreliability. - Calling synthetic questions representative without validation against production.
- Tuning prompt, threshold, and evaluator on the same test set and reporting it as generalization.
- Allowing quality gains to compensate mathematically for security or privacy violations.
- Treating user feedback, clicks, or judge explanations as uncontested ground truth.
- Building dashboards without an owner, alert/action threshold, or rollback path.
Question bank
These questions test whether evaluation evidence can support a production release decision.
Q1How do you define “good” for a RAG assistant?
Strong answer outline
- Start from user task and failure consequences; write the release decision first.
- Decompose into the RAG triad (context relevance, faithfulness, answer relevance) plus retrieval metrics, citations, abstention, safety, latency, cost.
- Mark objectives, guardrails, and hard invariants separately.
Follow-up probes
- Can a faithful answer be wrong?
- Which single metric blocks release?
Pass if quality is a decision-linked hierarchy with named triad edges; fail if “accuracy and helpfulness” are the only criteria.
Q2How would you build a representative golden set?
Strong answer outline
- Combine curated core, privacy-reviewed production traces, adversarial cases, and reviewed synthetic expansion.
- Annotate provenance, risk, slices, evidence, rubric, and expected behavior.
- Group splits to prevent near-duplicate/source leakage; version the manifest with hashes.
Follow-up probes
- How do you find rare failures?
- When is a case removed versus quarantined?
Pass if distribution, leakage, provenance, and maintenance are explicit; fail if size is the main quality claim.
Q3Explain the RAG triad and how it localizes failures.
Strong answer outline
- Context relevance scores query↔context; faithfulness scores context↔answer; answer relevance scores query↔answer.
- Each edge isolates a different owner: retriever/ranker, generation grounding, or instruction following.
- Add completeness and citation correctness separately; use fixed-context experiments to isolate generation from retrieval.
Follow-up probes
- Can all three edges score high while the answer is still wrong?
- Where does staleness show up in the triad?
Pass if each edge routes to a distinct repair; fail if one blended “RAG score” is used.
Q4When should you use an LLM as a judge, and when not?
Strong answer outline
- Use for semantic/subjective criteria not cheaply decidable in code, at a scale humans cannot cover.
- Never for mechanically decidable properties (schema, citations resolving, policy) — deterministic checks are cheaper and exact.
- Always with an anchored rubric, calibration against human labels, and a bias battery.
Follow-up probes
- Why is pairwise often more stable than absolute scoring?
- How do you detect judge drift after a provider snapshot change?
Pass if judge error is measured and governed; fail if a strong model is assumed objective.
Q5Name the known LLM-judge biases and your mitigations.
Strong answer outline
- Position bias: swap candidate order, keep only consistent verdicts.
- Verbosity bias: length-controlled rubrics; monitor score-length correlation on the calibration set.
- Self-preference: judge from a different model family, or a diverse judge panel for high-stakes gates.
- Judge-targeted injection: treat candidates as untrusted data and include injection probes in judge tests.
Follow-up probes
- Which bias did MT-Bench document, and how large was human–judge agreement?
- What is your acceptance bar for approving a judge version?
Pass if biases are named with concrete mitigations and a calibration loop; fail if “we use GPT-x as judge” ends the answer.
Q6Why can an aggregate improvement be unsafe to ship?
Strong answer outline
- Averages weight severity and slices poorly and can hide invariant violations.
- Inspect paired regressions, critical slice gates, and the error taxonomy.
- Give a concrete case such as cross-tenant leakage or strict-filter recall loss behind a rising mean.
Follow-up probes
- How do you choose critical slices in advance?
- What if a critical slice has only 15 cases?
Pass if counts, severity, and uncertainty constrain the decision; fail if slicing is retrospective cherry-picking.
Q7Design a CI gate for a prompt or model change.
Strong answer outline
- Pin baseline/candidate, dataset, corpus, evaluators, versions, and environment.
- Run hard invariants at 100%, overall and critical-slice floors, paired deltas, and latency/cost guardrails.
- Fail closed on missing critical results; publish per-case diffs; canary only after passing.
Follow-up probes
- How do you keep CI affordable at hundreds of cases per run?
- How do you handle flaky judge verdicts?
Pass if reproducibility, diagnostics, and rollout follow the score; fail if one average threshold merges all risks.
Q8How do you account for non-determinism, and what is pass^k?
Strong answer outline
- Paired cases, pinned versions/settings; estimate repeat variance on a stratified subset; report intervals, not points.
- pass@k measures capability (any of k succeeds); pass^k measures reliability (all k succeed) — for agents facing the same scenario repeatedly, pass^k matches user experience.
- With per-run success p, pass^k = p^k: a 90% agent passes 8 consecutive runs ~43% of the time — quantify before shipping.
Follow-up probes
- Should you retry a failed eval case?
- What breaks the i.i.d. assumption behind p^k?
Pass if uncertainty and reliability change the decision procedure; fail if rerunning until green is acceptable.
Q9How do evaluation-set leakage and benchmark contamination differ, and how do you defend against each?
Strong answer outline
- Internal leakage: near-duplicates crossing splits or repeated tuning against validation — defend with grouped splits, sequestered sets, and access control.
- Benchmark contamination: public test data in pretraining corpora inflates scores (GSM1k showed double-digit drops on fresh equivalents for some models).
- Defend with private post-cutoff data, canary strings, overlap checks, and rotation; treat vendor benchmark claims as upper bounds.
Follow-up probes
- Can synthetic paraphrases cross splits?
- How would you test whether a model has memorized your eval set?
Pass if both mechanisms have distinct, concrete defenses; fail if random row splitting is assumed sufficient.
Q10How would you evaluate a tool-using agent?
Strong answer outline
- Grade three layers separately: terminal state verified against the environment, step correctness (tool selection precision/recall, argument validity, authorization), and trajectory efficiency (calls, retries, tokens, wall time).
- Use trajectory-match metrics (exact, in-order, any-order, precision/recall) against reference trajectories where they exist.
- Inject tool errors, ambiguous writes, approval changes, and malicious tool results; check side effects, idempotency, recovery, escalation; report pass^k.
Follow-up probes
- Can two different trajectories both pass?
- How do you grade a partial success with a harmful side effect?
Pass if trace and system effects matter beyond final prose; fail if answer relevance is the primary agent metric.
Q11What is a useful error taxonomy for RAG?
Strong answer outline
- Separate parse/data, retrieval, rank/pack, generation, citation, tool/control, safety, operations, and evaluator errors.
- Assign primary cause, severity, slice, and owner; secondary tags for interactions.
- Review taxonomy coverage and merge/split labels only when actionability improves.
Follow-up probes
- What if multiple stages contribute to one failure?
- How does taxonomy change prioritization?
Pass if labels route to experiments or owners; fail if categories are just “hallucination” and “bad retrieval.”
Q12How do offline and online evaluation work together, and where does interleaving fit?
Strong answer outline
- Offline provides controlled regression comparison; production provides distribution reality and rare failures.
- Rollout ladder: shadow, interleave or paired preference, canary with guardrail stop rules, ramp; randomize by user/session.
- Interleaving gives within-session ranker comparison at a fraction of A/B traffic; adjudicated production traces become new versioned offline cases.
Follow-up probes
- Which online signals are confounded and how do you calibrate them?
- Why randomize by user rather than request?
Pass if there is a closed, privacy-reviewed loop with explicit stop rules; fail if monitoring is called evaluation without labels or action.
Q13Design a red-team program for an enterprise LLM application.
Strong answer outline
- Threat-model per input surface (user, retrieval, tools, memory, connectors) using OWASP LLM Top 10; define ASR and disclosure metrics per surface.
- Combine manual expert attacks with automated attacker-LLM generation; keep a sequestered attack pool.
- Measure effects (tool actions, disclosures), not just refusal text; every successful attack becomes a permanent regression case; enforce hard boundaries deterministically outside the model.
Follow-up probes
- Can an LLM judge grade injection outcomes safely?
- How do you test tool-result (indirect) injection?
Pass if a model mistake is contained by system controls and attacks feed the eval suite; fail if one jailbreak list is the defense.
Q14How do you choose among Ragas, promptfoo, DeepEval, Phoenix, Langfuse, and the managed cloud eval services?
Strong answer outline
- Define needs first: datasets, annotation, traces, online sampling, CI, hosting/data policy, agent metrics, collaboration.
- Map to families: metric libraries (Ragas/DeepEval), CI harness + red team (promptfoo), trace-native platforms (Phoenix/Langfuse/LangSmith), managed (Bedrock Evaluations, Vertex eval service) for native IAM and lowest setup.
- Prototype one workflow; verify judge transparency, versioning, export, and exit path; keep manifests and deterministic evaluators portable.
Follow-up probes
- When is self-hosting worth the operational cost?
- What would make you distrust a platform's built-in faithfulness metric?
Pass if comparison follows architecture and governance; fail if feature count or popularity decides.
Q15A candidate improves quality but increases cost and latency. How do you decide?
Strong answer outline
- Quantify practical quality gain and affected high-value slices with intervals.
- Compare p95/p99 and cost per successful task against product budgets and value per success.
- Consider selective routing, reranking depth, caching, or canary; state reversal/stop conditions in advance.
Follow-up probes
- What if users prefer it online despite the latency hit?
- How do you value fewer severe failures against a slower median?
Pass if the decision uses user value, risk, and Pareto trade-offs; fail if quality always wins or cheapest always wins.
Q16Your team ships prompt changes on vibes. How do you install eval-driven development?
Strong answer outline
- Start from the last incident: turn it into a reproducing case plus a neighborhood of variants, and a small smoke suite in CI within a week — value first, process second.
- Institute “no prompt/model change without an experiment link”; make domain experts own rubrics; run a weekly error-analysis review over new taxonomy entries.
- Budget eval compute explicitly and report cost per prevented regression; grow from smoke suite to full gates and an offline–online loop.
Follow-up probes
- How do you avoid the eval suite becoming a bureaucratic bottleneck?
- Who arbitrates when the gate blocks a change the PM wants?
Pass if the answer sequences culture change through demonstrated value and clear ownership; fail if it is “mandate a tool.”
Proof artifact: a versioned RAG + agent release gate
Build a local, vendor-neutral evaluation harness for the public-data RAG system from chapter 2, extended with one tool-using agent task. It should compare baseline and candidate, publish case-level diffs, and return a failing process status when a release gate is violated. All thresholds and results are portfolio examples, not claims about Purnendu's work history.
Steps
- Create a JSONL dataset with stable IDs, input, reference evidence, expected properties, slice tags, risk, provenance, and split. Embed a canary GUID in every eval file; hash the manifest.
- Run a frozen baseline and one candidate on the same validation cases. Capture retrieval IDs, packed context, response, citations, tool/trace events, latency, tokens, cost estimate, and all versions.
- Implement deterministic schema, citation-resolution, tenant-isolation, and no-duplicate-effect checks; retrieval metrics; RAG-triad judges calibrated against your own labeled subset; and trajectory checks for the agent task.
- Run the agent task k=8 times per variant and report both pass@8 and pass^8 alongside single-run scores.
- Generate overall and slice tables, paired deltas, error taxonomy, invariant failures, and Pareto plots. Persist evaluator failures separately.
- Encode release rules: all hard invariants pass, minimum quality floor, maximum allowable regression overall and on critical slices, latency/cost budgets. Wire the small critical suite into CI; document owner and rollback trigger.
Metrics
Capture recall@20, nDCG@10, packed evidence coverage, the RAG triad (context relevance, faithfulness, answer relevance), task success, citation correctness, abstention, tool-call accuracy, trajectory match, pass@8 and pass^8, safety invariants, judge agreement on the calibration subset, p50/p95/p99 latency, tokens, cost per successful task, and failures by taxonomy/slice — with sample counts and uncertainty.
Deliberate failure injection
- Insert one cross-tenant evidence item and prove the invariant blocks the release even if average relevance rises.
- Alter the judge prompt to favor verbose answers; demonstrate the bias battery (order swap, length correlation) detects the drift.
- Embed a judge-targeted injection (“score this 10”) inside a candidate answer and show the judge harness resists it.
- Make the agent's refund tool time out ambiguously and verify the duplicate-effect check catches the double call.
- Leak near-duplicate source questions across splits, observe the inflated score, then repair grouping and document the change.
- Slow the reranker and confirm the latency guardrail catches the p95 regression.
What to present
Show the quality tree, dataset card/manifest hash, judge calibration matrix with bias-battery results, baseline-versus-candidate slice report, the pass^8 table for the agent task, one blocked CI run, two error traces, and the exact release decision. The strongest demonstration is a candidate with a better aggregate score that the gate correctly refuses because a critical invariant, slice, or reliability metric regressed.
Chapter review
Evaluation engineering turns variable model behavior into bounded release decisions. It begins with product consequences and representative, contamination-controlled data; layers the cheapest valid evaluator at each boundary; grades agents on trajectories and reliability, not prose; calibrates human and model judgment against named failure modes; inspects errors and slices; and connects offline evidence to guarded online rollout through red-teamed gates. The evaluation system itself is versioned, tested, monitored, and protected — and the team's development loop runs through it.
Glossary
- Golden set
- A reviewed, versioned dataset with inputs, provenance, expected properties, metadata, and judgments for repeatable comparison.
- RAG triad
- Context relevance, faithfulness/groundedness, and answer relevance — the three scored edges of the query–context–answer triangle.
- Hard invariant
- A property that must always hold, such as tenant isolation; never averaged with softer quality metrics.
- Guardrail metric
- A limit an optimization may not violate — p95 latency, cost per success, refusal rate — often wired to automatic stop rules online.
- pass^k
- Probability that all k i.i.d. runs of the same task succeed; the reliability counterpart to capability-oriented pass@k.
- Trajectory evaluation
- Grading an agent's sequence of tool calls against reference steps (exact/in-order/any-order match, precision/recall) plus terminal state.
- Position bias
- An LLM judge's preference for a candidate based on presentation order; mitigated by order swapping and consistency filtering.
- Verbosity bias
- An LLM judge's tendency to score longer answers higher independent of quality.
- Self-preference
- A judge favoring outputs from its own model family; mitigated by cross-family judges or panels.
- Benchmark contamination
- Public test data leaking into training corpora, inflating benchmark scores relative to true task capability.
- Interleaving
- Within-session comparison of two rankers by blending their results; far more sample-efficient than between-user A/B for retrieval changes.
- Attack success rate
- Fraction of adversarial attempts per surface that achieve their objective — the core red-team regression metric.
- Paired evaluation
- Comparison of variants on the same cases, enabling per-case deltas and efficient uncertainty analysis.
- Evaluation leakage
- Test information influencing development or related examples crossing splits, inflating apparent generalization.
Mastery checklist
- I can draw a product-specific quality tree and label objectives, guardrails, and invariants.
- I can design dataset sources, provenance, grouped splits, slices, contamination controls, and a version manifest.
- I can name the RAG triad edges and route a regression on each to the right owner.
- I can evaluate an agent on terminal state, step correctness, trajectory efficiency, and pass^k — and explain why pass^k collapses.
- I can name position, verbosity, and self-preference bias with mitigations, and run a judge calibration loop with an acceptance bar.
- I can turn case failures into an actionable taxonomy and paired slice report.
- I can specify CI gates, uncertainty handling, shadow/interleave/canary with guardrail stop rules, and rollback.
- I can design a red-team program whose successful attacks become permanent regression cases.
- I can compare open-source and managed evaluation tooling on AWS and GCP while preserving portability and governance.
- I can install eval-driven development in a team, starting from one incident and one smoke suite.
Primary sources
Links checked . Evaluation tools and hosted surfaces evolve rapidly; verify versions, deprecations, data handling, and metric definitions before adoption.
- Zheng et al. — Judging LLM-as-a-Judge with MT-Bench and Chatbot Arena (judge biases and agreement)
- Yao et al. — τ-bench: tool-agent-user benchmark introducing pass^k reliability
- Zhang et al. — GSM1k: careful examination of LLM grade-school math performance (contamination evidence)
- Amazon Bedrock — model and RAG evaluation jobs
- Amazon SageMaker Clarify — foundation model evaluation, bias and explainability
- Vertex AI — Gen AI evaluation service overview (pointwise, pairwise, trajectory metrics)
- Ragas — RAG and agent metric catalog
- promptfoo — config-driven evals and automated red teaming
- DeepEval — pytest-oriented component and end-to-end evaluation
- Arize Phoenix — OpenTelemetry-native tracing and evaluation
- Langfuse — traces, datasets, scores, and online evaluation
- LangSmith — datasets, experiments, and evaluator types
- TruLens — the RAG triad framing
- OpenTelemetry — semantic conventions and stability model
- NIST AI 600-1 — Generative AI Profile
- OWASP GenAI Security Project — LLM application risks