Skip to content

Context rot: why long prompts make models worse

Context rot is the drop in output quality as a prompt gets longer, even inside the context window. What causes it and how to keep an agent's context small.

Published
Updated
Reading time
9 min read

In short

  • Context rot is the decline in a model's accuracy as its input grows. It begins long before the context window is full.
  • A 2025 Chroma study of 18 models found the effect in every one, even on a task as simple as repeating a list of words, and a single distractor passage made it worse.
  • Benchmarks that test more than literal lookup put usable length far below the advertised window. In NoLiMa, 11 of 13 models scored below half their short-context baseline at 32K tokens.
  • The fix is a smaller context: retrieve less, clear old tool output, summarize history, and give side tasks to sub-agents with clean windows.

Context rot is the tendency of a language model to get less accurate as the amount of text in its prompt grows. It happens well inside the context window. A model with room for a million tokens can start making mistakes at a small part of that.

The term spread after a technical report from Chroma in July 2025. The practical lesson is that window size tells you what fits. It does not tell you what the model can use well.

CONTEXT WINDOWTurn 3ToolsDocumentsUnusedTHE TASK: 13% OF WHAT THE MODEL READSTurn 40ToolsDocumentsHistoryTool outputTHE SAME TASK: 6% OF WHAT THE MODEL READS
The task stays the same size while everything around it grows. Proportions are illustrative.

What the research found

The Chroma report tested 18 models from Anthropic, OpenAI, Google, and Alibaba, and every one became less reliable as its input got longer. Five results matter in practice.

  1. Length alone hurts. Accuracy fell as input grew even on a task that only asked the model to repeat a sequence of words.
  2. Loose wording hurts more at length. When a question and the passage holding its answer shared less vocabulary, accuracy fell faster as the input grew.
  3. Distractors hurt. One passage that resembled the answer but was wrong lowered accuracy. Four lowered it further.
  4. Tidy documents were harder than noise. Models did better when the surrounding text was shuffled than when it was logically coherent.
  5. Focus wins. On a conversational memory benchmark, every model scored higher when given about 300 relevant tokens than when given the full history of about 113,000.

An earlier paper, "Lost in the Middle" from 2023, found that models used information best when it sat at the start or end of the input and worst when it sat in the middle. Treat position as a weak lever. In Chroma's tests the position of the answer made no notable difference, so moving text around will not rescue a prompt that is too long.

Advertised window vs effective context length

The context window is the most text an API will accept. The effective context length is the longest input at which the model still does a given task well. Benchmarks that test more than literal lookup put the second number far below the first, often at half the advertised window or less.

RULER, a 2024 benchmark from NVIDIA researchers, made the distinction concrete. It tested 17 long-context models on 13 tasks. Every model claimed a window of 32K tokens or more, and only half kept satisfactory performance at 32K. The authors defined effective length as the longest input at which a model scored above 85.6%, which was Llama 2 7B's score at 4K tokens.

ModelAdvertised windowEffective length in RULER
Gemini 1.5 Pro1MAbove 128K, the longest length tested
GPT-4128K64K
Llama 3.1 70B128K64K
Mixtral 8x22B64K32K
Yi 34B200K32K

NoLiMa, published in 2025, found a wider gap. It tested 13 models that claim at least 128K tokens and removed most of the word overlap between each question and the passage that answers it. At 32K tokens, 11 of the 13 models fell below half of their own short-context scores. GPT-4o dropped from 99.3% to 69.7%.

These models are older than the ones you run today, and newer models score higher on both benchmarks. The gap has not closed, though. Chroma's 2025 study covered Claude Opus 4, GPT-4.1, and Gemini 2.5 Pro and still found the decline in every model. Read any advertised context window as a ceiling, not a working length.

Why needle-in-a-haystack scores mislead

A needle-in-a-haystack test hides one sentence in a long document and asks a question that shares words with it. Models score close to perfectly, which made long context look solved. Tests that require reasoning, or that remove the shared words, show steep drops at the same lengths. The easy test measures lookup, not use.

RULER found exactly this pattern: models reached nearly perfect accuracy on the plain needle test while almost all of them dropped sharply on its harder tasks as context grew. NoLiMa's result above comes from the same test with the shared vocabulary taken out, so the model has to infer the link instead of matching words. Chroma reached the same conclusion from its own experiments and wrote that the needle test underestimates what most long-context tasks require in practice.

Real work looks more like the hard version. A support agent reading a policy document is rarely asked a question that quotes it. A coding agent looking for the cause of a bug is not told which file holds it. A model card that shows a green grid of needle results tells you the model can find a quote. It does not tell you the model can use a long document to answer your question.

Why agents get hit hardest

Agents suffer most because they grow their own context on every step. Each tool call appends its result to the conversation. After forty turns the window holds old search results, file contents, and error traces from problems already solved.

That material is the worst kind of filler. It is on topic, it looks like evidence, and most of it is out of date. The research calls that a distractor.

Anthropic's applied AI team describes context as a finite attention budget, and an agent spends it without being asked. The symptoms are familiar to anyone who has watched a long session: the agent repeats a step it already finished, forgets a rule from the system prompt, or acts on a tool result that a later result replaced.

Prompt caching will not help here. Caching lowers the price of a long prefix. The model still has to attend to all of it.

How to keep context small

Keep context small by removing text the model no longer needs, starting with the cheapest change.

FixWhat it removesWhat it costs
Retrieve lessExtra passages. Return the top few after reranking, not twenty, because every extra passage is a candidate distractorA relevant passage is occasionally left out
Clear old tool outputResults the model has already acted on, replaced by a one-line note of what each showed. Anthropic calls this the lightest form of compactionVery little, since the note keeps the fact that the call happened
Compact the historyOld turns, replaced by a model-written summary once the conversation passes a token thresholdA fresh cache write and any detail the summary drops
Keep notes outside the windowDecisions and open tasks, written to a file and read back only when the current step needs themA tool call each time the agent reads them
Delegate to sub-agentsSide tasks, run in a clean window that returns a summary. Anthropic reports these often run 1,000 to 2,000 tokensExtra model calls and added latency
Load on demandFile contents, replaced by paths and queries the agent fetches when it needs themMore tool calls per task

Compaction has a price. It rewrites the start of the conversation, which invalidates the prompt cache and forces a full-price write. Compact in large steps at a threshold, not a little on every turn.

Summaries also lose detail. Keep the original transcript in storage and let the agent search it, so a fact that the summary dropped can still be recovered.

How to budget each part of the window, and in what order to place the parts, is covered in context engineering.

How to test it on your own task

Run a length sweep: keep the task fixed, grow the surrounding context in steps, and score each step. The length where the score starts to fall is the effective context length for that task on that model. It takes an afternoon and replaces a guess based on the advertised window with a number from your own data.

  1. Pick 50 to 100 questions from real traffic with known correct answers. LLM evaluation covers how to build that set.
  2. Build the surrounding context from your own material, not random text. Chroma found coherent text harder than shuffled text, so filler that looks like your documents gives an honest result.
  3. Add near-miss distractors: passages from your corpus that look relevant but are wrong or out of date. These are what an agent's history fills up with.
  4. Grow the context in steps, for example 4K, 16K, 32K, 64K, and 128K tokens, and place the relevant passage at several positions at each step.
  5. Score every answer with the same automated check you use in production, and plot score against input length for each model you are considering.

Rerun the sweep when you change models. Effective length differs by model and by task, and a new model with a larger window can have a shorter effective length on your task than the one it replaces.

How to tell if you have it

You have context rot if quality falls as input size rises. Plot your evaluation score against input tokens per request and look at the slope.

To get that chart you need two numbers on every request: the input token count and a quality score. The first comes from the provider's usage fields. The second comes from an automated check such as the grounding score described in the hallucination detection article.

Then set a budget. Pick the input size where your score starts to drop, trigger compaction below it, and alert when a session goes over. A context budget is a limit you choose from your own data. The provider's window size is only the ceiling.

Frequently asked questions

What is context rot in LLMs?

Context rot is the decline in a language model's accuracy as the amount of text in its prompt grows. It starts well before the context window is full and shows up as missed instructions, ignored facts, and answers built on the wrong passage. Chroma's 2025 study found it in all 18 models tested, including on tasks as simple as copying a list of words.

Does a bigger context window prevent context rot?

No. A larger window raises how much text the API accepts, not how well the model uses it. In the RULER benchmark, every model claimed at least 32K tokens and only half performed satisfactorily at 32K. Models with larger windows can still lose accuracy at lengths far below their limit, so a bigger window mostly gives you more room to make the problem worse.

What is the difference between context rot and lost in the middle?

Lost in the middle is a position effect: a 2023 paper found models used information best at the start or end of the input and worst in the middle. Context rot is a length effect: accuracy falls as total input grows, wherever the answer sits. Chroma found answer position made no notable difference in its tests, so shortening the context does more than reordering it.

What is effective context length?

Effective context length is the longest input at which a model still performs a task to a set standard. RULER defined it as the longest length scoring above 85.6%, and found it was often half the advertised window or less: GPT-4 advertised 128K and reached 64K. Your effective length depends on your task, so measure it with a length sweep on your own data.

How long can a prompt be before quality drops?

There is no universal number. It depends on the model, the task, and how much distracting material the prompt contains. In NoLiMa, 11 of 13 models fell below half their short-context scores at 32K tokens, while simple lookup tasks hold up much longer. Run a length sweep on your own task and set your context budget below the point where your score starts to fall.

How do you fix context rot in an AI agent?

Remove text the agent no longer needs. Replace tool results it has already acted on with one-line notes, compact the history in large steps when it passes a token threshold, keep decisions in an external notes file, and hand side tasks to sub-agents that return short summaries. Then set a context budget from your own evaluation data and alert when a session exceeds it.

Sources

  1. 01Context Rot: How Increasing Input Tokens Impacts LLM PerformanceChroma Research
  2. 02Lost in the Middle: How Language Models Use Long ContextsarXiv:2307.03172
  3. 03RULER: What's the Real Context Size of Your Long-Context Language Models?arXiv:2404.06654
  4. 04NoLiMa: Long-Context Evaluation Beyond Literal MatchingarXiv:2502.05167
  5. 05Effective context engineering for AI agentsAnthropic Engineering