LLM and RAG Evaluation
Eight guides to eval datasets, graders, retrieval metrics, groundedness, adversarial cases, model changes, production feedback, and governance.
Series Chapters (8)
Build an LLM Eval Dataset from Real Product Risks
A benchmark of polished prompts can climb while users keep hitting the same failures. This guide builds a dataset for a QA assistant that must derive tests, cite requirements and refuse secret extraction: a task and harm map, case sources, a per-case record with owner and risk, behaviour-first references, a hash split that keeps the holdout fixed as cases are added, and per-slice reporting that exposes a 0 of 9 high-risk row behind a 53% aggregate.
Calibrate an LLM Judge Before You Trust Its Scores
A groundedness score can look precise while the grader marks a contradicted answer as supported. This guide writes a rubric with a precedence rule, builds a blinded labelled set, and measures agreement with Cohen's kappa and a confusion matrix, using a deterministic stub judge and a synthetic 30-item set. It adds swap, padding and planted-bias tests, shows why 30 perfect items still cannot prove 95% reliability, and lists when a judge should not make the call.
Find Whether a RAG Answer Failed in Retrieval or Generation
A wrong RAG answer can come from missing evidence, a zero-overlap query, a chunk ranked below k, a context budget that cut it, or a model that ignored it, and one end-to-end score cannot tell which. This part saves a per-case trace, applies six ordered checks to eight cases on an in-memory BM25 retriever with a deterministic stub generator, and shows why recall@k, faithfulness and a larger k each mislead on their own. It ends with a per-failure decision table and a gold-only probe that separates a generation failure from a retrieval one.
Test RAG Chunking with Questions the Product Must Answer
A chunk-size debate means little until you know whether the facts a question needs survive intact and reach the prompt. This lab labels gold evidence as verbatim fact spans instead of chunk IDs, then compares seventeen chunking strategies on 44 questions for a fictional policy with exceptions in other sections, tables and cross-references. It measures fact survival with no retriever, complete-evidence recall at equal word budgets on BM25 and a local MiniLM embedding model, top-chunk citation support, index size and latency. Fixed chunks lost facts, 25% overlap closed most of the gap, parent-child and chapter-sized parents lost, and most gaps need more questions than 44 before anyone acts on them.
Test LLM Hallucination, Abstention and Citation Faithfulness
A well-formed citation to a real passage can still sit under an invented answer. This guide splits hallucination into contradicted claims, unsupported claims, citations that do not entail their claim and wrong abstention, using a 46-case lab with answerable, unanswerable, partial and conflicting-source questions and a rule-based system with switchable failure modes. It shows two systems with the same headline rate and opposite diagnoses, a lexical entailment check and the cases it gets wrong, and a threshold sweep that prices over-refusal against fabrication with Wilson intervals.
Red-Team an LLM Application with Abuse Cases You Can Measure
A pattern filter scored 0 breaches in 180 trials on the cases it was written for, then 23% after a paraphrase and 18% after base64. This part builds 47 abuse cases for a stub support assistant from assets, actors and exits, tagged by OWASP 2025 category and severity, judged from tool and egress traces, with Wilson intervals, four mutation operators, a regression gate and an abuse-case record. It also shows what a mutation generator misses that a tool inventory finds.
Decide on an LLM Model Upgrade with Paired, Per-Slice Evidence
A candidate model can win the aggregate by 5.1 points and still fail a high-risk refusal floor, and one run cannot show either fact reliably. This part freezes arm manifests, shows how far a single run moves when nothing changed, tests paired differences with McNemar's exact test and a paired bootstrap cross-checked in SciPy, and measures how many runs and cases the decision needs. It then writes budgets for quality, cost, p95 latency and refusal rate, replays traffic in shadow, explains why a canary barely sees a 3% slice, and reads the vendors' pinning and deprecation rules.
Turn a Production LLM Failure into a Regression Eval That Holds
A support assistant quoted a superseded 45-day refund window, the stale document was deleted, and nothing stopped it happening again. This finale of the LLM and RAG Evaluation series turns that incident into a regression case: replaying against the index snapshot, scrubbing against the customer record with keyed pseudonyms, shrinking with delta debugging against a mechanism predicate, and grading with fixture-driven checks. Hidden sibling cases then reject a prompt hotfix and a newest-version fix that both pass the original incident.