CONCEPT Where you put the documents changes the answer
When a prompt carries large documents or data-rich inputs (~20K+ tokens), placement is a first-class lever, not a formatting detail. Anthropic's long-context guidance is three concrete rules, and the exam rewards knowing all three:
| Rule | What to do | Why it works |
|---|---|---|
| Longform data at the top | Place long documents and inputs near the top of the prompt, above the query, instructions, and examples. | "Improves performance across all models." |
| Query at the end | Put the question after the documents. | Can improve response quality by up to 30% in tests, especially with complex, multi-document inputs. |
| Quote first | Ask Claude to quote the relevant passages before doing the task. | Helps Claude "cut through the noise" of the rest of the document. |
CONCEPT Wrap each document in tags with metadata
For multi-document prompts, wrap each document in <document> tags with
<document_content> and <source> (and any other metadata) subtags, nested inside
a <documents> container with an index attribute per document. Structure gives the model
clean boundaries — it can tell where one source ends and the next begins, and it can attribute quotes back to a
named <source>.
<source>, index numbers, dates) cost almost nothing and pay
off in attribution: when you later ask Claude to "quote from patient_records.txt", the tag names give it
a handle to cite by.DIAGRAM The canonical long-context prompt shape
<documents> … </documents>
each in <document> + <source>"] T --> M["Instructions / few-shot examples"] M --> Q["🔵 BOTTOM: the query
(+ 'quote relevant passages first')"] Q --> R["Response quality
up to +30% vs query-on-top"] classDef ok fill:#d4edda,stroke:#28a745,color:#155724; classDef gate fill:#ffe8cc,stroke:#ff9f40,color:#9a4a0a; classDef bad fill:#f8d7da,stroke:#dc3545,color:#721c24; class T ok; class Q gate; class R ok;
CODE Assembling a long-context prompt
Documents rendered at the top of the user turn, wrapped and tagged; the query and a quote-first instruction go
last. Note the cache_control breakpoint on the stable document block so repeat questions over the same
corpus read from cache.
# Docs on TOP, query on the BOTTOM — the +30% ordering. docs = """<documents> <document index="1"> <source>annual_report_2023.pdf</source> <document_content>{annual_report}</document_content> </document> <document index="2"> <source>competitor_analysis_q2.xlsx</source> <document_content>{competitor}</document_content> </document> </documents>""".format(annual_report=rpt, competitor=comp) resp = client.messages.create( model="claude-opus-4-8", max_tokens=4096, messages=[{"role": "user", "content": [ {"type": "text", "text": docs, # TOP: long data "cache_control": {"type": "ephemeral"}}, # reuse across questions {"type": "text", "text": # BOTTOM: query + quote-first "First, pull the passages relevant to Q3 strategy into " "<quotes> tags. Then recommend focus areas in <plan> tags."}, ]}], )
TRADE-OFFS Structured placement vs. dump-and-ask
✅ Docs-top, query-bottom, quote-first
- Up to +30% quality on complex multi-doc inputs
- Named sources → attributable quotes
- Stable prefix caches cleanly for repeat queries
⚠️ Query-on-top, raw concatenation
- Model reads the question before it has the evidence
- No boundaries → mid-prompt content gets lost (4.2)
- Harder to ground or cite specific passages
EXAM TRAPS
<document> with
<document_content> and <source> subtags — boundaries and metadata matter.PRACTICE
Q1 · Where do the long documents go, and where does the query go?
Long documents go near the top of the prompt, above the query, instructions, and examples. The query goes at the end. This query-at-the-end ordering can improve response quality by up to 30% on complex, multi-document inputs.
Q2 · What token threshold triggers this "long context" advice?
Roughly 20K+ tokens — "large documents or data-rich inputs." Below that, ordering matters less; at 20K+ the placement rules and the quote-first technique start paying off meaningfully.
Q3 · Why ask Claude to quote relevant passages before answering?
It helps Claude cut through the noise of the rest of the document — the model surfaces the
load-bearing evidence first, then reasons over that focused set instead of the whole corpus. Pair it with tagged
<source> metadata so quotes are attributable.