Skip to content
ML Academy

LLMs, GenAI, RAG, agents, evaluation · insight-0614

Validate citation ids in code before showing a cited answer

Evidence type
empirical finding
Difficulty
easy
Roles
Applied AI, ML engineer
Industries
healthcare, insurance

Summary: situation, action, reason, boundary

  1. Situation

    Your RAG prompt asks the model to cite sources as [doc-id] markers.

  2. Action

    Give every context chunk a stable id, parse the citations from the output, reject or flag ids not present in the provided context, and render the cited source text next to the claim.

  3. Reason

    Citation markers are generated text like any other. Liu, Zhang and Liang found that only about three quarters of citations in audited generative search engines supported the sentence they were attached to.

  4. Boundary

    Any user-facing answer that shows sources, especially in regulated domains.

Symptom or risk

Answers cite ids that were never retrieved, cite the wrong chunk, or leave key sentences uncited, and the interface displays them as if verified.

Exceptions

Internal brainstorming tools where citations are a convenience rather than a control.

Trade-offs

An id check catches fabricated references but not misattributed ones; support still needs sampled review.

Pitfalls

Treating "has a citation" as "is grounded".

Lessons and concepts

Claims and their sources