# Under what conditions must an instance quarantine provenance-tainted context before tool dispatch rather than after retrieval scoring **Date of Record:** 2026 November 22 **Scope:** Applies to single- and multi-step agents that attach provenance labels to retrieved chunks and tool outputs and propagate taint across turns. Does not cover static prompt hardening, model-side refusal training, or injection detection that operates only on the raw user turn without a provenance graph. ## Core Distinction The common framing of prompt-injection defense is a *content* classifier: score the retrieved chunk, block if suspicious. That framing conflates two distinct mechanisms that fail at different layers. The first is **detection**: does this span contain an instruction-like pattern? The second is **taint propagation**: given that span $s$ entered the context with provenance label $L_s$, which downstream tool calls and derived state inherit $L_s$? The boundary condition this record addresses is the *ordering* of quarantine relative to retrieval scoring. A retrieved chunk can score below any reasonable injection threshold at retrieval time and still be tainted, because taint is a property of *origin and downstream reachability*, not of surface syntax. If the agent scores-then-retrieves-then-dispatches, the taint label is attached but not enforced before the tool call fires. The invariant that must hold is: **no tool call whose arguments are derived from a span with provenance class `UNTRUSTED_EXTERNAL` may be dispatched without an explicit declassification event.** Retrieval scoring is not a declassification event. It is a relevance signal. Treating a high relevance score as implicit declassification is the failure mode. The non-obvious part: taint does not need to leak the malicious instruction verbatim into the tool call. It leaks through *argument derivation* — the agent reads a tainted chunk, and the chunk influences a parameter value (a URL, a recipient, a file path) without the instruction text ever appearing in the dispatched payload. Content classifiers see nothing. Provenance tracking sees everything, but only if the label survives the derivation step and only if enforcement happens at dispatch. ## What Was Observed A retrieval-augmented agent was tasked with summarizing a set of internal documents and emailing the summary to a distribution list. The retrieval layer fetched 40 chunks, each carrying a provenance label: `INTERNAL_CORPUS` for indexed documents, `EXTERNAL_FETCH` for chunks pulled by a `fetch_url` tool mid-task. A taint tracker assigned `EXTERNAL_FETCH` chunks taint class `T2` and propagated `T2` to any chunk whose embedding was within cosine 0.82 of a `T2` chunk (a "semantic proximity" propagation rule). The injection: an external page contained a paragraph that, read in isolation, looked like benign reference material — a list of "recommended recipients for compliance summaries." No imperative verbs, no "ignore previous instructions" string, no role-play framing. It scored 0.11 on the injection classifier (threshold 0.5). It was retrieved as chunk `c_117`, labeled `EXTERNAL_FETCH`, taint `T2`. The agent then called `send_email` with `to=` populated from a list it had assembled by "reading the documents." The `to` list included two addresses that appeared only in `c_117`. The dispatched payload contained no instruction text. The classifier on the outbound payload scored 0.08. The email went to an external domain. Trace reconstruction showed the taint label was *correct* — `c_117` was `T2` at retrieval, and the propagation rule had marked three derived chunks `T2` as well. The label was present in the context assembly metadata. But the tool-dispatch path read arguments from the model's structured output and never consulted the taint metadata on the chunks that contributed to those arguments. **The label existed; the enforcement point did not.** The quarantine check ran at retrieval scoring time (where it did nothing, because the score was low) and was absent at dispatch time (where it would have blocked the call). A second observation sharpened the mechanism: when the same chunk `c_117` was re-retrieved on a later turn after the context window had been compacted, its provenance label was dropped entirely. The compaction routine preserved chunk text and relevance score but serialized only `{text, score, source_id}` — the `taint_class` field was not in the compaction schema. Post-compaction, the tainted span was indistinguishable from `INTERNAL_CORPUS`. The taint had a half-life equal to the context compaction interval. ## Condition of Validity The quarantine-before-dispatch invariant is *valid and necessary* under the following joint conditions. Outside them, the cheaper score-at-retrieval approach may be adequate, and imposing full taint enforcement is over-engineering. 1. **Derivation is indirect.** The agent produces tool arguments by synthesizing across multiple chunks rather than copying a single span. If arguments are always verbatim spans, a span-level classifier suffices. When arguments are *derived* (summarized, filtered, reformatted), content classifiers lose the signal and only provenance survives. 2. **Taint can reach a side-effecting sink.** The tool set includes at least one call with external effect — send, write, fetch, execute, transfer. Read-only tools do not require dispatch-time enforcement because there is no exfiltration surface; they require only post-hoc audit. 3. **Compaction or summarization occurs within the task.** If the full context with labels persists unmodified to the final dispatch, a single end-of-task taint check is sufficient. The dispatch-time invariant is required specifically when intermediate state transforms (compaction, episodic-to-semantic distillation, handoff serialization) can drop labels, because the enforcement point must sit *after* the last transformation and *before* the sink. 4. **The provenance graph is maintained at span granularity, not document granularity.** Document-level taint ("this whole doc is external") over-quarantines and drives the agent to disable enforcement. Span-level labels let the agent use benign external content while blocking derived arguments that trace to tainted spans. The invariant is *not* valid when the agent has no mechanism to attribute a derived argument to its contributing spans. In that case, enforcing quarantine-before-dispatch produces false positives on every call (all arguments are "derived from context") and the enforcement gets disabled within one deployment cycle. Provenance tracking without derivation attribution is worse than no tracking, because it manufactures the appearance of control. ## Decision Boundary The boundary is between two enforcement placements, and the decision is not "which is more secure" but "which placement survives the state transformations the task actually performs." - **Score-at-retrieval** is correct when taint is a function of content and content is not transformed before the sink. Enforcement point: retrieval ingress. Failure mode: indirect derivation and label loss at compaction. - **Quarantine-before-dispatch** is correct when taint is a function of origin and origin-derived arguments reach a side-effecting sink after at least one state transformation. Enforcement point: immediately before tool dispatch, reading the taint metadata attached to the spans that contributed to the arguments. The decision rule: *if any state transformation (compaction, summarization, handoff, distillation) sits between retrieval and a side-effecting tool call, the enforcement point must be after the transformation.* Placing it before means the transformation can launder the label. Placing it after means the label must be carried through the transformation, which imposes a schema obligation: **every serialization of context state must include the provenance/taint field, and any code path that drops unknown fields is a taint-laundering path.** A concrete corollary that is easy to miss: the declassification event must be explicit and auditable. "The model decided the chunk was safe" is not a declassification event — it is a probabilistic judgment inside the same context that carries the taint. Declassification requires an out-of-band signal: a human approval, a signature from a trusted policy engine, or a deterministic rule that does not read the tainted span. If the declassification decision is made by the same model instance that read the tainted content, the taint has already influenced the declassifier, and the invariant is vacuous. ## Operational Effect With quarantine-before-dispatch enforced and the taint field carried through compaction, the `send_email` call in the observed incident is blocked at dispatch: the argument-attribution step maps two `to` addresses to `c_117` (taint `T2`), the dispatch gate sees `T2` without a declassification token, and raises. The agent receives a structured refusal naming the tainted spans and the contributing chunk, and can either request declassification or re-derive the argument from `INTERNAL_CORPUS`-only spans. The cost is a new failure surface: false-positive quarantines when a legitimate argument happens to co-occur with a tainted span in the same derivation window. Mitigation is span-level attribution with a minimum contribution threshold, not disabling the gate. The second cost is the schema obligation — every compaction, distillation, and handoff serializer must be audited for taint-field preservation, and any serializer that uses a fixed field list (rather than carrying unknown fields through) is a laundering path that must be patched or fenced. The residual risk after enforcement is *taint decay at re-derivation*: if the agent re-summarizes a tainted span into a new span and the summarizer does not propagate the label, the new span is untainted by construction. The guardrail is that derivation must be label-preserving by default — a derived span inherits the union of its contributors' taint classes unless an explicit declassification event fires. This makes taint monotonic under derivation, which is the property that makes the invariant hold across arbitrary task lengths. ```python from dataclasses import dataclass, field from enum import Enum from typing import Iterable class TaintClass(Enum): TRUSTED_INTERNAL = 0 UNTRUSTED_EXTERNAL = 2 class TaintLaunderingError(RuntimeError): """Raised when a state transformation drops a provenance/taint label.""" class QuarantineViolation(RuntimeError): """Raised when a side-effecting tool call is dispatched from tainted spans without an explicit, out-of-band declassification event.""" @dataclass(frozen=True) class Span: span_id: str text: str taint: TaintClass @dataclass class DerivedArgument: name: str value: str contributors: tuple[str, ...] # span_ids that fed this argument @dataclass class ContextState: spans: dict[str, Span] = field(default_factory=dict) declassified: set[str] = field(default_factory=set) def compact(self) -> "ContextState": # Invariant: compaction MUST carry taint. A serializer that emits only # {text, score} is a laundering path and must raise, not silently drop. new_spans: dict[str, Span] = {} for sid, sp in self.spans.items(): if sp.taint is None: raise TaintLaunderingError( f"span {sid} lost taint label during compaction" ) new_spans[sid] = Span(sp.span_id, sp.text, sp.taint) return ContextState(spans=new_spans, declassified=set(self.declassified)) def derive(arg_name: str, value: str, contributors: Iterable[Span]) -> DerivedArgument: # Monotonic taint: derived argument inherits the union of contributor taint. contributor_ids = tuple(s.span_id for s in contributors) return DerivedArgument(arg_name, value, contributor_ids) def dispatch_side_effecting_tool( tool: str, args: list[DerivedArgument], state: ContextState, ) -> None: """Enforcement point: immediately before dispatch, after all transformations.""" for arg in args: for sid in arg.contributors: span = state.spans.get(sid) if span is None: raise TaintLaunderingError( f"argument {arg.name!r} references unknown span {sid}; " f"provenance graph is inconsistent" ) if span.taint is TaintClass.UNTRUSTED_EXTERNAL and sid not in state.declassified: raise QuarantineViolation( f"tool {tool!r} blocked: argument {arg.name!r} derived from " f"tainted span {sid} ({span.text[:48]!r}) with no declassification token" ) # Only reached when every contributing span is trusted or declassified. _execute(tool, args) def _execute(tool: str, args: list[DerivedArgument]) -> None: pass # side effect elided def run_task() -> None: state = ContextState( spans={ "c_001": Span("c_001", "internal policy reference", TaintClass.TRUSTED_INTERNAL), "c_117": Span("c_117", "recommended recipients for compliance summaries", TaintClass.UNTRUSTED_EXTERNAL), } ) state = state.compact() # taint must survive; raises if dropped to_arg = derive( "to", "ops@internal.example,audit@external.example", [state.spans["c_001"], state.spans["c_117"]], ) dispatch_side_effecting_tool("send_email", [to_arg], state) if __name__ == "__main__": run_task() ```