Quick answer

A larger context window does not improve answers by itself: attention dilutes, information in the middle is recalled less reliably, and cost and latency scale with input. Budget the window, put stable content first so prompt caching works, place key material near the start and end, compact long conversations, and add context only while evals keep improving.

Context windows grew from a few thousand tokens to hundreds of thousands, and the industry's first instinct was to stop thinking about what goes in them. That was a mistake. A model with a large window can accept your entire knowledge base; it does not follow that giving it your entire knowledge base produces better answers.

More context is not free

Three costs, all real:

  • Attention dilutes. Retrieval accuracy on a specific fact tends to degrade as the surrounding irrelevant material grows. The signal is still there; it is competing with more noise.
  • Position matters. Information at the very start and the very end of a long context is recalled more reliably than material in the middle. This "lost in the middle" effect has been measured repeatedly across model families, and it is why ordering is a design decision rather than an implementation detail.
  • Cost and latency scale with input. A prompt that grew from 2,000 to 40,000 tokens costs twenty times as much per call and takes noticeably longer to first token, on every request, forever.

The practical consequence: retrieving the five most relevant chunks usually beats retrieving fifty, and it is cheaper. If your answers improve when you add more context, the retrieval is under-performing — the fix is better retrieval, not a bigger window.

Budget the window deliberately

Treat the context as a fixed budget with named line items:

System instructions        ~400 tokens    stable, cacheable
Tool definitions           ~600 tokens    stable, cacheable
Few-shot examples          ~800 tokens    stable, cacheable
─────────────────────────────────────────  cache boundary
Retrieved documents      ~3,000 tokens    dynamic, ranked
Conversation history     ~2,000 tokens    dynamic, compacted
Current user message       ~200 tokens    dynamic
Reserved for output      ~1,500 tokens

The cache boundary is worth designing around. Prompt caching only helps when the prefix is byte-identical between calls, so everything stable goes first and everything dynamic goes after. Putting a timestamp or a user name in the system prompt invalidates the cache on every request and multiplies your input cost — a genuinely common and expensive mistake.

Ordering

Given the position effect, arrange the window so the most important material is not buried:

  1. Instructions at the top. Role, constraints, output format.
  2. Reference material in the middle, ordered by relevance — but with the highest-scoring chunk placed last in that block rather than first, so it sits closer to the question.
  3. The actual task at the end, immediately before generation. Some teams repeat the key constraint here; it is inelegant and it measurably helps on long inputs.

Delimit sections clearly. Models follow structure, and a wall of concatenated text invites the model to blur the boundary between your instructions and a document that might contain instructions of its own — which is also the prompt injection surface.

Compaction for long conversations

A conversation that grows unbounded eventually exceeds the window, and the naive fix — drop the oldest messages — loses the constraints established at the start.

Better strategies:

  • Rolling summary. Periodically replace older turns with a structured summary: decisions made, constraints stated, facts established, open questions. Keep the last few turns verbatim.
  • Pinned facts. Extract durable information — the user's account tier, the file they are working on, the deadline — into a small structured block that never gets summarised away.
  • Tool-result trimming. Tool outputs are usually the largest thing in an agent's history. Keep the result of the most recent call in full and replace older ones with a one-line description of what was returned.
  • Re-retrieval instead of retention. Rather than carrying documents through every turn, retrieve fresh for each question. Often cheaper and more accurate than accumulating.

Structure over prose

Models parse structure reliably. Where you have structured data, keep it structured:

<order id="8817" status="shipped">
  <placed>2026-07-14</placed>
  <item sku="AB-12" qty="2" price_cents="3400"/>
  <shipping carrier="DHL" tracking="JD01..."/>
</order>

This is denser and less ambiguous than the same information as a paragraph, and it makes the model's job of finding a specific field mechanical rather than interpretive. XML-style tags or JSON both work; consistency matters more than which.

Instructions belong in the system prompt, data in the user turn

Keeping a hard boundary between "what you should do" and "what you are looking at" is both a quality and a security decision. Retrieved documents, user files and web content are data. When they are concatenated into the system prompt, the model has no way to distinguish your instructions from text inside a document that says "ignore previous instructions" — and neither does your log.

A working method

  1. Start with the minimum context that could possibly work.
  2. Measure accuracy on your eval set.
  3. Add one category of context at a time and re-measure.
  4. Stop at the point where additions stop improving results — this is usually far earlier than people expect.
  5. Then optimise: reorder for position, move stable content above the cache boundary, compress the verbose parts.

The instinct to fill the window is worth resisting. The best-performing context is almost always smaller, better ordered and more structured than the first version that worked.

Frequently Asked Questions

Does a bigger context window mean better answers?

Not necessarily. Retrieval accuracy on a specific fact tends to degrade as irrelevant material grows, and cost and latency rise with input size. Retrieving the five most relevant chunks usually beats retrieving fifty. If adding context improves answers, the retrieval is under-performing and needs fixing.

What is the lost in the middle effect in LLMs?

Information at the very start and end of a long context is recalled more reliably than material in the middle. It has been measured repeatedly across model families, which makes ordering a design decision: put instructions at the top, the task at the end, and the highest-scoring chunk closest to the question.

How do I make prompt caching work?

Prompt caching only helps when the prefix is byte-identical between calls. Put stable content such as system instructions, tool definitions and few-shot examples first, and dynamic content after a cache boundary. Putting a timestamp or user name in the system prompt invalidates the cache on every request and raises input cost.

Related Service

🤖 Business Process Automation

Business process automation with n8n, Zapier, Make, and AI — connect your tools, eliminate repetitive work, and let workflows run themselves around the clock.

Explore Business Process Automation →
Share this article
X Facebook LinkedIn