DEV Community

Naeem Okpara Rashidi
Naeem Okpara Rashidi

Posted on

Building a Grounded RAG Assistant: Why Citation Enforcement Matters More Than Retrieval

Most RAG tutorials focus on retrieval quality: better embeddings, better chunking, better reranking. What they skip is the part that determines whether users trust the output: what happens when the retrieved context doesn't actually answer the question.

When I built a RAG assistant delivered over WhatsApp, backed by vector search over PostgreSQL with pgvector, the retrieval pipeline was the easy part. The hard part was what I'd call the confidence problem: LLMs sound certain even when the retrieved context is thin or missing. A demo tolerates that. A production assistant answering real users doesn't.

The fix was structural, not prompt-based. Instead of asking the model to "only answer based on the provided context," I enforced a structured JSON output where every claim had to carry a citation pointing to a specific retrieved chunk. If the model couldn't populate that field, the response was rejected before reaching the user, and the system fell back to "I don't have enough information to answer that."

This shifts the whole design conversation from optimizing retrieval recall to closing the gap between what was retrieved and what the model is allowed to claim:

  • Chunking got more conservative, since vague chunks produce unciteable claims.

  • The system prompt got shorter, since enforcement moved from instructions to schema validation.

  • Failure became visible instead of silent: a bad retrieval now produces "I don't know," not a confident wrong answer.
    Retrieval quality gets you a demo. Citation enforcement gets you something you can put in front of real users without babysitting it.

Top comments (2)

Collapse
 
hannune profile image
Tae Kim

The move from instructions to schema validation is the right frame, but there is a level below it worth adding: a populated citation field and a grounded citation field are not the same thing. A model that is forced to cite will find a citation — sometimes the right one, sometimes the closest chunk that does not actually support the claim. The enforcement step catches uncited claims; it does not catch cited-but-unsupported ones. A lightweight post-generation check — re-scoring the cited chunk against the claim it was cited for — closes that gap, and it runs on output you already have.

Collapse
 
jupitersoft profile image
Jupiter Soft

I agree that grounding cannot depend only on a prompt asking the model not to hallucinate. The constraint has to be enforced by the system.

Citation enforcement is an important step because it makes the origin of a claim visible. But a citation proves where the information came from, not necessarily that the information is correct, current, or officially accepted.

For organizational AI, we also need to know who approved the claim, which version is active, what exceptions exist, and within which boundaries it may be applied.