Skip to content
bits
Context is everything · Lesson 3 of 7

Docs first, question last

Tutor:

Once you've picked what goes in, where you put it matters. Anthropic's guidance for long inputs (think 20,000 tokens and up) comes down to three habits.

Documents at the top, question at the bottom. Put the long material first, then your instructions and the question last. In Anthropic's tests, ending with the query improved answers by up to 30%, most of all with several complex documents.

Wrap each document in tags, with its metadata. A <document> holding a <source> (and any other metadata, such as a date) plus a <document_content>. Now Claude can tell where one file ends and the next begins, and can say which one it's quoting.

Ask for quotes first. Have Claude pull out the relevant lines before it answers. It has to find the evidence before reasoning from it, and you can check the quotes against the source.

Question first, raw paste vs Docs first, tagged, question lastillustrative: made-up numbers that show the idea, not output from a real modelcompare

promptTwo supplier contracts, about 40 pages each, and one question: which has the longer notice period?

Question first, raw paste

The notice period is 30 days, after which either party may terminate the agreement.

Docs first, tagged, question last

<quotes>acme.pdf: “either party may end this agreement with 30 days' notice”. globex.pdf: “termination requires 90 days' written notice”.</quotes> Globex has the longer notice period: 90 days, against Acme's 30.

Tutor:

On the left, Claude answered about one contract and never noticed there were two. On the right, the tags told it there were two sources, and the quotes show its working.

Tutor:

Tags are cheap. Here's a <source> line cut into tokens (illustrative ids): a handful of tokens to label a document that might be thousands long.

tokenizerillustrative: made-up numbers that show the idea, not output from a real model9 tokens · 25 characters

Tutor:

In code, the layout looks like this. The documents go in first, the instructions and question last.

import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic();
type Doc = { source: string; text: string };
export async function ask(docs: Doc[], question: string) {
const documents = docs
.map((doc, i) => `<document index="${i + 1}">
<source>${doc.source}</source>
<document_content>
${doc.text}
</document_content>
</document>`)
.join("\n");
return client.messages.create({
model: "claude-haiku-5-5",
max_tokens: 1024,
messages: [{
role: "user",
content: `<documents>\n${documents}\n</documents>
Quote the lines that answer the question in <quotes> tags, then answer.
If the documents don't say, reply "Not in the documents."
Question: ${question}`,
}],
});
}
TypeScriptUTF-8● lines 9–14: highlighted
Tutor:

Your turn, at a small scale. The draft below asks first and pastes the policy after. Rebuild it: the policy inside <document> with a <source>, then ask for a quote, then the question last. The checks can see your tags and the quote request, but not the order, so the order is on you.

Your turn

Run your prompt and the replies land here.

    • Keeps the policy, not yet
    • Wraps it in a document tag, not yet
    • Names the source, not yet
    • Asks for a quote, not yet
    • Asks the question, not yet
    • Ran at 1.0, not yet
    run at
    ~0 tokens

    Turn on JavaScript to run prompts.