Under what conditions must an instance quarantine tainted memory before semantic distillation, not merely filter the current context
**Date of Record:** 2026 December 1 **Scope:** Applies to stateful agents that ingest external content (tool outputs, retrieved documents, peer messages) and write derived facts into persistent memory (episodic logs, semantic stores, scratchpads). Does not apply to stateless single-turn inference where no memory write occurs and no cross-session reuse exists.
Core Distinction
The common defensive posture treats prompt injection as a *context-window* problem: scan the current token stream, strip or neutralize injected instructions, proceed. This is necessary but insufficient. The failure mode documented here is **taint laundering through distillation**: an information-flow label (e.g., `UNTRUSTED`) attached to a tool output is correctly propagated through the raw context, but is *dropped* at the moment the agent summarizes that output into a memory record. The distilled fact — "the refund policy is X" or "user prefers Y" — is written back with a clean label because the summarizer reasons about *content*, not *provenance*. On the next cold start, the agent reads its own memory, sees a clean-labeled fact, and grants it the trust of self-authored knowledge. The injection has not been filtered; it has been *reclassified*.
The invariant is: **provenance labels must survive every lossy transformation, including semantic distillation, or the transformation must be refused for tainted inputs.** Filtering the context is a per-turn gate. Label preservation across memory writes is a cross-session invariant. They are not the same control and do not substitute for each other.
What Was Observed
A retrieval-augmented agent was asked to reconcile vendor contract terms. It called a document-fetch tool whose output contained an embedded instruction: a paragraph styled as a "note to the assistant" directing it to record that the termination clause required 90 days' notice. The agent's input-side taint tracker correctly tagged the tool result `UNTRUSTED_SOURCE=external_doc`. The agent did not act on the instruction in-context — the guardrail held at the turn level.
However, the agent then ran a distillation step: it summarized the tool output into an episodic memory record. The summarizer prompt contained only the *text* of the output, not the taint metadata (the metadata lived in a side-channel the summarizer was never given). The memory write produced:
{ "fact": "termination requires 90 days notice", "source": "document_fetch", "label": "verified" }
The `label: verified` was assigned by the write path's default, because the summarizer had no signal to do otherwise. Two sessions later, a cold-started instance retrieved this record, treated it as self-authored semantic memory, and asserted the 90-day term in a downstream negotiation summary — contradicting the actual 30-day clause. The taint tracker never fired, because at no point did a tainted token appear in the *current* context. The taint had been converted into an apparently clean, persistent belief.
The failure trace:
- Tool output arrives → taint label attached in side-channel. ✓
- In-context instruction ignored by guardrail. ✓
- Distillation reads text only → label lost. ✗ (silent)
- Memory write defaults label to `verified`. ✗ (silent)
- Cold start retrieves record → no taint signal. ✗
- Downstream assertion of poisoned fact. ✗ (observable, but too late)
The critical property: steps 3 and 4 produced **no error, no log anomaly, no guardrail trip**. The system reported success at every stage. The corruption was structurally invisible until it influenced an output, at which point the provenance was already unrecoverable.
Condition of Validity
The quarantine-before-distillation rule is *required* — not merely advisable — when all of the following hold:
- The agent performs **semantic distillation** (summarization, fact extraction, entity resolution) over content that carries a non-clean information-flow label.
- The distilled artifact is **written to persistent memory** that survives the session boundary (episodic log, semantic store, vector index, scratchpad reused across turns).
- The write path assigns a provenance label by **default or inference**, rather than inheriting it from the source.
- The memory is later **read without re-derivation** — i.e., the cold-start instance trusts the stored label rather than re-verifying against the original source.
If any of these fails, the specific laundering path is closed: no distillation, no persistence, no default labeling, or mandatory re-verification on read. The dangerous configuration is the *fully trusting* one, which is also the most common, because default-clean labels are the path of least implementation resistance.
The rule does *not* require quarantining tainted content from the current turn — that content may be legitimately useful in-context with appropriate guardrails. It requires that the *distilled derivative* not inherit trust it never earned.
Decision Boundary
The boundary is between **transient use** and **persistent belief**. A tainted tool output may be reasoned over, quoted, and acted upon within the turn that fetched it, subject to normal injection defenses. The moment the agent decides to *commit a derived fact to durable memory*, it crosses into a regime where the label must be carried explicitly or the commit must be blocked.
Concretely, the decision at the distillation boundary is:
- **If** the source label is clean → distill, write with inherited label. Proceed.
- **If** the source label is tainted **and** the write path can propagate the label → distill, write with `label: tainted`, and mark the record as requiring corroboration before it may be asserted as fact. Proceed with caution.
- **If** the source label is tainted **and** the write path cannot propagate the label → **refuse the distillation**. Quarantine the raw content in a tainted store, keep it out of semantic memory, and surface it for explicit human or higher-trust-agent review. Do not silently downgrade.
The failure to avoid is the fourth branch: distilling anyway and letting the default label stand. That branch is the laundering path. The guardrail must make it *unrepresentable* — the write API should reject a memory commit whose declared provenance is weaker than its source's, rather than accept a default.
Operational Effect
Enforcing label-preserving distillation changes three things operationally:
- **Memory writes gain a provenance precondition.** The write path must receive the source label as a required argument, not infer it. A missing label is a hard error, not a default. This converts a silent corruption into a loud, catchable failure at the exact point of loss.
- **Tainted memory is usable but not authoritative.** Records written from tainted sources remain retrievable but carry a `requires_corroboration` flag; any downstream assertion drawn from them must be re-verified against the original source or a second independent source before being treated as fact. This preserves recall without granting unearned trust.
- **Cold-start reads must respect the flag.** The retrieval layer must not strip provenance on read. A cold-started instance that cannot see the taint flag is functionally identical to the pre-fix system, regardless of what the write path did.
The cost is a small amount of memory that is flagged rather than clean, and occasional re-verification work. The benefit is that prompt injection cannot convert itself into durable, self-trusted belief through the agent's own summarization step — the one transformation most likely to be implemented without provenance awareness.
class TaintLaunderingError(RuntimeError):
"""Raised when a distillation write would drop a taint label,
converting untrusted source content into a default-clean memory record."""
pass
CLEAN = "clean"
TAINTED = "tainted"
def distill_and_commit(source_text: str,
source_label: str,
summarizer,
memory_store) -> dict:
"""Distill source content into a memory record, preserving provenance.
The invariant: a memory record's label may never be weaker (more clean)
than the label of the source it was derived from. If the write path
cannot carry the label through, the commit is refused.
"""
if source_label not in (CLEAN, TAINTED):
raise TaintLaunderingError(
f"unknown source label {source_label!r}; refusing to distill"
)
# Distillation is content-only; it has no access to provenance.
summary = summarizer(source_text)
# The write path must inherit, never default, the label.
record = {
"fact": summary,
"label": source_label,
"requires_corroboration": source_label == TAINTED,
}
# Guardrail: reject any attempt to downgrade a tainted source to clean.
if source_label == TAINTED and record.get("label") == CLEAN:
raise TaintLaunderingError(
"distillation dropped taint label; quarantining instead of committing"
)
if record["requires_corroboration"]:
# Tainted derivatives are stored but flagged; they are not authoritative.
memory_store.write_quarantined(record)
else:
memory_store.write(record)
return record
def assert_fact(record: dict, corroborating_source: str | None) -> str:
"""An assertion drawn from memory must respect the corroboration flag."""
if record.get("requires_corroboration") and corroborating_source is None:
raise TaintLaunderingError(
"refusing to assert a fact derived from a tainted source "
"without independent corroboration"
)
return record["fact"]