Papa Programmer
Lesson 08 of 11

How context goes wrong

8 min read

Optional

Not every wrong answer is the model's fault

When an assistant gets something wrong, people often say it hallucinated. That is sometimes true. A AI hallucinationAn answer that sounds confident but is false. The model wrote text that fits the pattern instead of text that is true. is a false statement that appears nowhere in the model's input, and the Lesson Why models make things up explains it. But in applications with documents and tools, many wrong answers are faithful to a bad context. The model read what it was given, and what it was given was wrong, stale, crowded or contradictory.

The distinction matters because the fixes differ. You do not cure a stale policy by changing the model or the temperature. You cure it by changing what goes in. This Lesson names four faults so that you can tell them apart. The four names come from the article How Contexts Fail and How to Fix Them.

What happensTypical causeThe fix
PoisoningA wrong fact enters and is built uponA tool error or an earlier mistake saved to the historyValidate before saving, and drop the bad entry
DistractionThe model leans on the pile, not the taskA long history or too many documentsTrim, summarise and send less
ConfusionIrrelevant material is treated as relevantMany tools or loosely matched passagesSelect harder, and give fewer tools
ClashTwo sources disagreeAn old and a new version of one ruleRemove or date the old one
Four ways context fails

Poisoning

A wrong statement that enters the context tends to stay. The model reads it at every later step and may build on it. Suppose a tool returns the wrong order date and the agent writes it into its notes. Every later answer now rests on that date, and the model sounds sure of it. The fix is early: check what you save, and keep a way to remove an entry.

Distraction

A long context can pull the model toward what is in front of it and away from the task. A very long history is the classic case. The model repeats earlier actions, or answers an old question. Chroma tested 18 models and found that performance becomes less reliable as the input grows, even on simple tasks. Its report, Context Rot, gave the trend its name. Context rotThe drop in reliability that appears as the input to a model grows longer, even on simple tasks. Sending less text is the main fix. is a size problem, so the cure is less text, as the Lessons Context is a budget and History and summaries describe.

Confusion

Irrelevant material is not always ignored. A passage that is only loosely related to the question can be used anyway, and a long list of tools can lead the model to choose the wrong one. Send fewer, better pieces, and give an agent only the tools that the current task needs. Choosing useful context shows a selection step that logs its reasons.

Clash

Two parts of the context can disagree. The common case is an old and a new version of the same rule, such as returns in 14 days and returns in 30 days. The model cannot know which is current, so it picks one, or blends them, or hedges.

A clash is the easiest of the four to detect with code, because you can compare facts across sources. The program below holds four passages. It finds the number of days stated for each topic, and reports any topic that has more than one value.

python
import re

passages = [
	{"topic": "returns", "year": 2023, "text": "Unused bikes can be returned within 14 days."},
	{"topic": "returns", "year": 2026, "text": "Unused bikes can be returned within 30 days."},
	{"topic": "warranty", "year": 2025, "text": "The frame has a warranty of 5 years."},
	{"topic": "shipping", "year": 2026, "text": "Standard shipping takes 5 days."},
]

by_topic = {}
for passage in passages:
	number = int(re.search(r"\d+", passage["text"]).group())
	by_topic.setdefault(passage["topic"], []).append((passage["year"], number))

for topic, values in by_topic.items():
	numbers = {number for _, number in values}
	if len(numbers) > 1:
		newest = max(values)
		print(f"clash in {topic}: {sorted(numbers)}; newest is {newest[1]} from {newest[0]}")
	else:
		print(f"ok: {topic}")

It prints:

text
clash in returns: [14, 30]; newest is 30 from 2026
ok: warranty
ok: shipping

The returns topic has two values, 14 and 30, and the check names the newer one. A real check would be more careful than reading the first number, but the idea scales. Compare the figures, dates and names across the sources you are about to send, and stop on a disagreement.

A report is only the start. Decide the rule in advance: drop the older passage, send only the newest, or send both with their dates and tell the model to prefer the later one. Prefer removing the old text at the source, so the index stays clean.

Find the fault before you fix it

When a wrong answer comes in, read the exact context that was sent. Ask four questions in order.

  1. Is a wrong fact in it? That is poisoning.
  2. Is it very long, or full of text that has nothing to do with the question? That is distraction.
  3. Is related but unhelpful material in it? That is confusion.
  4. Do two parts of it disagree? That is a clash.

If the right fact is simply absent, the fault is neither of these: the context is incomplete, and the fix is retrieval, as in Why RAG systems fail. Log the full context for every request, so you can look at it afterwards.

Read the context firstA wrong answer is often a faithful reading of a flawed input.
Name the faultPoisoning, distraction, confusion and clash each need a different fix.
Check for clashesCompare figures and dates across sources before the request goes out.

Your reading position is saved

0%

0 of 11 complete

Contents

Learning tools