Skip to content

Courses / RAG Systems / Module 9

Module 9: Grounding, citations and the 'not found' path

6 h · theory 2 · hands-on 2 · project 1 · revision 1

You will be able to

  • Make the model answer only from retrieved context
  • Attach and verify inline citations
  • Detect unanswerable questions and say 'not found'
  • Measure citation precision

Capstone increment: Answers with verified citations and an explicit 'not found' response, tested on unanswerable questions.

Job-description skills: RAG pipelines, LLM prompting · Lab tools: openai, llama-index

1. Grounding is a contract

A grounded assistant makes three promises: it answers only from the retrieved sources, it shows which source supports each claim, and it says “not found” when the sources don’t cover the question. Each promise is enforced in code and measured, not left to a polite instruction in the prompt.

The pipeline below gates on retrieval strength, drafts an answer that cites numbered chunks, verifies each cited claim, and takes the honest path when either check fails.

Top chunks[1] … [5] with pagesGatescore ≥ threshold?Draft answercites [n] per claimVerify claimssupported by [n]?Answertext + links to pagesNot foundsay so, offer next stepAnswer only from what was retrievedThe honest pathweak or unsupported
A citation is only useful if it is checked. “Not found” is a feature: measure it on questions the documents can’t answer.

2. Prompt and schema for grounded answers

Number the retrieved chunks and include their document and page: “[3] (travel-policy.pdf, p. 1) Hotel bills above…”. Put the context before the question, tell the model to cite [n] after every sentence, and ask for structured output: a status (answered or not_found) and a list of sentences, each with its citation ids. A quote-first prompt, where the model extracts the supporting quotes before answering, makes unsupported sentences rarer and easier to check.

Several providers now offer citation features that return the exact cited spans, such as Anthropic’s Citations API, and frameworks offer citation query engines. They save work, but you still verify and you still measure.

Common misconception: “The model cited a source, so the claim is supported.” Models cite chunks that don’t say what the sentence says, and occasionally cite chunks that were never retrieved. Check every citation.

3. Verify before you show

Run cheap checks first: every cited id exists and was retrieved; every number, date and name in a sentence appears in its cited chunk. Then run a support check per sentence with a small natural-language-inference model or a judge prompt that asks only “does [n] support this sentence: yes or no?”.

Decide in advance what happens to a sentence that fails: drop it, mark it as unverified, or refuse the whole answer. For HR, legal and medical assistants, refusing is usually right. Build source links from chunk metadata in code, never from URLs the model wrote; a model-written link is an injection and phishing risk.

In production: Highlight the supporting text on the source page using the bounding boxes you kept in Module 2. Users trust answers they can check in one click.

4. The “not found” path

Retrieval scores alone make a poor “not found” detector: questions the documents don’t answer often retrieve near-identical text (a policy for employees when the question is about contractors). Combine a retrieval gate with the claim check, then tune both on a set of questions you know the documents can’t answer.

Make the refusal useful: say what you searched, what the closest document covers, and who can answer (“HR policies don’t cover contractors; ask HR Ops”). Measure two rates and show both on your dashboard: unsupported answers and needless refusals.

When should the assistant say “not found”?16 questions the policy documents answer and 8 they don’t. Each has the top re-ranker score of its best chunk. Set the score needed to answer.

Correct answers 16 · correct “not found” 3 · unsupported answers 5 · needless refusals 0

answerablenot in the documents
How many sick days do I get?0.95answered
What is the daily allowance in Mumbai?0.93answered
Who approves business class?0.91answered
Notice period after confirmation?0.90answered
Can I carry over annual leave?0.88answered
How long is maternity leave?0.87answered
Deadline for expense claims?0.85answered
Is alcohol reimbursed?0.84answered
Remote work days per week?0.83answered
I lost a taxi receipt, what now?0.79answered
When is my full and final paid?0.76answered
Do I need the VPN at a café?0.72answered
Can part-timers take annual leave?0.69answered
How early do I book a flight to Delhi?0.66answered
We adopted a baby. What leave do I get?0.64answered
Can I swap leave for my last month?0.55answered
What is the sick leave policy for interns?0.81answered, but nothing supports it
What is the per diem in London?0.77answered, but nothing supports it
Can I fly business on a 5-hour red-eye?0.74answered, but nothing supports it
How much parental leave do contractors get?0.62answered, but nothing supports it
Is there a gym reimbursement?0.58answered, but nothing supports it
What is the bonus payout date?0.47said “not found”
How do I change my bank account for salary?0.33said “not found”
What's the office Wi-Fi password?0.21said “not found”
Guided experiments
  1. Without the claim check, find the lowest threshold with zero unsupported answers. How many good questions does it refuse? Would users trust this assistant, or give up on it?
  2. Why do “sick leave for interns” and “per diem in London” score so high when the documents don’t answer them? What does that tell you about using retrieval scores as a confidence measure?
  3. Turn on the claim check and lower the threshold until something slips through. Which question is it, and why does a near-identical policy for employees fool the checker?
  4. Pick your production setting. Which error is worse for an HR assistant: a confident wrong answer or a “not found” that sends someone to HR?

5. Measure citation quality

Citation precision is the share of citations that support their sentence. Citation recall is the share of sentences needing support that cite a supporting chunk. Track the unsupported-sentence rate alongside them. Label 50 answers by hand to calibrate any automatic checker you use, exactly as in Module 8.

Add these metrics to the CI gate. A prompt change that makes answers longer often lowers citation precision without touching retrieval metrics; without the measurement you would never see it.

Hands-on: coding window

The coding window and the full VS Code lab are available after you sign in.

Sign in to code

Labs

Lab 9.1: Grounded output

Change the capstone generator to return the GroundedAnswer schema with numbered, page-referenced chunks and a quote-first prompt.

Expected: Every answer sentence carries at least one citation; not_found returns no sentences.

Lab 9.2: Verifier and metrics

Add id, number and support checks. Label 40 answers by hand and compute citation precision, citation recall and unsupported-sentence rate before and after the verifier.

Expected: A before-and-after table and the policy you chose for flagged sentences.

Lab 9.3: Not found, tested (capstone increment)

Tune the retrieval gate and verifier on 15 unanswerable and 45 answerable questions, return citations as page links built from metadata, and add the unanswerable set to CI.

Expected: /ask returns not_found with a useful next step for the unanswerable set; the CI check fails if any is answered.

Go deeper

Videos

Further reading

GitHub repositories

Checkpoint quiz

1. The model cites [4] but only chunks 1–3 were retrieved. What should your code do?
2. Why build source links from metadata rather than letting the model write URLs?
3. Why isn’t a retrieval score threshold enough for “not found”?
4. Citation precision measures…
5. A prompt change made answers longer. Which metric is most likely to drop?

Interview questions

  1. How do you make a RAG system cite its sources reliably?
  2. How would you detect that a question can’t be answered from the documents?
  3. Design a verifier for answer citations. What do you check cheaply, and what needs a model?
  4. What do you show the user when part of an answer is unsupported?
  5. How do you measure and monitor citation quality in production?

Ask the professor

Sign in to ask questions about this module.

Discussion

Community discussion appears here once giscus is configured (see README).