Long-Context Ordering
Definition
For large / data-rich inputs (20k+ tokens), place longform documents at the top of the prompt and put the query, instructions, and examples last — improving response quality across all models.
Key points
- Documents first, query last. Placing the query at the end can improve response quality by up to 30% in tests, especially with complex, multi-document inputs.
- Structure each document with XML: wrap in
<document>tags with<document_content>and<source>(plus other metadata) subtags; the canonical form is<documents>→<document index="1">→<source>+<document_content>— see XML Structuring. - Ground responses in quotes: ask Claude to first quote relevant parts of the documents (e.g. into
<quotes>tags) before performing the task, to cut through noise. - Relates to the "lost in the middle" effect — attention is strongest at the start and end, so the query at the end stays salient.
Why it matters for the exam
- "Documents first / query last, up to 30%" is a near-guaranteed, verbatim D4 fact.
- Structured Data Extraction and multi-document RAG scenarios test exactly this ordering.
Common gotchas
- Putting the query before the documents is the wrong answer for long context.
- The 30% figure is tied to long, multi-document inputs — not a blanket claim for short prompts.
See also
Sources
Referenced by
Practice questions optional · AI
Generate fresh practice questions about this concept with AI. These are not vault-verified.