
Prompt Engineering for RAG: How Should You Prompt an AI That Has Retrieved Documents?
Retrieval can hand the model the exact right document and still get a wrong answer, if the prompt around that document doesn't do its half of the job.
RAG From Scratch builds the retrieval half of this system by hand, chunking, embeddings, a vector store, a similarity threshold. This post picks up exactly where that one hands off: documents have already been retrieved, correctly, and the question is what to actually do with them in the prompt, because a perfect retrieval and a bad prompt still produces a wrong answer.
The one sentence to remember
Retrieval's job is finding the right documents. The prompt's job is making sure the model actually uses them, admits it when they don't contain the answer, and shows its work. Getting retrieval right doesn't do any of that for you.
The Full Path
Context Boundaries
Retrieved documents are exactly the External Content layer, information to reason from, never instructions to follow, and the same delimiter discipline covered for any untrusted content applies here directly: wrap retrieved chunks in a clear, consistent boundary, and label each one with its source.
Context:
[Source: deployment-runbook.md]
{chunk text}
[Source: incident-2026-03.md]
{chunk text}
Question: {question}A model working from an unlabeled wall of retrieved text has no way to tell where one document ends and another begins, which is exactly what makes citation and conflict detection unreliable later in the same prompt.
Source Grounding: "Answer Only From Supplied Context"
The phrase alone is doing less work than it looks like
"Answer using only the context below" is a real, useful instruction, and it's also just a request. A model with strong prior knowledge about a topic can still blend in something it learned during training rather than something actually present in the retrieved chunks, especially when the retrieved context is thin and the training-data answer is confident. Grounding is a matter of degree, reinforced by structure, not guaranteed by one sentence.
State the constraint, then make it costly to ignore
Follow "answer only from the context below" with an explicit consequence: "if you use information not present in the context, say so." This doesn't make violation impossible, but it removes the easy path of blending training knowledge in silently.
Ask for the supporting quote, not just the answer
Requiring the model to name which part of the context supports each claim makes fabricating an answer with no real source noticeably harder than just answering confidently, since there's now a second, checkable claim ("this is where I found it") sitting next to the first one.
Missing Information
A RAG prompt with no instruction for 'not in the documents' will still produce an answer
Asked a question the retrieved context doesn't actually cover, a model with no explicit permission to say so will often produce a fluent, plausible-sounding answer anyway, since nothing in the prompt told it that's the wrong move. RAG From Scratch's own prompt template handles this directly: "if the context doesn't contain enough information to answer, say so explicitly rather than guessing." That one sentence is the difference between an honest gap and a confident hallucination.
Conflicting Documents
A question a retrieval-based system will eventually hit that a single-document prompt never has to: two retrieved chunks that disagree, an old policy document and its replacement, two versions of a runbook, a draft and a final. Silently picking one is worse than answering "I don't know," because it looks confident while being arbitrary.
Instruct the model to surface the conflict, not resolve it silently
"If retrieved documents disagree, state the conflict explicitly and cite both sources, rather than picking one answer" turns a silent, arbitrary pick into a visible signal the person asking can actually act on, checking which document is current, which is exactly the kind of judgment a retrieval system has no way to make on its own.
Citations
Citing "the documents" isn't a citation. Citing which specific source, and ideally which specific claim came from which source, is what makes an answer checkable rather than just plausible.
Output format:
Answer the question directly, then list each claim with its
source in brackets, like this: "Rollback requires a manual
approval step [deployment-runbook.md]."The same discipline covered for any output format applies directly here: naming the exact citation format, inline brackets, a footnote list, a structured field, gets a consistent, parseable result. Asking generically for "sources" gets a different format every time.
Retrieval Quality vs. Prompt Quality
A wrong RAG answer is one of two different bugs, and they need different fixes
RAG From Scratch draws this distinction directly: a wrong answer from a failed retrieval (the right document was never fetched) is a search problem. A wrong answer from a correct retrieval (the right document was fetched, and the model still got it wrong) is a prompt problem. Conflating the two means a real retrieval bug gets "fixed" by rewording a prompt that was never broken, or a real prompt bug gets chased with retrieval tuning that was never going to help.
| Symptom | Likely cause | Where to look |
|---|---|---|
| The answer is confidently wrong, and the right document was never in the retrieved set | Retrieval | Chunk size, similarity threshold, embedding model |
| The right document was retrieved, but the answer ignores it or blends in outside knowledge | Prompt | Grounding instruction, context boundaries |
| The answer doesn't mention that documents disagreed | Prompt | Missing conflict-handling instruction |
| The answer is a confident guess when nothing relevant was actually retrieved | Prompt | Missing "say so if the context doesn't contain enough information" instruction |
| Citations are vague or inconsistent between runs | Prompt | Unspecified citation format |
Before changing anything, check which document actually made it into the context for that specific query. That one check almost always tells you immediately which half of this table you're actually debugging.
A Complete Worked Template
Every technique in this post, combined
Answering only from context, admitting a gap explicitly, surfacing a conflict instead of hiding it, and citing every claim, all five techniques from this post in one template.
You are answering questions using only the context provided below.
Answer only from this context, if it doesn't contain enough
information to answer, say so explicitly rather than guessing. If
sources disagree, state the conflict explicitly and cite both. Cite
the specific source for every claim using the format [filename].
Context:
[Source: {name}]
{chunk}
Question: {question}Every sentence in that template maps to a real failure mode covered above: the first line sets the boundary, the second forces an honest gap instead of a guess, the third surfaces disagreement instead of hiding it, and the fourth makes every claim checkable.
The Bottom Line
RAG's reputation for still hallucinating despite "having the right documents" is usually a prompt problem wearing a retrieval costume. Retrieval did its job, found the right chunk, but the prompt around it never told the model what to do when the context was incomplete, contradictory, or simply present, and the model filled that silence with its own confident guess. The fix isn't better retrieval. It's a prompt that draws the same boundaries this post walks through, every single time context is retrieved and handed off.
The test worth running on your own RAG prompt
Ask it a question your documents actively contradict on, an old policy versus a new one, and see what comes back. If it picks one silently, that's not a retrieval gap, it's a missing instruction, and now you know exactly which line to add.
Has a RAG system you've built ever answered confidently from the wrong document, or blended in an answer that wasn't actually in what got retrieved? Drop a comment with what the prompt was missing.
Written by
Chetan Yamger
Cloud Engineer · AI Automation Architect · Modern Workplace Consultant
Cloud Engineer, AI Automation Architect, and Modern Workplace Consultant based in Amsterdam, Netherlands. Specializing in scalable, secure enterprise solutions with Microsoft Azure, Intune, PowerShell, and AI-driven automation using ChatGPT, Gemini, and modern LLM technologies.
Stay in the loop.
New articles, straight to you.
Deep-dive technical articles on Intune, PowerShell, and AI — no noise, no spam.
Discussion
Share your thoughts — your email stays private
Leave a comment