CONCEPT A prompt has parts, and their order matters
A well-structured prompt is assembled from recognizable elements, and Anthropic recommends a canonical order for them. Putting each piece where it belongs makes the prompt easier for the model to parse and measurably improves output quality. The recommended sequence:
| # | Element | What it is |
|---|---|---|
| 1 | Task context | Role, background, the situation the model is operating in |
| 2 | Tone | The voice/style the response should take |
| 3 | Detailed instructions | The rules and steps to follow |
| 4 | Examples | Few-shot demonstrations, wrapped in tags |
| 5 | Input data / documents | The material to operate on |
| 6 | Immediate task / request | The specific ask, placed last |
CONCEPT Long documents go near the top; the request goes last
The one placement rule the exam loves: put long-form data near the top of the prompt, above your query, instructions, and examples. Anthropic: "Place your long documents and inputs near the top of your prompt, above your query, instructions, and examples. This improves performance across all models." And the payoff is quantified: "Queries at the end can improve response quality by up to 30% in tests, especially with complex, multi-document inputs."
So the immediate request lands last — after the model has ingested the context and the
documents. The reference table above lists input data at step 5 for a compact prompt; when that data is a
large document (20k+ tokens), hoist it to the very top and keep the actual question at the bottom.
Wrap each document in <document> tags with <source> and
<document_content> subtags so the model can tell material from instructions.
DIAGRAM Element order, top to bottom
(role · background)"] --> B["② Tone"] B --> C["③ Detailed instructions"] C --> D["④ Examples
(<example> tags)"] D --> E["⑤ Input data / documents"] E --> F["⑥ Immediate task / request
(placed LAST)"] LD["📄 Long documents (20k+ tokens)"] -.->|"hoist near the TOP,
above query & examples"| A classDef top fill:#cfe2ff,stroke:#0d6efd,color:#084298; classDef last fill:#d4edda,stroke:#28a745,color:#155724; classDef doc fill:#ffe8cc,stroke:#ff9f40,color:#9a4a0a; class A top; class F last; class LD doc;
CODE The anatomy assembled — long doc up top, request last
Note the ordering: context/role and tone first, then instructions and an example, the document near the top of the input block, and the actual question at the very bottom.
system = ( # ① Task context / role "You are a contracts analyst supporting a procurement team. " # ② Tone "Write in precise, neutral, professional language.\n\n" # ③ Detailed instructions "Follow these steps:\n" "1. Identify the termination clause.\n" "2. Quote the exact text before summarizing.\n" "3. Flag any auto-renewal terms.\n\n" # ④ Example (few-shot, tagged) "<example>Clause: '30 days written notice.' → Summary: ...</example>" ) user = ( # ⑤ Input data — the LONG document goes near the TOP of the input. "<documents>\n" " <document index='1'>\n" " <source>msa_2026.pdf</source>\n" " <document_content>{{FULL_CONTRACT_TEXT}}</document_content>\n" " </document>\n" "</documents>\n\n" # ⑥ Immediate task / request — placed LAST (up to +30% on complex inputs). "Summarize the termination and renewal terms of the contract above." )
TRADE-OFFS Canonical ordering vs. ad-hoc layout
✅ Canonical order, doc-up-top
- Model parses each element unambiguously
- Query-last is worth up to ~30% on multi-doc tasks
- Long data near the top improves performance across all models
- Easy to template and reuse
⚠️ Ad-hoc / request-first
- Quicker to dash off
- Question before the data → model answers with less grounding
- Instructions tangled with material → misinterpretation
- Inconsistent across prompts, hard to iterate on
EXAM TRAPS
<document>, <example>) so the model
separates material from instructions.PRACTICE
Q1 · Give the recommended element order for a prompt.
Task context (role/background) → tone → detailed instructions → examples → input data / documents → immediate task/request (last). Long documents are the exception to "middle": hoist them near the top of the input.
Q2 · Where do long documents go, and where does the actual question go?
Long documents near the top of the prompt, above the query, instructions, and examples; the question goes last. Anthropic reports query-at-the-end can improve response quality by up to 30% on complex, multi-document inputs.
Q3 · Is prompt element order just cosmetic?
No — it's a measurable performance lever. Long data near the top "improves performance across all models," and placing the query last yields up to a 30% quality gain on complex multi-document tasks. Structure the prompt deliberately, wrapping documents and examples in XML tags.