Verification layer for RAG pipeline
10 min read
November 02, 2026
I built an eval harness for a RAG pipeline a couple of weeks ago. I prepared 58 questions, along with expected answers and the evidence that supports them. The idea was always to measure before improving. A handful of metrics helped me make the key decisions along the way, and they changed how the LLM produced its answers in many ways.
One of the key metrics was faithfulness. An LLM judge reads the whole answer and scores whether it is supported by the retrieved context. It’s a useful number, but it has two blind spots. It scores the answer as a whole, so it can’t tell me which sentence is wrong. It also gives the same low score to an answer that says something false and to an answer that says something the documents simply don’t cover. It even gave a perfect 1.0 to answers that had facts backwards. q023 described the check_dir setting the wrong way round and still scored 1.0.
There are two kinds of undesirable claims. First, a claim can contradict the corpus: the documents say one thing and the answer says the opposite. Second, a claim can be ungrounded: nothing in the corpus settles it either way. A claim of the second kind can be true in real life (functools.lru_cache really does default to 128), but these documents don’t vouch for it. It’s less harmful than a contradiction, where the model had the truth in front of it and said otherwise. So the verification layer treats them differently.
With all this in mind, I prepared a file of 94 golden claims labelled supported (33), contradicted (36) and no_evidence (25). Supported means the corpus states the claim or directly entails it. 32 of the claims are harvested from real answers across five eval runs. I could have stopped there, but harvested claims are mostly correct ones, so I wrote the other 62 myself. Some are deliberately false, to be contradicted. Others are true in the world but absent from the docs, so that no_evidence actually means something. Every claim carries its evidence as a (source file, verbatim quote) pair, and a validator script checks every quote against the corpus before any number is built on the file.
One rule settled every labelling argument: a golden claim quotes the answer, not the corpus. If I wrote a claim as my own interpretation of the docs, I’d be punishing the extractor for not finding words the answer never used, and making the judge rule on a claim the system never made.
The process has four steps: extraction, retrieval, judgement and aggregation.
Extraction takes the question and the generated answer and asks an LLM to break the answer into atomic, self-contained claims. I used structured outputs, so the API enforces the JSON shape and it can’t break silently. To check the extractor, I measured coverage: for each harvested golden claim, did the extractor produce a matching claim from the same answer? The match uses fuzzy string similarity plus token recall. It only compares wording and phrasing, not meaning, so borderline matches are printed for me to review by eye.
For extraction, I used a model from the same family as the generator (OpenAI). Restating an answer is clerical work. Judging it isn’t: a model grading its own family’s answer shares its blind spots. So the judge comes from a different family (Claude). The rule for the answer as a whole is “worst claim wins.” If even one claim is contradicted by the corpus, the whole answer is contradicted, no matter how many true sentences surround it. If one claim has no evidence, the answer is unverified. Only an answer whose claims are all supported is verified.
In the real system, each extracted claim becomes the search query, not the original question. The question retrieves what you need to answer; the claim retrieves what you need to check. A false claim needs the passage that refutes it, and the question may never have surfaced that passage. To evaluate this step, I used the golden claims as queries, because their evidence is already verified. I used the same retrieval approach as in the RAG pipeline, hybrid search with reranking. Vector search and full-text search together nominate 20 chunks, a cross-encoder re-scores them by reading the claim and each chunk together, and the top 5 go to the judge.
The golden claims already have the evidence that supports them in the same file. We know for certain those passages back the claims. We can’t say the same for the chunks retrieval returns for the same claims. The common assumption is that if the retrieved chunks match the hand-picked evidence, retrieval has done its job perfectly. But this isn’t the ideal case.
So I ran the judgement phase in two modes. In retrieved mode, the judge sees only the chunks the retrieval step returned. This is the real system. In oracle mode, retrieval is taken out and the judge sees the chunk that contains the golden evidence quote. Oracle isolates the judge. If oracle gets a claim wrong, the judge or the label is at fault; if retrieved does worse than oracle, retrieval is. Ideally, oracle accuracy should be at least as high as retrieved.
What the numbers said
Extraction: from 48% to 100%, with one prompt change
The first coverage number was 48%. It looked like a bad extractor. It was actually a bad measurement, twice over.
First, stale answer keys. Claims harvested from one eval run’s answer were being graded against a different run’s answer to the same question. I fixed it by extracting from every source run and scoring each claim against its best match, which took coverage to 84%.
Second, split credit. The prompt tells the extractor to split compound facts into atomic claims, and my pairwise matching punished exactly that. Switching to token recall across all the extracted claims together took it to 97% automatically, and 100% after reviewing the borderlines.
The extractor’s prompt changed only once in all this, to preserve the question’s frame. “Starlette is based on ASGI as its async library” is contradicted. Bare “Starlette supports ASGI” might not be.
Retrieval: the reranker is what catches false claims
I measured whether the golden evidence showed up in the top 5 retrieved chunks, for the 69 claims that have golden evidence (no_evidence claims have none by definition).
| hit@5 | hybrid | hybrid + rerank |
|---|---|---|
| all claims | 0.913 | 0.971 |
| contradicted | 0.889 | 1.000 |
| supported | 0.939 | 0.939 |
| median latency / claim | 0.45 s | 1.84 s |
Supported claims didn’t move at all. Every claim that flipped from miss to hit was a contradicted one (c001, c025, c026, c049). The cross-encoder scores topical match, not truth, and that turns out to be exactly what a detector needs. A false claim’s wording pulls in keyword-matched chunks from the right file but not the specific passage that refutes it. The cross-encoder ranks that passage up. Without the refuting passage, the best verdict the judge can honestly give is no_evidence, and the whole false-vs-ungrounded distinction collapses. That’s why I accepted four times the latency.
The two supported claims that still missed weren’t retrieval failures. In one, the support lived in a passage my label didn’t list. In the other, the evidence spanned a chunk boundary. Adding a second evidence quote fixed both. Evidence lists aren’t exhaustive, so a “miss” on a supported claim is first a question about the label.
Judgement: when oracle scored worse than reality
The first run gave oracle 0.755 and retrieved 0.957. The mode that should have been the ceiling was 20 points below the real system. Instead of touching the prompt, I read the judge’s rationales. They pointed to three measurement bugs:
- Truncated verdicts.
max_tokens=300cut the judge off mid-response, producing labels with blank rationales and “no verdict” rows that looked like judgments. I raised it to 1024 and tagged any truncated rationale. - Fragments instead of evidence. The first oracle fed the judge my golden quotes. Those are short locator fragments chosen to find a span, not to stand alone as evidence. The judge kept saying the passage cut off mid-sentence and refused to call the claim supported. It was right. I fixed it by giving oracle the full chunk containing the quote.
- A wrong label. c071 had been flipped to
supportedwith a quote that didn’t contain the fact. The judge’s rationale said so. I reverted the label.
Only then did I change the prompt, once, and the change came from the judge’s own words. Its wrong calls were hedged with phrases like “this takes a small inference” and “loose match.” The new rule: if your rationale needs words like that, the label is no_evidence. That removed the remaining over-calls.
| oracle | retrieved | |
|---|---|---|
| accuracy | 0.979 | 0.968 → ~0.99 after the “small inference” rule |
| false-supported rate | 0 / 36 | 0 / 36 |
| contradicted recall | 1.000 | 1.000 |
False-supported rate is the number I care about most: how many contradicted claims did the judge wave through as supported? It was zero in both modes. It is only measurable because contradicted is its own class.
What stayed imperfect: c017, a vague claim whose label I’m still not sure about, is wrong in both modes. c089, a borderline claim, flipped between two runs on identical input even at temperature 0. With 94 claims, one claim is about one point of accuracy, so I report the soft cells as ranges, not single values.
Prompt or model? One variable at a time
The extractor still made mistakes that caused false flags. It dropped a scope (“validator exceptions” became all exceptions), dropped a mechanism, inverted a causal clause, and turned summary sentences into claims. To measure extraction precision (does each extracted claim say what the answer said?), I ran the judge with the answer itself as the only evidence. The first attempt scored 0.14, because the passage was labelled as the answer under test and the judge refused to let a text vouch for itself. With neutral framing, it gave a real number.
Then I changed one thing at a time:
| 4o-mini, original prompt | 4o-mini, revised prompt | gpt-4o, revised prompt | |
|---|---|---|---|
| coverage | 30/31 | 30/31 | 29/31 (two borderlines, zero misses) |
| extraction precision | 0.988 | 0.982 | 1.000 |
| claims per answer | 5.7 | 5.7 | 5.1 |
| contradicted answers: real / false | 3 / 3 | 3 / 2 | 4 / 1 |
| summary-sentence noise claims | 7 | 7 | 3 |
| median latency / answer | 25.3 s | 22.9 s | 17.6 s |
The prompt revision fixed dropped scopes and nothing else. The model change fixed what the prompt couldn’t. The small model followed rules about content and ignored rules about form. If I had changed the prompt and the model together, “it was the model” would have been a guess. Fewer, tighter claims also meant fewer judge calls, so the bigger model ended up faster per answer. The extractor is now frozen at gpt-4o with the revised prompt.