The generation prompt is where retrieved context becomes an answer. Its structure affects faithfulness, citations and tone.
A Reliable Structure
- Role and audience: who the assistant serves.
- Grounding rules: answer only from the documents; say when the answer isn't there.
- The documents, clearly delimited, each with an ID, title, date and source.
- The question.
- Output requirements: length, format, citation style.
Example
You answer employees' questions about HR policy.
Use only the documents below. Cite document IDs in square brackets after each claim.
If the documents don't answer the question, say "I couldn't find that in the policies"
and suggest contacting HR.
<documents>
<doc id="1" title="Leave Policy" updated="2026-03-01">...</doc>
<doc id="2" title="Travel Policy" updated="2025-11-12">...</doc>
</documents>
Question: How many days of annual leave do part-time staff get?
Order Documents Sensibly
Put the most relevant documents first or last; models can pay less attention to material buried in the middle of long contexts.
Handle Conflicts
Tell the model what to do when documents disagree — prefer the most recent, and mention the conflict.
Keep It Versioned
Store templates in version control and re-run your evaluation set whenever they change.
Don't Overload
Including more documents isn't always better. Irrelevant context can reduce accuracy; re-rank and keep the most relevant.