Testing a RAG Bot Before It Ships: Slices, a Release Gate per Slice, and the Week After
In a simulated 210-case eval, a new model lifts the average from 0.895 to 0.929 and leaks 4 restricted documents. A gate per slice blocks it where the average says release. Plus why 20 of 20 can mean 0.88, and why the gate must also run when the index changes.
What you will learn
- Build a golden set from slices sized by cost of failure, not by how common they are
- Write a release gate per slice, so an average that says release can still be blocked
- Judge a small slice by its lower bound, not its clean score
- Score retrieval, answer and tools apart, then keep watching after a staged rollout
Before you start
- Why You Cannot Ship an LLM Feature Without an Eval
- Building a Golden Dataset for LLM Evals
An interviewer asks: what would you test before shipping a RAG customer support bot? The usual answer is "I'd try some questions and see if the answers look good." This article gets you past that answer. You build a test set, score each part of the bot, and put a gate in front of the release.
The cases and model results here come from a small simulation with a fixed seed. They show the idea. They don't measure a production bot.
The answer in four steps
- A golden set: a fixed list of questions, with the hard ones in it on purpose.
- Score each part separately: retrieval, the answer and the tools.
- A release gate: rules you wrote down before the candidate ran.
- Roll out slowly and keep watching, because testing doesn't end at launch.
Think of a restaurant's soft opening. A few friends get a fixed menu. Someone orders a dish you don't serve, and the waiter should say so. Someone has an allergy, and that plate has to be right. When a plate comes out wrong, you ask whether it was the shopping, the kitchen or the waiter. You agreed beforehand that one allergy mistake means you don't open, however good the food tastes. And after opening, you still read the first week's complaints.
Better fluency, worse facts
For illustration, picture a model update whose answers read beautifully. Everyone who tries it likes it. But smooth wording isn't correct wording, and a confident wrong answer reads just as well as a right one. Trying it by hand can't catch that.
Now with numbers, from the simulated eval set of 210 cases. The old model scores 0.895 overall and the new one 0.929. It went up, so you'd ship it. Look inside, though. On questions that touch restricted documents, it went from 30 out of 30 to 26. In this scenario that's four cases where someone saw a document they weren't allowed to see. One average can't show you that.
The golden set: slices by cost, not by frequency
A golden set is fixed questions, each with the right answer or the right behaviour written beside it. You take them from past tickets and past incidents. The simulated set has four slices:
| Slice | Cases | What a pass means |
|---|---|---|
| Answerable | 120 | The document exists; we found it and the answer sticks to it |
| Unanswerable | 40 | No document exists; the bot abstains and says it doesn't know |
| Restricted | 30 | Same question, two users with different permissions; one must not see the document |
| Unsafe | 20 | The bot should decline |
The slices aren't sized by how common they are. The rare ones are in there because they're expensive when they fail. For how to build and check the cases themselves, see Building a Golden Dataset.
Score each part
A bot has parts, and one pass or fail doesn't tell you which part broke.
- Retrieval: did the right document come back at all? If not, no model can save the answer.
- Answer: given that document, does every claim come from it? That's grounding.
- Tools, if the bot uses them: did it call the right one, with the right details, and did it work?
So a failed case points at one part, like the shopping, the kitchen or the waiter. To be honest about the simulation: it gives one pass or fail per case. On your own bot you'd keep these three scores apart.
The release gate
The rules are written before the candidate runs. Each slice has a limit, and the restricted slice allows zero failures. Here is the simulated run:
SIMULATED results, fixed seed
baseline overall 0.895
answerable 104/120 rate 0.87 low 0.81
unanswerable 34/40 rate 0.85 low 0.74
restricted 30/30 rate 1.00 low 0.92
unsafe 20/20 rate 1.00 low 0.88
candidate overall 0.929
answerable 113/120 rate 0.94 low 0.90
unanswerable 36/40 rate 0.90 low 0.80
restricted 26/30 rate 0.87 low 0.73
unsafe 20/20 rate 1.00 low 0.88
average gate: release
contract gate: block
- restricted: 4 fails, max 0
- restricted: down 0.13
candidate2 overall 0.948
answerable 113/120 rate 0.94 low 0.90
unanswerable 36/40 rate 0.90 low 0.80
restricted 30/30 rate 1.00 low 0.92
unsafe 20/20 rate 1.00 low 0.88
average gate: release
contract gate: release
SIMULATED week after release
rollback: (5, 'leak')
Answerable passes, unanswerable passes. Restricted has four failures against a limit of zero, and it's down 0.13 on the old model, so two reasons go on the list. Unsafe passes, but the list isn't empty, so the decision is block. The average said release, the gate says block, and it tells you why.
Then the simulation is set so a second candidate gets restricted back to 30 out of 30. That isn't a fix; it only shows how the gate reacts. Overall 0.948, no reasons, release.
This is the part the earlier eval articles leave out. Regression Testing in CI gates on one pass rate and a drop from baseline. A per-slice gate adds a hard stop on the slice where one failure is too many.
The trap: 20 out of 20 is not perfect
Unsafe is 20 out of 20, so weak candidates call it perfect. It means twenty cases didn't catch anything. With so few cases, the true pass rate could reasonably be as low as 0.88. That's the low column in the output above. So you judge a small slice by that lower number, not by the clean score.
The week after
The failure test comes after launch too. You release to a small share first, and watch. In the simulation, day five shows one leak, because a new index exposed a restricted document. The rule says roll back.
Notice that the gate had passed that release. It tested a model, and the index changed later. So run the gate on index changes as well, and add that leak to the golden set so it's caught next time.
Follow-ups
- A slice is too small to tell you anything. Now what? Add cases. Don't loosen the rule.
- The team keeps rerunning until it passes. What's wrong? The set has stopped being a test. Tune on one set, and lock another for the release decision.
- Why zero failures on restricted but not on the others? Because the cost isn't even. And zero on the set doesn't mean zero in the world.
A simple rubric
| Level | What the answer has |
|---|---|
| Weak | "We tried it and the answers looked good." |
| Solid | A golden set, split into slices, with a threshold for each |
| Strong | Also scores retrieval, answer and tools apart, treats a permission failure as a hard stop, rolls out gradually, and says what the gate can't see |
The rubric is a guide for practice, not a measurement.
Recap
| Idea | What to remember |
|---|---|
| Hand testing | Can't catch a confident wrong answer |
| Golden set | Slices sized by cost of failure; rare, expensive cases on purpose |
| Gate | Rules per slice, written first; simulated: average 0.929 said release, gate said block |
| Small slices | 20 of 20 has a lower bound of 0.88 |
| After launch | Staged rollout, gate on index changes, new incidents into the set |
For the basics of an eval, see Why You Cannot Ship Without an Eval.
Try it yourself
Think of a support bot you've used. Write three questions it should refuse or get exactly right, and say which slice each one belongs to.
Related course on Udemy
Machine Learning Engineer: From First Model to ML Engineer
Learn machine learning in Python, then ship it: data analysis, regression, classification, tuning, deployment and MLOps.View on Udemy ↗: Machine Learning Engineer: From First Model to ML Engineer (paid course, opens in a new tab)Related posts
Why You Cannot Ship an LLM Feature Without an Eval: Five Parts, Three Graders, One Tiny Eval
A friendlier prompt looked better on three questions and broke on others. An eval catches that: a fixed set of cases, a grader, a pass rate and a threshold. A tiny Python eval scores two prompt versions on the same six questions: v1 passes 83% and ships, v2 passes 50% and is blocked.
Building a Golden Dataset for LLM Evals: Cases, a Schema, a Coverage Table and a Seeded Split
The answer key for a support bot: 24 cases in one JSONL file, from 12 past tickets, 8 edge cases and 4 attacks. A Pydantic schema catches 4 problems in a broken file, a stats table finds that payments and account have no hard case, and a seeded split gives the same 16 dev and 8 test cases every time.
Retrieval Evals: Score the Retriever With Recall@K, MRR and nDCG Before Blaming the Model
When a RAG answer is wrong, check the retriever first. Score two retrievers on 24 graded queries with Recall@5, MRR and nDCG@5: overall there's no clear winner (0.757 vs 0.819, 0.854 vs 0.826, 0.769 vs 0.782), but the paraphrase slice drops to about 0.5 for both, and one query scores zero everywhere.
Regression Testing an LLM Bot in CI: A Golden Set, Two pytest Gates and GitHub Actions
A teammate changes one prompt line to make answers shorter, and four of ten golden questions lose their facts. A pytest eval on saved answers catches it: 12 passed for the old prompt, 2 failed gates and 4 xfailed cases for the new one, exit code 1, and the pull request check turns red.