What Anthropic’s Prompting Best Practices Actually Say About Long Documents, and What Most Prompts Still Get Wrong

A large haystack in a field, illustrating information buried in the middle of a long document

Anthropic’s own prompting documentation says long documents belong near the top of a prompt, above the question that depends on them, and that moving the query to the end can improve response quality by up to 30 percent on complex, multi-document inputs. Most prompts that paste in a retrieved document, a transcript, or a contract still put the question first and the document after it, which is the exact pattern the documentation warns against.

What Anthropic’s prompting guide actually recommends

Anthropic’s prompting best practices documentation is explicit about document placement for inputs of 20,000 tokens or more: “Place your long documents and inputs near the top of your prompt, above your query, instructions, and examples. This improves performance across all models.” The same page adds a specific figure: “Queries at the end can improve response quality by up to 30 percent in tests, especially with complex, multidocument inputs.”

That is one sentence in a longer best-practices page, not a separate standalone “long-context” document, which is why it is easy to miss. It sits alongside more commonly cited advice, like using XML tags or giving Claude a role, and it gets skipped specifically because it conflicts with how most people naturally draft a prompt: ask the question, then attach the supporting material as an afterthought.

The two patterns that put the document in the wrong place

Two common prompt structures violate the placement rule without anyone noticing, because the violation is buried in code rather than in the visible prompt text.

  • RAG pipelines that template the question first. A typical retrieval-augmented generation template reads “Answer this question: {question}. Use the following context: {retrieved_chunks}.” The question variable sits before the retrieved content in the final assembled prompt, even though the person who wrote the template was thinking about the question as the “main point” and the context as supporting detail.
  • Chat interfaces that append a new message after existing history and attachments. When a user pastes a long document early in a conversation and then asks a question several turns later, the document is correctly positioned near the top of the conversation already — but if the application re-sends the document as a fresh attachment alongside the new question, it often lands after the question in the assembled context, undoing the benefit of the earlier placement.

Both patterns are invisible from the chat window. The person prompting never sees the final assembled order, which is exactly why this mistake survives in production systems that otherwise look polished.

Why the order affects the answer at all

The placement advice is not an arbitrary Anthropic preference. It lines up with a 2023 Stanford-led study, “Lost in the Middle: How Language Models Use Long Contexts” (accepted for publication in Transactions of the Association for Computational Linguistics), which tested how language models use information at different positions in a long context. The paper found that “performance is often highest when relevant information occurs at the beginning or end of the input context” and “significantly degrades when models must access relevant information in the middle of long contexts.”

Putting the document first and the query last does two things at once: it moves the document itself out of a buried middle position relative to the rest of the prompt, and it puts the query in the strongest position, immediately before generation starts. A query sandwiched between a system prompt and a long document sits in the weakest spot in the entire context.

The XML structure most long documents are still missing

Placement alone is not the whole recommendation. Anthropic’s documentation also specifies how to wrap the document once it is at the top: “wrap each document in tags with and (and other metadata) subtags for clarity,” and to “nest tags when content has a natural hierarchy (documents inside , each inside ).”

Common prompt structureDocumented structure
Question, then a wall of pasted text with no tags<documents><document index="1"><source>contract.pdf</source><document_content>...</document_content></document></documents>, placed above the query
Multiple files concatenated with line breaks onlyEach file in its own numbered <document index="n"> block, so Claude can refer to “document 2” unambiguously
Source filename mentioned only in the surrounding proseSource recorded as metadata inside the tag, separated from the content itself

The practical effect of tagging is that Claude can cite which document a claim came from without guessing from prose context, and a prompt with three or four pasted documents stops reading as one undifferentiated block of text.

Grounding the answer in quotes before the summary

A second piece of the same documentation addresses accuracy rather than placement: “For long document tasks, ask Claude to quote relevant parts of the documents first before carrying out its task. This helps Claude focus on the relevant content and ignore the rest of the document.” In practice this means adding one explicit instruction — something like “First, extract the quotes most relevant to the question inside tags, then answer using only those quotes” — rather than asking for a direct answer from the raw document.

This step also makes the output auditable. A reader can check the extracted quote against the source document in seconds, which is a faster check than re-reading the entire document to see whether a summary paragraph is accurate.

Chain-of-thought as a fallback, not a default

For long-document reasoning that involves comparing figures across sections or following a multi-step argument, Anthropic frames step-by-step reasoning as a fallback rather than a default: “Manual chain-of-thought (CoT) prompting as a fallback. When thinking is off, you can still encourage step-by-step reasoning by asking Claude to think through the problem before it answers.” The same guidance favors general instructions over prescriptive steps, so the fix for a long-document task that needs reasoning is usually “think through this step by step before answering,” not a rigid numbered checklist dictating exactly how to reason.

The self-check instruction that helps most models and hurts one

Appending a verification line — “before you finish, verify your answer against the source document” — catches errors reliably on most models, according to the same documentation. But the guidance carries a specific, model-scoped exception: “Claude Opus 5 is the exception: it verifies its own work well without explicit instruction, and verification instructions carried over from prompts tuned for earlier models can cause over-verification, adding tokens and latency. On Claude Opus 5, remove these instructions rather than rewriting them.”

That detail matters for anyone maintaining a prompt library across model versions. A verification line copied forward from a Claude Sonnet or Haiku prompt into an Opus 5 deployment is not neutral; the documentation describes it as actively counterproductive on that model, not merely unnecessary.

A before-and-after rewrite

Here is a typical long-document prompt before applying the documentation’s recommendations, followed by the same task rewritten to match them.

Before: “Here is our Q3 vendor contract: [4,000 words of contract text]. Based on this, does the contract allow the vendor to raise prices mid-term, and if so under what conditions? Answer in a short paragraph.”

After: “<documents><document index=”1″><source>Q3 vendor contract</source><document_content>[4,000 words of contract text]</document_content></document></documents>\n\nFirst, quote the specific clause or clauses in <quotes> tags that address price changes during the contract term. Then, using only those quotes, answer: does the contract allow the vendor to raise prices mid-term, and under what conditions? Keep the answer to one paragraph, and verify your answer against the quoted clauses before finishing.”

The rewrite moves the document above the question, tags it with its source, asks for a quote extraction step before the answer, and appends a verification instruction — four separate, individually documented recommendations applied to one ordinary request.

What this connects to in prompt structure more broadly

Document placement is really a special case of a broader instruction-position problem. The same loss of attention that affects a document buried in the middle of a long prompt also affects a rule buried in the middle of a long system prompt, which is why both problems share the same fix: move the thing that must not be missed to a position of attention, at the top or immediately before the output. The quote-extraction step described above is a manual version of what Claude’s Citations API automates for supported document types, and the chain-of-thought fallback sits on the same spectrum as the token cost trade-offs covered in a comparison of few-shot, chain-of-thought, and RAG context costs. Framing an instruction positively rather than negatively, covered in a separate look at vague negative instructions, is the same kind of small, documented, and frequently skipped fix. For the mechanics of what a context window actually holds before any of these techniques apply, this explainer on context windows and token limits covers the underlying limit itself.

None of these fixes requires a different model or a larger context window. They are four sentences added to a prompt that already had the right document in it, in the wrong order.

Sources: Anthropic, Prompting best practices; Liu et al., “Lost in the Middle: How Language Models Use Long Contexts”.

Photo: “A haystack in Chandpur district.jpg” by Kritzolina, CC BY-SA 4.0, via Wikimedia Commons.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top