Prompting with long documents: data first, question last, quotes before answers
TL;DR
For long inputs, put documents first and the question last (Anthropic reports up to 30% better quality), wrap each document in XML with its source, and have Claude quote relevant passages before answering.
Paste an 80-page report plus two Excel files into a chat, ask "analyse this for me", and the result is often generic, misses figures, and sometimes "misremembers" details. The problem rarely lies with the model; it's how the prompt is arranged when the data is long. Anthropic's prompting docs have a dedicated section for inputs of roughly 20K tokens and above, with three simple but effective techniques. This post explains each one and how to apply them, whether you're chatting or building an app.
Three main techniques
| Technique | What to do | Effect |
|---|---|---|
| Documents at the top, question at the end | Put long data above instructions, examples and the question | In Anthropic's tests, putting the question at the end can improve quality by up to 30%, especially with multiple documents |
| Wrap each document in XML | <document> containing <source> and <document_content> | Claude can tell which document says what and cite correctly |
| Quote first, answer second | Ask for relevant passages in <quotes> before doing the task | Focuses on what's relevant, ignores noise, easy to verify |
1. Documents first
The common habit is writing the request first and pasting documents after. With long input, reverse it: documents first, then instructions, finally the question. By the time the model reaches the question, all the data is above it, and the question is the "most recent" thing in context.
2. Structuring multiple documents
<documents>
<document index="1">
<source>annual_report_2025.pdf</source>
<document_content>{{REPORT}}</document_content>
</document>
<document index="2">
<source>competitor_analysis_q2.xlsx</source>
<document_content>{{COMPETITORS}}</document_content>
</document>
</documents>
Analyse the annual report and the competitor table.
Identify 3 strategic advantages and propose a Q3 focus.
State which document number each finding comes from.
You can add other metadata inside each <document>: date, author, version. When documents contradict each other, Claude uses the metadata to explain rather than blend them.
3. Quote before concluding
Find the passages in the contract about termination and penalty
clauses. Put them verbatim in <quotes> tags.
Then, based only on these quotes, list the risks for the buyer
in <risks> tags. If no relevant quote is found,
write "not in the document".
This technique has three benefits: Claude "filters" the relevant parts before reasoning; you can verify quickly by checking the quotes; and "if not found, say it's not there" sharply reduces made-up information.
In everyday chat
- Attach files first, then type the question in the last message.
- Multiple files: give them meaningful names (
contract-v3-signed.pdfinstead ofscan001.pdf), because the file name acts as the "source". - Ask specific questions instead of "analyse everything". Narrow questions get answers with clear citations.
- On Claude.ai, paid plans can use Projects: when project knowledge approaches the context limit, it automatically switches to retrieval (RAG) mode to expand capacity.
When building apps
- Combine with prompt caching: long documents at the top are also the ideal spot to cache. Many questions over the same document only pay the cache-read price for the long part.
- Citations: if you need precise source citations down to the passage, consider the API's citations feature instead of parsing
<quotes>tags yourself. - Don't stuff everything in: long context isn't free. Pre-filter with search (RAG) when the document store is much larger than what's needed.
Risks and caveats
- Quotes still need checking: spot-check a few against the original, especially for legal and financial documents.
- Poor-quality scans or complex tables may be misread; for important figures, export tables to CSV first.
- External documents may contain hidden instructions (prompt injection). Treat content inside
<document_content>as data, not commands.
How to apply it
- Dev: Standardise your prompt builder: documents (XML) → instructions → question. Add a quote-first step for precision tasks.
- Tech Lead: Measure quality before/after reordering prompts on an eval set; combine with caching for reused documents.
- PM / BA: When reading long documents with Claude, always ask it to "quote verbatim and state the document number". Your analysis notes become verifiable.
Sources & references
- Prompting best practices — Claude Docs