- In short
- Preventing context drift and bloat means using tool output pruning and compaction to stop irrelevant or stale content from crowding out what matters. Pruning trims verbose tool results to the part the model actually needs; compaction summarizes older turns to reclaim space; and facts that must be exact are preserved verbatim rather than summarized.
Drift and bloat are what happen when you stop curating
Context window management establishes the principle: the window is a budget you curate as the task grows. This knowledge point is the applied craft of doing that curation over time. Two failure modes creep in as an agent or conversation runs. Bloat is the window filling with verbose, low-value content until useful material is squeezed out. Drift is the gradual loss of focus as stale turns and irrelevant results accumulate and pull the model away from the current goal. The Claude Certified Developer - Foundations (CCDV-F) exam expects you to apply two concrete techniques against them: tool output pruning and compaction.
The reason this is an apply-level knowledge point rather than a recall one is that both techniques involve judgement. You have to decide what to trim, when to summarize, and crucially which facts must survive untouched. Get those judgements wrong and the cure is worse than the disease, because you can just as easily compact away the one detail the task depended on.
- Context drift and bloat
- Bloat is the context window filling with verbose or low-value content that crowds out what matters. Drift is the loss of focus as stale, irrelevant content accumulates over a long run. Tool output pruning and compaction are the techniques used to prevent both.
Tool output pruning: keep the signal, drop the dump
Tools are the biggest single source of bloat. A search returns dozens of results, an API returns a deeply nested payload, a file read returns thousands of lines. If you drop the raw result straight into the context, most of it is noise the model does not need, and it consumes budget the rest of the task requires. Tool output pruning is the practice of trimming a verbose result to the part the model actually needs before that result enters the window.
Concretely, pruning means extracting the relevant fields, rows, or lines and discarding the rest, rather than pasting the whole response. If a lookup returns a large record but the model only needs the status and the balance, you pass the status and the balance. The exam trap here is letting raw tool output accumulate until early instructions fall out of the window. A scenario will describe an agent that worked fine early on but started ignoring its original instructions after a series of large tool calls, and the correct reading is that unpruned tool results grew until they pushed the instructions out of the budget. The fix is to prune at the source, not to hope the window absorbs it.
Compaction: summarize the old, keep the durable
Pruning controls what enters the window; compaction controls what stays. Over a long conversation, older turns lose most of their moment-to-moment relevance but may still carry facts the task depends on. Compaction summarizes those older turns into a compact form, reclaiming space while preserving the durable facts they established. Instead of resending twenty verbatim turns, you carry a short summary that captures the decisions made, the constraints agreed, and the state reached.
The skill is in the summary. A good compaction keeps what future steps will need, the durable facts and commitments, and drops the conversational scaffolding around them. This is a curation act in exactly the sense the prior knowledge point described, applied to history rather than to fresh input. It is closely related to context isolation through subagents, which prevents bloat by never letting a subtask's detail into the main window at all. Compaction cleans up what is already there; isolation stops it accruing in the first place. Both serve the same budget.
The exact-facts rule is where candidates slip
Here is the judgement the exam cares about most. Compaction is lossy by design, so anything that must remain exact should be preserved verbatim rather than summarized. A summary that says "the customer provided their account details" has destroyed the account number. A summary that says "several errors were discussed" has destroyed the specific error codes a later step needs to act on. The principle is that facts that must be exact are held word-for-word, and only the genuinely disposable narrative around them is compacted.
The corresponding exam trap is compacting case-critical facts that must remain exact. A scenario will describe an agent that summarized a long thread and then produced a confident but wrong answer because a precise identifier, figure, or verbatim quote was lost in the summary. The correct diagnosis is not "compaction is bad," it is that compaction was applied to content that should have been preserved verbatim. The applied skill is separating the two: summarize the reasoning and the chatter, protect the identifiers, numbers, quotations, and any value another step must match exactly. When output later depends on those exact facts, response validation and defensive parsing is the safety net that catches a value the compaction quietly corrupted.
Worked example
A support agent runs a long troubleshooting session. Each diagnostic tool returns a full multi-hundred-line log, and after twenty turns the developer adds a compaction step that summarizes everything older than five turns into a two-sentence recap. Soon the agent starts ignoring its escalation policy and quotes a wrong ticket number.
Two separate faults are in play, and the exam wants you to name both. First, the raw diagnostic logs were dropped into the window unpruned. Twenty turns of multi-hundred-line logs is exactly the accumulation that pushes the earliest content, including the escalation policy in the original instructions, out of the budget. The agent is not disobeying the policy so much as no longer holding it. Pruning each log to the handful of lines that actually indicate the fault would have kept that budget clean.
Second, the compaction step summarized "everything older than five turns," which swept up the exact ticket number into a two-sentence recap and lost its precise value. When a later step needed that number, only a paraphrase remained, so the agent reconstructed a plausible but wrong one.
The fix applies both techniques correctly. Prune tool output at the source so logs never bloat the window, and compact old turns while preserving the ticket number and any other exact-critical fact verbatim. Same session, same tools, but curated instead of accumulated.
How this is tested on the CCDV-F exam
Because this is an apply-level knowledge point, questions give you a running agent that has degraded and ask which technique to apply and how. The two traps are the two most common wrong turns. If instructions or early context stopped being honoured after heavy tool use, the answer is pruning: raw tool output accumulated until the early content fell out of the window. If a summarized or compacted conversation produced a confident but factually wrong result, the answer is that a case-critical fact was compacted when it should have been preserved verbatim.
Watch for distractors that overcorrect. Deleting all history, refusing to use tools, or upgrading the model do not address drift and bloat at their source. The exam rewards the surgical move: prune verbose results to the needed part, compact stale turns to reclaim space, and protect the exact facts by keeping them verbatim.
Misconception
If the context is getting full, I should just summarize the whole conversation, including all the details, to save space.
What's actually true
Misconception
Tool results are data, so I should keep them in full in case the model needs any part of them later.
What's actually true
Where this fits
Preventing drift and bloat is the maintenance layer of context engineering. It keeps the budget defined by context window management clean over a long run, and it pairs naturally with context isolation through subagents, which prevents bloat by design rather than cleaning it up after the fact. Master the two techniques and the judgement about exact facts, and you can keep an agent focused across a session instead of watching it drift.
An agent handled tasks well for the first several turns, then began ignoring its original safety instructions after making a series of tool calls that each returned large payloads. What is the most likely cause and the right fix?
People also ask
What is tool output pruning?
What is context compaction?
Which facts should not be compacted?
Watch and learn
Official Anthropic Academy lessons first, then hand-picked walkthroughs. Videos load only when you press play.
No videos curated for this concept yet
We are still curating the best official and community videos for this topic.
References & primary sources
Master this concept with Archie
Practice it inside an adaptive study session. Archie, your Socratic AI tutor, tracks your mastery with Bayesian Knowledge Tracing and schedules the perfect next review.