CONCEPT Three rules for large, data-rich prompts
When you work with large documents or data-rich inputs — roughly 20K+ tokens — the official long-context guidance boils down to three moves that stack on everything in this cluster:
| Rule | What to do | Why |
|---|---|---|
| Longform data at the TOP | Place long documents near the top of the prompt, above your query, instructions, and examples. | Improves performance across all models; queries at the end can improve response quality by up to ~30% in tests, especially on complex multi-document inputs. |
| Wrap each doc with metadata | Put each document in <document> tags with <document_content> and <source> (and other metadata) subtags. | Gives structure Claude can navigate and cite (builds on 4.4 nesting). |
| Quote first, then answer | Ask Claude to pull relevant quotes into <quotes> before doing the task. | Helps Claude cut through the noise of the surrounding text and ground its answer. |
CONCEPT Grounding responses in quotes
For long-document tasks, instruct Claude to first find and quote the relevant passages —
placed in <quotes> tags — and only then produce its answer (e.g. in <info>
or <answer> tags). Quoting first forces Claude to locate its evidence in the noise before
reasoning over it, which improves accuracy and gives you a traceable link from claim back to source.
DIAGRAM Long-context prompt order
each <document> with
<source> + <document_content>
(the 20K+ token bulk)"] DOCS --> STEP["<instructions>
1) put quotes in <quotes>
2) then answer in <info>"] STEP --> Q["🟢 <query>
the actual question — LAST"] Q --> B["BOTTOM of prompt"] classDef ok fill:#d4edda,stroke:#28a745,color:#155724; classDef step fill:#e7f0ff,stroke:#4a90d9,color:#123; class DOCS,Q ok; class STEP step;
CODE Docs at top, query at bottom, quote-first
Mirrors the official quote-extraction pattern: documents (with sources) first, then instructions that ask
for quotes in <quotes> before the diagnostic answer in <info>, with the
query at the end.
You are an AI physician's assistant that helps doctors diagnose illnesses.
<documents>
<document index="1">
<source>patient_symptoms.txt</source>
<document_content>
{{PATIENT_SYMPTOMS}}
</document_content>
</document>
<document index="2">
<source>patient_records.txt</source>
<document_content>
{{PATIENT_RECORDS}}
</document_content>
</document>
</documents>
<instructions>
Find quotes from the patient records that are relevant to the reported symptoms
and place them in <quotes> tags. Then, based on those quotes, list the
information that would help the doctor diagnose, in <info> tags.
</instructions>
<query>
What are the most likely diagnoses to investigate first?
</query>
Assembled in a Messages API call, the token-heavy documents lead the user turn and the query trails it:
import anthropic client = anthropic.Anthropic() user_content = ( docs_block # <documents>…</documents> — 20K+ tokens, goes FIRST + instructions_block + query_block # the question — goes LAST ) msg = client.messages.create( model="claude-opus-4-8", max_tokens=2048, messages=[{"role": "user", "content": user_content}], )
TRADE-OFFS Query placement & quote-first
✅ Docs-top / query-bottom / quote-first
- Up to ~30% better quality on complex multi-doc inputs
- Quotes give a traceable evidence trail
- Metadata tags let Claude cite each source
⚠️ Costs to weigh
- Quote-first adds output tokens and a little latency
- Very large prompts cost more — pair with prompt caching for the static doc block
- Order matters most at scale; short prompts see little difference
EXAM TRAPS
<document> with <source> and <document_content> so
Claude can navigate and cite them.PRACTICE
Q1 · Where do long documents go, and where does the query go?
Long documents (~20K+ tokens) go near the top of the prompt, above the instructions and examples; the query goes at the bottom. Query-at-the-end can improve response quality by up to ~30% on complex multi-document inputs.
Q2 · What is "quote-first" and why use it?
Ask Claude to first extract the relevant passages into <quotes> tags before answering. It helps Claude cut through the noise of long documents and grounds the final answer in specific evidence.
Q3 · How should each document be wrapped in a long-context prompt?
In <document> tags (inside a <documents> container), each with a <source> and a <document_content> subtag (plus an index/other metadata) — so the structure is navigable and citable.