A RAG answer with a citation looks trustworthy: "Hardware is covered for 24 months [d2#0]." But the model writes the citation the same way it writes everything else. It can cite a chunk you never sent it, or skip citing altogether, and the answer still reads fine.
This post builds a small retrieval-augmented generation (RAG) pipeline in C# and adds a check in code: every answer must cite at least one chunk, and every cited id must belong to a chunk we actually retrieved. Answers that fail the check never reach the user.
You need to know C#. You don't need to have built RAG before.…