Topic 2 of 5 · 4 min read
Trimming and ordering the window
Goal: Cut a bloated request down to what the task needs and order it so the key instruction and question sit where the model uses them.
Keep only what changes the answer, put long material first, and end with the question and the rules that matter most.
Check yourself · 1 of 3
For a long document question, which layout does Anthropic's prompting guide recommend?
Why it matters
Every extra line is a chance for distraction, and position changes how well a line is used. Trimming and ordering are the two cheapest fixes for a weak answer, and both cost nothing but a few minutes of care.
Step 1: Cut
Go through the request item by item and ask one question: if I removed this, would the answer change? Use three piles.
- Keep: the task, the facts the answer depends on, the constraints, and the format you need.
- Cut: pleasantries, repeated instructions, whole files when one function matters, tool output you already acted on, and anything that is true but not needed.
- Shrink: long things that matter a little. Replace a 200-line log with the 10 lines around the error. Replace a full email chain with its last two messages.
Step 2: Order
Anthropic's prompting guide advises putting long documents near the top and the question or instruction at the end. In its tests, queries at the end improved response quality, especially with long, multi-document inputs. A workable layout:
- Background and reference material (long, in labelled blocks).
- Short statement of the task.
- The rules that must not be missed.
- The question, last.
Label each block, for example <contract> and <emails>, so the model can tell where one source ends and the next begins. If the answer must rest on the material, ask the model to quote the relevant lines first, then answer.
Before and after
Before: a user pastes a full 900-line file, a stack trace, last week's chat about a different bug and a polite introduction. The question is buried in the middle: "Can you help with the crash?"
After: the 40 lines of the failing function in a labelled block, the 8 lines of the trace around the crash, then: "Task: find the cause of this crash. Rule: do not change the function's public signature. Question: why does it crash when the list is empty?"
What goes wrong
- Cutting the constraint. Trimming hard but dropping the one rule that mattered, such as "do not change the signature".
- Question first, material last. For long inputs the model may follow the early question less well than one placed at the end.
- Unlabelled blocks. Three pasted sources with no names blur together, and the model blends them.
- Trimming by guess. If you are unsure a piece matters, test the answer with and without it instead of keeping everything.
Examples
Cutting a debugging request
Before: the whole 900-line file, a 300-line log, and "help with the crash?" at the top.
After: one labelled block with the failing function, one with the 8 trace lines around the crash, then at the end: "Task: find the cause. Rule: keep the public signature. Question: why does it crash on an empty list?"
The model now reads less, sees the rule near the question, and answers about the right function.
Ordering a document question
You have a contract and two email threads and want to know if a late payment triggers a fee.
Put the three sources first, each in its own labelled block. Then write: "Quote the clauses that mention late payment, then say whether a fee applies. If the documents do not say, say so." The question and the fallback rule come last, where they are read most reliably.
Key points
- Cut anything that would not change the answer, and shrink what matters only a little.
- Never trim away the constraints, the format or the one fact the answer depends on.
- Put long reference material first and the question and key rules last.
- Label each block of material so the model can tell the sources apart.
- If unsure whether a piece matters, compare answers with and without it.
Common mistakes
- Trimming so hard that the constraint, format or key fact is lost.
- Putting the question at the very top of a very long input and nothing after the material.
- Pasting several sources with no labels so the model blends them.
- Keeping every line because it feels risky to remove anything, instead of testing with and without it.
Check yourself · 2 of 3
You are cutting a request. Which item should you keep above all others?
Check yourself · 3 of 3
A user pastes a 200-line log and asks about one error. What is the best way to shrink it?
Practice items, not counted towards your mastery.
Start here
- Context Rot (Chroma research) (opens in a new tab)ArticleFree
Tests many models as input grows and shows accuracy dropping even on simple tasks.
- Lost in the Middle: How Language Models Use Long Contexts (opens in a new tab)PaperFree
The study showing models use facts at the start and end of a long input better than facts in the middle.
- NoLiMa: Long-Context Evaluation Beyond Literal Matching (opens in a new tab)PaperFree
Shows long-context accuracy falls when the question does not share words with the answer.
More for this topic
- Prompting best practices (Claude docs) (opens in a new tab)DocsFree
Official advice on long inputs: put documents first, the question last, and quote the relevant parts.