Lesson 3.2 · 7 min read · about 50 min to master at a very slow pace
Building the Prompt: Context, Citations and Refusals
How to lay out retrieved passages in the prompt, make the model cite them, and make it say "I don't know" when the answer is not in the sources. A complete RAG system prompt, explained line by line.
A system prompt that works
You answer questions for employees of Acme Logistics
using ONLY the numbered sources provided.
Rules:
1. Every factual sentence ends with its source number, e.g. [2].
2. If the sources do not contain the answer, say:
"I couldn't find this in the company documents."
and suggest who to ask. Do not use outside knowledge.
3. If sources disagree, say so and prefer the most recent one.
4. Be concise: at most 150 words unless asked for more.
Each rule fixes a known failure: rule 1 makes answers checkable, rule 2 stops invented answers, rule 3 handles outdated documents, rule 4 controls cost and latency.
Laying out the sources
Give each chunk a number and a label the user will recognise:
[1] Travel Policy 2026, section 4.2 (updated 2026-03-01)
Economy class is required for flights under 6 hours...
[2] Expenses FAQ, "Meals abroad"
The daily meal allowance outside Slovenia is...
Your application then maps "[1]" back to a link. Check after generation that every cited number exists; a citation to [7] when you sent five sources is a hallucination you can catch automatically.
How much context to send
More chunks raise the chance the answer is present, but also raise cost, latency and distraction. Models attend best to the start and end of a long context and less reliably to the middle ("lost in the middle"). Practical guidance:
- Send the 3–8 best chunks after reranking, not 30 mediocre ones.
- Put the most relevant chunk first, and the question after the sources.
- Drop near-duplicate chunks; they waste tokens and over-weight one source.
Refusals are a feature
A system that says "I couldn't find this" when the documents are silent is worth more to a client than one that always answers. Measure both sides: how often it answers questions it should answer, and how often it refuses questions it cannot answer (Section 5).
Over-refusal
Strict grounding rules can make the model refuse answerable questions, especially when the answer needs combining two chunks. If refusals rise, look at retrieval first (was the evidence sent?), then soften the rule ("answer if the sources support it, even partly, and say what is missing").
Stuck? Common doubts
Questions real learners asked while studying this lesson. They stay closed so they don't spoil your own thinking: open only the ones you need.
First passShould citations be per sentence or per answer?
Per sentence (or per claim) where possible. Users can check the exact claim, and your evals can verify each claim against its cited source. A single list of sources at the end hides which source supports which statement.
Going deeperWhere should the retrieved chunks go: system or user message?
Usually the user message, because they change with every question; the system message holds the fixed rules. This also keeps the system prompt identical across requests so it can be cached. Mark the sources clearly as data, which also helps against prompt injection hidden in documents (lesson 4.4).
Cheatsheet
RAG prompt rules
Context layout
Fake citations
Check your understanding
Score 75% or more to master this lesson and earn XP. Answer first, then check.