Topic 1 of 5 · 3 min read
Context poisoning by early errors
Goal: Trace a wrong answer back to the poisoned item in the context and remove or correct it.
Context poisoning is when a wrong statement enters the conversation and the model keeps treating it as true in every later answer. The error does not stay in one reply. It becomes part of the material the model reads each turn.
Check yourself · 1 of 3
What is context poisoning?
Why it matters
A model reads the whole conversation again on every turn. It cannot tell which lines were checked facts and which were its own guesses. If an early answer says "the contract renews on 1 March" and that was invented, every later answer can build on it: a reminder email, a budget plan, a summary for your boss. Each new answer repeats the error and makes it look more established. This is also why long agent sessions go off course: one bad tool result, such as a wrong file path or a stale search hit, gets reused for dozens of steps.
How to spot it
- Notice the first odd answer. Poisoning shows up as the same wrong detail returning in different forms.
- Walk backwards. Find the earliest message where the wrong detail appears. That is usually the poisoned item.
- Ask where it came from. Was it your own typo, a model guess, or a tool result nobody checked?
- Remove or correct it at the source. Do not just argue with the model later in the chat.
Before and after
Before: The chat contains an assistant line: "Your lease ends on 31 May." You never said that. Later you ask for a moving checklist and it plans everything around 31 May. You reply: "No, it ends in June." The model apologises, then a few replies later schedules the movers for May again.
The wrong line is still in the window, and your correction is one voice against several earlier ones.
After: Edit the message where the date first appeared, or start a new chat with: "Facts I have checked: the lease ends on 30 June. Build a moving checklist." The poisoned line is gone, so nothing pulls the answer back.
What goes wrong
- Correcting in place. A correction at the end of a long chat often loses to the many earlier lines that repeat the error.
- Trusting tool output. A search result, a file read or a calculator call is also text in the window. If it was wrong, it is poison like any other.
- Confident repetition. The more times the wrong claim is repeated, the more normal it looks to the model, so later answers state it with no hedging.
Optional: in a coding agent
An agent that reads a stale config can carry the wrong value forward.
tool result: DATABASE_URL=postgres://staging-db:5432/app (file was from an old branch)
agent: I will run migrations against staging-db.
Fix the source: re-read the right file, then restate the verified value in the next message.
Examples
The invented deadline
In message 3 the assistant wrote "the grant closes on 12 April". The real date was 12 May. By message 15 it had produced a plan, an email and a calendar entry for April. The fix was to edit message 3 to the correct date and regenerate, not to correct each later output.
The stale search result
An agent searched for a library's install command and got an answer from a five-year-old blog post. Every later step used the old command and failed in new ways. Removing that result and pasting the current docs page fixed all of them at once.
Key points
- The model rereads the whole conversation each turn, so one wrong line can shape many later answers.
- A model cannot tell a checked fact from its own earlier guess.
- Tool results, search hits and file contents can poison a context just as a model hallucination can.
- To find the poison, walk back to the earliest message where the wrong detail appears.
- Fix the source by editing or removing the bad item, because a late correction often loses to many earlier repetitions.
Common mistakes
- Arguing with the model at the end of a long chat instead of removing the bad line.
- Assuming tool output is correct because it did not come from the model.
- Fixing each wrong answer one by one without finding the first wrong item.
- Saving a wrong answer to memory or notes, which poisons future sessions too.
Check yourself · 2 of 3
Your assistant invented a meeting time in an early reply, and later replies keep using it. Where is the best place to fix this?
Check yourself · 3 of 3
A coding agent reads an outdated config file and uses its database address for ten steps. What is the best description of what went wrong?
Practice items, not counted towards your mastery.
Start here
- How long contexts fail (Drew Breunig) (opens in a new tab)ArticleFree
Names poisoning, distraction, confusion and clash, with examples from real agents.
- How to fix your context (Drew Breunig) (opens in a new tab)ArticleFree
Practical ways to prune, quarantine and summarise context after a failure.
- The lethal trifecta for AI agents (Simon Willison) (opens in a new tab)ArticleFree
Plain explanation of when untrusted content in context can leak private data.