← All questions
RAGMedium· Production RAG

How do you add reliable citations and source attributio...

The reliable pattern combines two layers, because either one alone has a failure mode. Inline citation prompting instructs the model, as part of the system prompt, to tag each claim with a numbered source marker as it generates — “after each claim, cite [Source N]” — which works most of the time but can’t be fully trusted on its own, since the model can occasionally misattribute a claim or cite the wrong source. Post- processing verification runs a separate pass after generation to check which retrieved sources actually support which claims in the answer, catching the cases inline prompting alone would miss.

Both layers depend on the retrieval step doing its part first: chunks need to be tagged with document name, page number, and section at indexing time so there’s something concrete to cite back to, and a numbered reference list at the end of the response gives the user something they can actually check. This matters more than it sounds like in regulated domains — legal, healthcare, finance — where a confident-sounding answer without a verifiable source is a liability, not a convenience, and users need the ability to trace a claim back to its origin rather than simply trust it.

Code playground (Python)