Detecting Poisoning, Distraction, Confusion, and Clash
Learn to diagnose four common AI agent context failures, poisoning, distraction, confusion, and clash. You’ll build Python checks for grounding, instruction drift, tool relevance, and conflicting facts, then combine them in a fixed-order classifier that connects each label to a practical repair.
We'll cover the following...
In the previous lesson, we saw that the on-call assistant can give a wrong answer even when note-1 is in the context. We called that general problem context rot, and we built a test to check whether position or competing content was behind it.
Context rot tells us that something is wrong. It doesn’t tell us what to fix. To repair a specific failing trace, we need a more precise name for the cause. Drew Breunig describes four failure modes that cover most of what goes wrong inside an agent’s context: poisoning, distraction, confusion, and clash. Each one needs a different repair, so naming the right one matters.
In this lesson, we’ll look at each failure mode with an on-call example, write a small Python check that detects it in a trace, and then combine the four checks into one classifier. A trace here is a plain dictionary that records what was in the context for one failing answer: the question, scratchpad lines, recent turns, the tool call, and any facts the sources reported.
Poisoning: A false fact sticks
Context poisoning happens when a false or invented statement enters the context and keeps shaping later turns. It usually gets in through a scratchpad write or a memory entry. Once it’s there, the model treats it as true.
The best-known example comes from Gemini 2.5 playing the game Pokémon FireRed. A detail from an older version of the game was in the model’s training data, and the model became sure it needed to find tea for a guard. Breunig’s write-up quotes the report: “Several times, Gemini 2.5 became convinced it needed to get tea, even though it was playing the older game. The tea task for FireRed was in its weights, so it poisoned its context. It spent hours trying to find or give the guard tea.” The false belief entered the context, and the agent never got past it.
For our assistant, picture this scratchpad line written during an incident: “note-9: the 14:02 checkout deploy was already rolled back.” If the assistant trusts it, it skips the rollback. But our store holds only note-1 to note-8, so note-9 doesn’t exist.
The check for poisoning is grounding: does each line cite a document that really exists? This is the same idea as citation_check() from Chapter 1. Here we run it as a plain local lookup, so it stays fast, repeatable, and easy to test.
In the code above:
Line 4: We build
VALID_DOC_IDS, the set of real note IDs, straight fromNOTE_STORE.Lines 7–10 ...