Course contentsShow
← AI Engineering
Lesson 367 of 1,8869. Retrieval-Augmented Generation (RAG) - BasicsFree lesson

Handling Missing or Hallucinated Citations

Detecting when the LLM fails to cite sources or invents non-existent references and implementing fallback strategies.

Handling Missing or Hallucinated Citations

What You'll Learn

You'll learn how to detect when your LLM fails to cite sources or invents fake references, and how to implement fallback strategies to maintain trust in your RAG system.

The Problem with Citation Failures

Even when you've carefully tracked document metadata and prompted your LLM to cite sources, things can go wrong. The model might:

  • Omit citations entirely despite retrieving relevant documents
  • Hallucinate references by inventing sources that don't exist in your knowledge base
  • Misattribute information to the wrong document

Think of it like a student who either forgets to cite their sources or makes up fake references to look more credible—both undermine trust.

Detection Strategies

Validate Against Retrieved Sources: After generation, programmatically check that every citation the LLM mentioned actually exists in your retrieved document metadata. If the model cites "Document-789" but you only retrieved "Document-456" and "Document-123", that's a hallucination.

Pattern Matching: Parse the LLM's output for citation markers (like [1], [Source: ...], etc.) and verify each one maps to a real chunk ID or document title.

Empty Citation Check: If your retrieved context is non-empty but the response contains zero citations, flag this as a potential issue.

Fallback Strategies

When detection fires:

  • Regenerate with stronger instructions: Re-prompt with explicit "YOU MUST cite sources" language
  • Append citations programmatically: If the answer is factually correct but uncited, inject citations yourself based on chunk relevance scores
  • Show a warning: Display "Answer generated without citations" to maintain transparency
  • Fall back to retrieval-only: Return just the raw retrieved documents instead of a generated answer

Key Takeaway: Citation failures erode user trust—always validate LLM citations against your actual retrieved documents and implement fallback strategies to either fix or flag unreliable outputs.