Prompt Engineering & Output Quality

Where You Put Context Changes the Answer

Two prompts with identical words in a different order can produce noticeably different answers — and different bills. Placement is the cheapest prompt optimization most teams never make.

Claude 3P 101 · Updated July 2026 · Unofficial guide

A prompt is not a bag of words. Claude reads it as a sequence, and where you place documents, images, and instructions within that sequence affects both answer quality and — through prompt caching — cost. The good news: the placement rules are few, documented, and easy to adopt as team conventions.

The headline rule: long context first, question last

For long inputs — Anthropic's guidance draws the line around 20k tokens — put your documents and data at the top of the prompt, above the instructions, examples, and question. Per the official best practices, placing the query at the end after long context can improve response quality by up to 30% in Anthropic's testing, and the effect is strongest with complex, multi-document inputs.

The intuition for non-specialists: instructions that arrive after the material apply to something Claude has already read, like asking a colleague a question after they've finished the report rather than before they start. Teams habitually write prompts the other way — ask first, paste after — because that's how chat feels. For production prompts on long inputs, invert it.

Content typePlacement guidanceSource of the rule
Long documents (20k+ tokens)Top of prompt, query at the endPrompting best practices
Multiple documentsEach in <document> tags with <document_content> and <source>Prompting best practices
ImagesBefore the text that refers to themVision documentation
PDFsBefore your text in the requestPDF support documentation
Stable instructionsSystem prompt, ahead of variable contentPrompt caching mechanics

Label what you place

Position only helps if Claude can tell the parts apart. Anthropic recommends wrapping instructions, context, and inputs in consistent, descriptive XML tags — and for multi-document prompts, the <source> subtag is what lets an answer say "per the Q3 vendor agreement" instead of "one of the documents mentions." Tagging also defuses a subtle failure: when user-supplied text sits adjacent to your instructions untagged, instruction-like sentences inside the data can read as instructions to follow. Clear boundaries keep data as data.

Placement is also a cost decision

Prompt caching gives placement a second job. Caching works on exact prefixes: per Anthropic's docs, the cache follows the hierarchy toolssystemmessages, and a change at any level invalidates that level and everything after it. One changed byte early in the prompt invalidates every cached breakpoint after that position.

So the ordering rule for cost is: stable content first, volatile content last. Tool definitions and the system prompt (which change rarely) lead; shared reference documents come next; the per-request question goes at the end. Done right, repeat requests re-read the expensive prefix at 0.1x the base input price. Done wrong — say, a timestamp interpolated near the top of the system prompt — you silently pay full price on every call. Happily, this ordering agrees with the quality rule above: big stable documents early, fresh question last serves both goals at once.

Rule of thumb: sort your prompt by rate of change. Things that change never (tools, role, rules) → things that change daily (reference docs) → things that change per request (the user's input and your question). Quality and caching both improve.

What placement doesn't do

Two cautions. First, position is emphasis, not authority — putting an instruction last doesn't make it override an earlier one, and contradictory instructions are a prompt bug to fix, not to arbitrate by position (see instruction hierarchy). Second, don't assume: reorder and measure. Anthropic's prompt-engineering overview puts empirical evals against clear success criteria ahead of any tuning, and placement changes are among the cheapest A/B tests you can run — same words, same token count, different order.

Where to go next

For the caching economics in depth, see prompt cache mechanics and system prompt caching ROI. For handling the documents themselves, read long-document handling and XML structure.

Sources