Given a question and a set of numbered context chunks, have the model answer the question and cite the chunk numbers it used inline, so every claim can be traced back to its source.
Citations are what make a RAG answer auditable. Without them, a user has no way to tell which parts of an answer came from the documents and which the model produced on its own. Numbering the chunks and asking the model to reference those numbers turns the answer into something a reader can verify against the original sources.
[1], [2], [3], and so on.The answer reads naturally and carries bracketed citations that point at the chunks each claim came from.
Numbering the chunks gives the model a stable label to point at, and the system prompt makes the citation a required part of the format rather than an afterthought. The result is a grounded answer where each claim names its source, so a reader can jump straight to chunk [2] to confirm the recommendation rather than taking the model's word for it.
Generating citations is only useful if you can check them. After the model answers with bracketed chunk numbers, parse those citations out and verify each one points at a real chunk. This is the programmatic grounding check that catches a model citing a chunk that does not exist.
[n] citations.The answer carries citations, and the validation confirms each cited number refers to a real chunk.
The regex \[(\d+)\] pulls every bracketed number out of the answer, and checking each against the valid range turns citations from decoration into something you can audit automatically. A citation pointing at a nonexistent chunk is a clear hallucination signal worth flagging or rejecting. This parse-and-verify step is what lets you trust citations at scale instead of spot-checking them by hand.