Course contentsShow
← AI Engineering
Lesson 417 of 1,88611. RAG - Improving GenerationFree lesson

Citation Instructions and Formatting

Learn to prompt models to cite sources accurately using retrieved document identifiers or metadata.

Citation Instructions and Formatting

What you'll learn: How to guide language models to cite retrieved sources accurately by embedding clear citation rules and document identifiers in your RAG prompts.

Why Citation Instructions Matter

When a model generates an answer using retrieved documents, it doesn't automatically know how you want it to cite those sources. Should it use numbered references like [1]? Document IDs? Inline URLs? Without explicit instructions, models may improvise inconsistently—or skip citations entirely.

Think of it like giving a research assistant specific formatting guidelines: "When you reference a source, use this exact format." The clearer your instructions, the more reliable the citations.

Core Citation Strategies

1. Document Identifiers in Context Include unique IDs or metadata with each retrieved chunk:

Document [doc_123]: "AI ethics require transparency..."
Document [report_2024_q1]: "Revenue increased 15%..."

2. Explicit Prompt Instructions Tell the model exactly how to cite:

"Answer using only the provided documents. 
Cite sources using the format [doc_id] after each claim.
Example: 'Revenue grew 15% [report_2024_q1].'"

3. Format Specification Be prescriptive about citation style:

  • Numbered: "AI is transforming industries [1]"
  • Named: "According to the Ethics Report..."
  • Inline: "As stated in [doc_123, page 5]..."

4. Multiple Citation Handling Instruct how to cite multiple sources: "When multiple documents support a claim, list all sources: [doc_1][doc_2]"

Key Formatting Elements

Include in your retrieved context metadata:

  • Document ID or slug
  • Title (for readability)
  • Page numbers (if applicable)
  • Timestamps (for time-sensitive content)

Key Takeaway: Explicit citation instructions in your prompt template—combined with clear document identifiers in the retrieved context—ensure models cite sources consistently and verifiably.