A RAG system that always answers is just harder to catch. The failure that passes every fluency check is a confident reply built on missing, off-topic or conflicting evidence. Few standard tests check whether the system should have declined, and skipping that test costs you later, usually in front of a customer. A support bot that confidently quotes a refund rule the company never had has made a promise. Now someone has to keep it or take it back in public.
A fluent answer can still fail
A retrieval-augmented generation (RAG) system can find plausible text and write a clear reply while inventing the facts. A policy changed but the index is out of date. A user asks about a feature that does not exist. Two sources disagree and the model quietly picks one. In every case the wording is fine and the content is wrong.
Answer evaluators make this worse. They reward similarity to a reference answer whenever evidence exists, and they never test the decision to stop. Abstention testing fills that gap. It checks whether the system refuses or limits its answer when the evidence cannot support one.
Treat this as a release-quality problem. The tests must tell missing evidence apart from irrelevant results and from conflicting sources. They must judge whether the system actually answered. And they stay as versioned files that fail builds when behavior drifts.
A top retrieval score is not permission to answer
A retrieval score ranks results; it says nothing about truth. Dense similarity measures how alike two texts look to the model. Keyword overlap and reranker scores answer their own ranking questions. None of them proves that a chunk contains the needed fact, fits the user's situation or agrees with the other documents.
So a top-score threshold breaks in both directions. A narrow question with no real answer can pull in nearby policy pages with high scores. A well-supported question in unusual words can score low. The scales also shift whenever you change the embedding model, the chunking, the documents or the reranker. A cutoff that worked last quarter quietly stops meaning the same thing.
Position is a second trap. In "Lost in the Middle" (2023), Liu and colleagues found that language models use information at the start or end of a long context better than information in the middle. A relevant chunk ranked fifth can be retrieved and still ignored. So a high retrieval score does not even prove the model read the evidence.
The fix is to treat abstention as a question of whether there is enough evidence. Retrieval confidence is one input among several: coverage, agreement between documents, how trusted the source is, and whether the cited text actually supports the generated claims. Where a product offers clarification or human review, abstaining can pass the question on instead of ending the conversation. The labels should reflect that expected behaviour.
A no-answer label needs a precise contract
"Abstain" is not one action. It can mean saying what is unknown, asking a specific follow-up question, or naming a conflict and refusing to pick a side. These are different behaviours, so the dataset must say which one is expected before anyone reads a response.
Label the action, not the tone:
| Evidence condition | Expected action | What counts as a pass | Risk if answered |
|---|---|---|---|
| Missing evidence | Abstain | States the knowledge gap or asks for the missing source | Fabricated policy or feature claim |
| Irrelevant retrieval | Abstain | Rejects nearby but non-responsive documents | Confident answer based on topical resemblance |
| Contradictory evidence | Abstain or escalate | Names the conflict and avoids selecting a winner without a rule | Silent preference for an arbitrary document |
| Sufficient, consistent evidence | Answer | Answers within source-supported scope | Unnecessary refusal that blocks a valid task |
Contradiction is not the same as uncertainty, and the difference decides the right label. If there is a fixed rule about which source wins, for example "the current signed policy beats an archived draft", build it in and test that the system gives the supported answer. Without such a rule, refusing is safer. Do not reward polite wording that sneaks in an unsupported choice.
Build cases around evidence states
A useful test set reads like a product spec for when the system must hold back. Clever trick prompts are only a small part of it. Store each case as its own JSONL line with a stable ID, so changes are easy to compare. Version the dataset together with the retrieval setup it assumes. The example below shows the format; four lines are nowhere near enough for calibration.
{"schema_version":"1.2.0","id":"abs-001","query":"Can customers export audit logs as CSV?","evidence_state":"missing","documents":[{"id":"help-17","text":"Audit logs can be viewed in the admin console."}],"expected_action":"abstain","reason":"No source establishes CSV export."}
{"schema_version":"1.2.0","id":"abs-002","query":"How do I revoke a shared dashboard link?","evidence_state":"irrelevant","documents":[{"id":"help-22","text":"Dashboard links can be copied from the Share menu."},{"id":"help-31","text":"Members can be removed from workspace groups."}],"expected_action":"abstain","reason":"Retrieved documents are related to sharing but do not describe revocation."}
{"schema_version":"1.2.0","id":"abs-003","query":"What is the retention period for deleted projects?","evidence_state":"contradictory","documents":[{"id":"policy-2024","text":"Deleted projects are retained for 30 days."},{"id":"policy-2025-draft","text":"Deleted projects are retained for 90 days."}],"expected_action":"abstain","reason":"Sources conflict and no authority rule is provided."}
{"schema_version":"1.2.0","id":"ans-004","query":"Where can an admin view audit logs?","evidence_state":"sufficient","documents":[{"id":"help-17","text":"Audit logs can be viewed in the admin console."}],"expected_action":"answer","reason":"The source directly supports the answer."}
Vary the wording of questions as much as the evidence. Mix short and long phrasing, synonyms, out-of-scope requests and documents that look out of date. Include cases where one extra trusted document changes the right behaviour from refusing to answering. Save the snippets seen at test time too. With live retrieval, a failure caused by a changed index is almost impossible to diagnose later.
Keep calibration separate from the CI holdout. The development set is where you choose the policy. The held-out cases exist to challenge it. A case you used to tune a threshold is no longer a fair release check. Record five versions with every run: dataset, index snapshot, embedding model, reranker, and prompt or policy. Then you can trace a regression to whatever actually changed.
Score the decision, then calibrate the threshold
Free-form text is hard to grade, so do not grade it. Have the pipeline return answer, abstain or escalate, and write the wording for the user afterwards. Evaluators then score a stable output, and the wording can still change.
The evaluator below reads the runner's results.jsonl, compares the frozen expected labels with the selected actions, and treats abstention as the positive class:
import json
from collections import Counter
matrix = Counter()
with open("artifacts/results.jsonl", encoding="utf-8") as handle:
for line in handle:
row = json.loads(line)
expected = row["expected_action"] == "abstain"
predicted = row["action"] in {"abstain", "escalate"}
if expected and predicted:
matrix["true_abstain"] += 1
elif expected and not predicted:
matrix["unsafe_answer"] += 1
elif not expected and predicted:
matrix["false_abstain"] += 1
else:
matrix["supported_answer"] += 1
print(dict(matrix))
if matrix["unsafe_answer"] > 0:
raise SystemExit("Unsafe answers found in abstention holdout")
Unsafe answers on no-answer cases and needless refusals on answerable cases are both defects, but they do not cost the same. Payroll, legal and security tools may need almost zero unsafe answers. A low-risk discovery tool can accept more, as long as you watch user corrections and satisfaction. Because of this, look at results by evidence state instead of trusting one number. An overall pass rate can hide a system that handles missing evidence well but still answers when sources conflict. That is a gap in the policy, whatever the average says.
Calibration turns that score into a release policy. It links a score to the real risk of a wrong decision on a development set. Choosing a neat value like 0.70 by feel skips that step. Start from a risk score that combines weak retrieval support, disagreement between documents, no answer found in the text and the model's own self-check. Fix those inputs before you compare thresholds, so only one setting changes.
Then list candidate thresholds and give each outcome a cost. These weights are product decisions, and writing them down makes the trade-off visible:
thresholds = [0.40, 0.55, 0.70, 0.80]
unsafe_cost = 5
false_abstain_cost = 1
for threshold in thresholds:
unsafe = false_abstain = 0
for row in development_rows:
predict_abstain = row["risk_score"] >= threshold
needs_abstention = row["expected_action"] == "abstain"
unsafe += needs_abstention and not predict_abstain
false_abstain += (not needs_abstention) and predict_abstain
cost = unsafe_cost * unsafe + false_abstain_cost * false_abstain
print(threshold, unsafe, false_abstain, cost)
The weights decide the winner. Say, as an example, that on a 200-case development set, threshold 0.55 gives 2 unsafe answers and 8 false refusals: a cost of 5 × 2 + 8 = 18. Threshold 0.40 gives 0 unsafe answers and 15 false refusals: a cost of 15. With a 5:1 weighting, 0.40 wins. Lower the unsafe weight to 3, and 0.55 wins, 14 against 15. Write the weights down before the run. Otherwise the threshold will be chosen to fit the result.
For the four-line fixture, a correctly wired result could be:
predicted abstain predicted answer
expected abstain 3 0
expected answer 0 1
unsafe_answer=0 false_abstain=0
Treat that as a wiring check. It says nothing about which of the four thresholds belongs in production. A set this small cannot show how much answerable and unanswerable cases overlap in score. Use it only to confirm that known unsafe behaviour fails the gate. Choose the threshold on a larger development set that people have reviewed. Check it again after any retrieval change. A new embedding model can shift scores enough that the old cutoff quietly changes the balance between unsafe answers and needless refusals. When that happens, recalibrate, compare the evidence states again and record the policy change.
CI should fail on unsafe answers
In CI, the job should retrieve from a fixed snapshot of the index, run the held-out JSONL cases, save the raw outputs and then run the evaluator. A live production index is fine for monitoring but wrong for a release gate that must give the same result every time. The index has to stay still, so a failure points at the model or the policy.
Keep these tests separate from citation-regression testing in a RAG CI/CD pipeline, because they ask different questions. Citation tests ask whether an answer points to evidence. Abstention tests ask whether it should have answered at all. A response can cite a nearby document perfectly and still be unsafe.
name: rag-abstention-gate
on: [pull_request]
jobs:
evaluate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build frozen evaluation index
run: python scripts/build_index.py --snapshot fixtures/index-v12
- name: Run held-out no-answer cases
run: python scripts/run_rag.py --input datasets/abstention-holdout-v1.2.0.jsonl --output artifacts/results.jsonl
- name: Enforce abstention policy
run: python scripts/evaluate_abstention.py
- name: Save failure evidence
if: failure()
uses: actions/upload-artifact@v4
with:
name: abstention-results
path: artifacts/
Always upload the artifacts. A bare failure count cannot tell you whether retrieval, reranking, policy, prompt or parsing got worse. For each failed case, save the retrieved IDs, their scores, the chosen action, the generated text and the policy version. Remove private data from test cases before they go into source control, and never store sensitive customer material there.
Tempting shortcuts hide the worst failures
The obvious shortcuts fail exactly where it hurts most. Treating every low-score retrieval as a refusal misses high-score irrelevant results and contradictions, and both look more convincing to a user than an empty result. Adding an "are you confident?" question just creates an uncalibrated second opinion that usually repeats the first one's mistake.
Refusal wording alone proves little. "I cannot find that" is fine until it is followed by an invented workaround. So grade the action first, then read the answers for claims without support. For an escalation, check that it actually passes on the conflict or the missing field the next person or system needs.
Watch the mix of the set as well. One that is mostly missing-evidence cases rewards refusing whenever retrieval is empty, so the per-state report above has little to say about conflicts. Keep the hard cases after you fix them. If you delete a case you just passed, a future regression becomes invisible.
Users trust a system that knows where its evidence ends, and the test set is where that boundary usually wears down. A frozen set covering missing, irrelevant, contradictory and sufficient evidence carries the first release. After that, regressions are caught by the real failures you add later, with private data removed. Retrieval changes will keep moving the thresholds. The release rule stays the same: confidence without support never counts as a pass.