Grounding and abstention
Grounding is more than adding a citation
Grounded answers are supported by the evidence actually available to the generator. A citation to a valid passage does not guarantee that the passage entails the claim. In the fictional handbook, H2-r1 states that returns require a receipt; it gives no refund deadline. Answer the receipt question with H2-r1 and return insufficient evidence for the deadline. The local example operates on manually annotated factual triples, rather than asking a model to interpret text. A second conflicting shipping duration also triggers abstention. This conservative policy avoids silently selecting one incompatible value. It is an intentionally narrow extractive baseline: a human annotator has already identified the field and value. It does not evaluate arbitrary natural-language entailment.
def answer(field, context): # Manually annotated factual triples (source ID, field, value). # No model or interpretation of free text occurs here. matches = [(key, value) for key, name, value in context if name == field] values = {value for _, value in matches} if len(values) != 1: return {"status": "insufficient_evidence", "value": None, "citations": []} return {"status": "answered", "value": next(iter(values)), "citations": sorted({key for key, _ in matches})}
facts = [("H2-r1", "receipt_required", "yes"), ("H3-r1", "shipping_days", "5")]print(answer("receipt_required", facts))print(answer("refund_deadline", facts))print(answer("shipping_days", facts + [("H4-r1", "shipping_days", "7")]))Distinguish failure modes
An unanswered question can mean the corpus lacks the fact, search missed the correct chunk, a budget excluded it, the user lacks permission, or the generator failed to use it. Keep these diagnostic categories internal where disclosure might reveal restricted records. A question may require two passages, for example a rule and an exception: supporting only the rule is not a complete answer. A real system should use effective dates and policy authority to resolve conflicts when that information is trusted, otherwise explain uncertainty or route to a reviewer. Avoid answering with an obsolete revision simply because it ranks highly. In the toy contract all facts supplied to answer are already current and authorized; when inconsistent values remain, it abstains. The response exposes no denied IDs.
Measure retrieval and generation separately
Recall is the fraction of relevant IDs retrieved, under a fixed relevance judgment set and corpus snapshot. If there are no relevant IDs, this example returns None; measure correct abstention on those queries separately. For a relevant set {H2-r1}, retrieving H2-r1 and H3-r1 gives recall 1.0, even though H3-r1 is irrelevant. Precision and rank-sensitive measures can reveal that problem in later lessons. Answer support is checked separately: this function checks that all cited IDs belong to the supplied context and exactly support the chosen field and value, rejecting conflicts and duplicate citations. It returns True for the receipt fact and False for the fabricated deadline. The rule only covers a single atomic field; in free text a reviewer must break an answer into claims and inspect meaning, conditions and completeness. Do not confuse citation presence, answer coverage, correctness and faithfulness.
def recall(relevant, retrieved): # Human-judged relevant source IDs for this query and snapshot. if not relevant: return None return len(set(relevant) & set(retrieved)) / len(set(relevant))
def supported(field, value, citations, context): # Exact fact support only; every cited ID must support the claim. if not citations or len(citations) != len(set(citations)): return False matches = [(key, val) for key, name, val in context if name == field] if {val for _, val in matches} != {value}: return False valid_ids = {key for key, val in matches if val == value} return set(citations) <= valid_ids
facts = [("H2-r1", "receipt_required", "yes")]print(recall({"H2-r1"}, ["H2-r1", "H3-r1"]))print(supported("receipt_required", "yes", ["H2-r1"], facts))print(supported("refund_deadline", "30", ["H2-r1"], facts))Design a small evaluation set
Freeze the handbook revision, record each question and authorized relevant IDs, label whether it is answerable, and note the expected fact or abstention. Include direct wording, synonyms, missing information, a two-part question, and a conflicting or stale passage. Hold out some queries when tuning chunk size and top-k. Log retrieval recall, context recall, answer support and correct abstention separately; for unanswerable examples report counts, not a fabricated recall of zero or one. A false abstention on an answerable question is also an error. Re-run the same judged fixtures after changing the chunking or retrieval settings, and compare errors instead of claiming universal improvement from a small sample. Treat source trust and currentness as additional checks beyond textual grounding.
Practice: decide whether to answer
Use the project fixture to retrieve, assemble and then select facts only from included IDs. Check receipt and shipping questions, the missing refund deadline, a too-small context budget, a stale ID and conflicting current shipping facts. Test a valid but unrelated citation and an invented citation. Explain why even a perfect citation-support result on the synthetic facts does not certify real-world factual correctness or model security. The corpus annotation, ID linkage and evaluation labels are visible in the project reviewer notes. In production, require reviewed evidence and isolate the generator from actions; an inert fixture is not proof of resistance to prompt injection. Do not use any paid API or external document for this lab.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Grounding and abstention quiz
Apply RAG evidence and grounding contracts.
A valid citation mentions returns but no refund deadline. What should the answer do?
What does recall measure in this lab?
Relevant IDs are A and B; retrieved A and C. Recall?
Two current factual triples disagree and authority is unknown. What does the local policy do?
Why evaluate correct abstention on answerable and unanswerable questions?