D4 · Prompt Engineering › Cluster 1 · Foundations & Being Clear

1.5 · The Prompt Anatomy (Element Order)

Where each piece goes

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:

#ElementWhat it is
1Task contextRole, background, the situation the model is operating in
2ToneThe voice/style the response should take
3Detailed instructionsThe rules and steps to follow
4ExamplesFew-shot demonstrations, wrapped in tags
5Input data / documentsThe material to operate on
6Immediate task / requestThe specific ask, placed last
🔑 Read top to bottom, it flows like onboarding a person: here's who you are and how to sound → here are the rules → here's what good looks like → here's the material → here's exactly what I need now.

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.

Rule of thumb: long documents first, question last. The model reads the material, then receives the ask fresh at the end — worth up to 30% on complex multi-document tasks.

DIAGRAM Element order, top to bottom

flowchart TD A["① Task context
(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
🔑 The two load-bearing placements: long documents near the top, and the immediate request at the very bottom.

EXAM TRAPS

Trap: Putting the question before the long document. → Reverse it. Long data near the top, query last — Anthropic measures up to a 30% quality gain from query-at-the-end on complex, multi-document inputs.
Trap: Interleaving instructions, examples, and raw data with no structure. → Use the canonical order and XML tags (<document>, <example>) so the model separates material from instructions.
Trap: Treating element order as cosmetic. → It changes results. Ordering is a performance lever, not formatting preference — especially the query-last placement.
Trap: Assuming "input data at step 5" means a big document goes in the middle. → For long documents specifically, hoist them to the top of the input, above query and examples.

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.