Context Poisoning in AI Agents: How One Bad Fact Takes Over a Run
A hallucinated goal, a wrong tool result or a stale memory gets written into the context, and every later step treats it as true. Here is how to recognize it, trace it to its first appearance and keep it out.
By Failure Mode Weekly Editors · November 20, 2026
Context poisoning is when a hallucination or other error makes it into an agent's context and is then referenced again and again. The model is not repeatedly making the same mistake from scratch. It made it once, wrote it down, and is now faithfully reasoning from its own notes.
That distinction matters for debugging. A poisoned run often looks like a reasoning failure at the step where it finally breaks, but the step that broke is usually doing its job correctly with bad input. The fix lives wherever the bad input was let in.
Where the term comes from
Google DeepMind named the failure in the Gemini 2.5 technical report, describing the agent harness that played Pokémon:
An especially egregious form of this issue can take place with “context poisoning” – where many parts of the context (goals, summary) are “poisoned” with misinformation about the game state, which can often take a very long time to undo. As a result, the model can become fixated on achieving impossible or irrelevant goals.
Drew Breunig's essay “How Long Contexts Fail” then made it one of four ways long contexts break, alongside context distraction, confusion and clash. That four-part split is now the common vocabulary, and it is useful because each one has a different cause and a different fix.
Context poisoning vs. the failures it gets mistaken for
| Failure | What is wrong with the context | Typical trace sign |
|---|---|---|
| Context poisoning | It contains a false claim the agent treats as fact, usually one it wrote itself | A claim with no supporting tool output that later steps keep citing |
| Context distraction | It is so long the model leans on its history instead of planning | Repeating earlier actions as the context grows |
| Context confusion | It contains irrelevant material (extra tools, documents) the model uses anyway | Calls to tools or citations of documents that have nothing to do with the task |
| Context clash | Two parts of it disagree, often an early wrong answer and later correct information | The final answer follows the early attempt, not the later evidence |
| Prompt injection / memory poisoning | Someone planted the false content on purpose | The bad content arrives through a document, web page, tool result or memory record from outside |
| Overflow and truncation | The right content was dropped to fit the window | A fact present early in the run is missing from later calls |
Poisoning and clash are close relatives. In a clash the correct information is also present and loses; in poisoning nothing in the context contradicts the error, so the model has no reason to doubt it. If nothing in the context is false and the run still degrades as it grows, that is context rot, not poisoning. If you find a correction sitting in the context and the agent ignored it, read why over-stuffed contexts compress reasoning as well. If the content was planted, treat it as a security incident first: see prompt injection detection in production.
How the poison gets in
Every agent context is assembled from a small number of sources. Poison enters through one of them, and knowing which one tells you which layer owns the fix.
- The model's own writing. Plans, goal lists, scratchpad notes and running summaries are model output that is fed back as input. One hallucinated line in a “current goals” block is reread on every following step. This is the case DeepMind described.
- Tool returns that are wrong but well-formed. An empty result, a default value, a stale cache hit or an error string that parses as data. The model continues from whatever it is given; see how continuation bias turns bad tool returns into confident wrong answers and silent tool failures that bypass error handling.
- Retrieval. An outdated or wrongly ranked document is retrieved and quoted as current fact. See stale retrieval in RAG-augmented agents.
- Long-term memory. A wrong fact written to memory in one session is loaded into the next, so the poison outlives the run that created it. See missed memory writes and silent context loss and state leakage between turns.
- Summaries and compaction. When history is condensed to save space, the summary keeps the conclusion and drops the evidence. A wrong conclusion now has nothing beside it that could expose it.
- Examples in the prompt. A flawed few-shot example is poison that ships with every request; see few-shot example poisoning.
- Adversarial content. Research such as AgentPoison shows attackers can deliberately plant records in an agent's memory or knowledge base so they are retrieved when a trigger appears.
Why it compounds instead of washing out
A poisoned context does not stay the same size. Each step that reasons from the false claim produces new text that restates it: a revised plan, a tool call built on it, a summary that mentions it. By the time the run fails, the error may appear in a dozen places, which is why DeepMind noted it can take a very long time to undo.
Multi-turn research points the same way. In “LLMs Get Lost in Multi-Turn Conversation”, Microsoft and Salesforce researchers found that models make assumptions in early turns, attempt final answers too soon and then rely on them: “when LLMs take a wrong turn in a conversation, they get lost and do not recover.” Agents run far more turns than a chat does, against their own earlier output.
Signs of context poisoning in a trace
- The agent states a fact (a file path, an ID, a status, a completed step) that no tool output in the trace ever returned.
- A goal or plan keeps an item that is impossible or already done, and the agent loops trying to achieve it.
- Tool calls are built on an argument value whose origin is a model message, not a tool result.
- The agent contradicts a tool return it received, siding with something it wrote earlier.
- Retries within the same session fail the same way, but the same task in a fresh session succeeds.
- Users report that “correcting” the agent mid-run does not stick, because the false claim still appears elsewhere in the context.
How to find the poisoned step
- Name the false claim. Write down the specific wrong belief the failing step acted on, in one sentence.
- Search backwards for its first appearance. Walk the trace from the failure to the start and find the earliest span whose input or output contains it. That span, not the failing one, is the root cause.
- Classify the source. Was the first appearance in model output, a tool return, a retrieved document, a memory read, a summary, or the prompt itself? That decides which layer owns the fix; the decision tree for pinning a failure to prompt, tool or workflow is a good next step.
- Confirm with a replay. Replay the run from just before the first appearance with the bad content removed or corrected. If the run recovers, you have the cause. See controlled replay for isolating failure causes.
- Check whether it persisted. If the claim was written to memory, a cache or a summary, it will poison the next run too. Find and remove that record.
This only works if the trace records what actually went into each model call, including tool results and the assembled context, rather than just the final messages. A trace that flattens a run into one failure event cannot show you where the claim first appeared.
Fixes, by where the poison entered
| Entry point | Layer that owns it | Fix |
|---|---|---|
| Model-written goals and plans | Workflow / harness | Keep goals and task state in a structured store the harness updates from verified events, not free text the model rewrites |
| Wrong but well-formed tool returns | Tool | Validate results against a schema and sanity rules before they enter the context; turn empty or default results into explicit errors |
| Stale or wrong retrieval | Memory / retrieval | Carry source and freshness with every retrieved item; filter or flag anything past its validity |
| Long-term memory writes | Memory | Gate writes: only persist claims backed by a tool result, and record where each memory came from |
| Summaries and compaction | Workflow / harness | Keep the evidence reference with each summarized conclusion, so a later check can trace it back |
| Few-shot examples | Prompt | Review and version examples like code; test prompt changes against real traces |
| Planted content | Security / tool | Treat retrieved and tool-provided text as untrusted data, never as instructions |
Two broader tactics help regardless of entry point. Quarantine context: give sub-tasks their own context (for example, a subagent) so a bad fact in one thread cannot spread to the rest of the run; keep such sub-tasks narrow, since parallel agents bring failure modes of their own. Remove, don't append: when a claim is found to be wrong, delete or rewrite it everywhere it appears in the assembled context. Adding “ignore what I said earlier” leaves both versions in place and turns poisoning into a clash.
When none of that is possible mid-run, roll back. Checkpoint the agent's state at each step, and on detecting a poisoned claim restart from the last checkpoint before it appeared rather than trying to talk the model out of it.
A short checklist
- Can you see, for every model call, the exact context it received?
- Does every fact in the agent's goals or memory point back to the tool result that established it?
- Are empty, default and error tool results rejected before they reach the model?
- Do memory writes require evidence, and can a bad memory be found and deleted?
- Do summaries keep references to their evidence?
- When you correct the context, do you remove the wrong claim or just add a new one?
- Do you have a replay path to confirm the poisoned step before shipping a fix?
Sources
Go deeper
- Over-Stuffed Context Windows Causing Reasoning Compression
LLMs lose reasoning ability before filling their context window, requiring intentional curation.
- How LLM Continuation Bias Turns Bad Tool Returns Into Confident Wrong Answers
Models keep answering when tools fail, so catch bad returns first.
- Missed Memory Writes and Silent Context Loss in Long Sessions
Silent memory failures hide inside successful model calls until production traces expose them.
- Stale Retrieval in RAG-Augmented Agent Workflows
Trace which harness layer let outdated context slip through to your model.
- Context Window Overflow and Silent Truncation in Agents
Models silently truncate context and ship confident wrong answers.
- Controlled Replay for Isolating Agent Failure Causes
Frozen prefix replay isolates which agent step caused failure.