Sub topic 1
What Grounding Means and Why Citations Help
Prerequisites
This chapter assumes you can read basic Python and have called a large language model (LLM) through an API. You should know roughly what retrieval-augmented generation (RAG) is, and you should be comfortable reading JSON. No code needs to be run in this chapter.
What grounding means
A grounded answer is one whose claims are supported by the documents the model was given for that question. If the answer says "the service retries failed requests up to three times," a grounded answer has a passage in the supplied sources that says so.
Grounding is the opposite of a hallucination. A hallucination is a statement the model produces that sounds plausible but has no support in the sources, or in reality. Models hallucinate because they predict likely text. They do not look facts up. When the supplied documents are silent, the model may fill the gap from its training data or invent a detail.
Grounding is a property of the answer and its sources together. You can't judge it by reading the answer alone.
Why citations help
A citation is a pointer from a statement in the answer to the source that supports it. Citations give you three things:
- Traceability. A reader can open the source and check the claim.
- Debuggability. When an answer is wrong, you can see whether retrieval failed or the model misused good material.
- Hooks for automation. Code can parse citations and check them, which later chapters do.
Citations in the pipeline
In a RAG system, a retriever finds passages (chunks) relevant to the question. Your code puts them into the prompt, and the model writes an answer. Citations connect the last step back to the second.
The numbering happens in your code, before the model sees anything. The model only repeats the numbers it was given. This is why your code can check them afterward.
A small example
Suppose the retriever returns two chunks, and your code labels them [1] and [2]. The model answers:
Failed requests are retried up to three times [2]. Timeouts default to 30 seconds [1].Your code can now check two things. First, do both numbers exist? Second, does source 2 really say anything about retries? The first check is simple. The second takes more work, and later chapters show how to do it.
What citations cannot fix
Citations do not improve the retrieved material. If the retriever returns the wrong chunks, the model can only cite wrong chunks, or answer from memory. Grounding quality is capped by retrieval quality.
Exercise
A model answers a question and adds "[3]" after a claim. Your prompt contained only two sources. What does this tell you, and does a valid marker such as "[1]" prove the claim is grounded?
Show answer
The marker "[3]" is an invalid citation, because no third source was supplied, so the model fabricated it. A valid marker such as "[1]" does not prove grounding. It only shows the number exists. You must still check that source 1 supports the claim.