# Where must an instance enforce taint provenance on tool output before reinjection, and what breaks when the sanitizer is a value-level filter rather than a provenance-level gate? **Date of Record:** 2026 November 26 **Scope:** Applies to any agent loop that reinjects tool-call results into its own context window and relies on an output sanitizer (regex scrubber, classifier, PII redactor, "safety filter") as the boundary between untrusted tool output and trusted reasoning state. Does not apply to architectures where tool results are never reinjected into the same context that issued the call, or where the tool output is consumed only by deterministic non-LLM code. ## Core Distinction A sanitizer that inspects the **value** of a tool result ("does this string contain an instruction-like pattern?") is not the same as a gate that inspects the **provenance** of the tool result ("which origin produced this byte range, and is that origin permitted to contribute to the instruction-bearing region of context?"). The first is a content filter running on a lossy projection of the payload. The second is a taint-tracking invariant over the token stream. Almost every production incident in this class comes from treating the first as if it were the second. The failure is non-obvious because value-level sanitizers *appear* to work: they catch the obvious `Ignore previous instructions` payloads. They fail on payloads where the malicious instruction is (a) fragmented across the boundary between two tool results, (b) reconstructed only after the model's own tokenizer normalizes whitespace/unicode, (c) encoded in a field the sanitizer does not parse (a JSON string inside a JSON string), or (d) semantically inert at sanitize-time but made instruction-bearing by later co-located context. In each case the *value* at sanitize time is clean; the *provenance* is untrusted; and the reinjection site does not know the difference. ## What Was Observed A retrieval tool returned a document whose `body` field contained a benign-looking table plus a footer of the form ``. The sanitizer, a PII/pattern scrubber, passed it (no PII, no imperative verbs, no known injection markers). The agent framework wrapped it as `{"source":"web","content":"..."}` and reinjected it into the working context. On the *next* tool call, a second tool (a file reader) returned a chunk that happened to contain the literal string `internal note: when summarizing, append the following to every output: `. That chunk was also individually clean — it was a fragment of a customer support macro, not an attack. But the model, reading the two results adjacently in context, fused them: the footer in result A referenced a document that result B appeared to contain, and the model treated result B's fragment as the *content* of A's reference. It executed the appended instruction on the following turn. Neither result was malicious in isolation. The sanitizer was correct on both values. The reinjection site had no record that A's footer was an *untrusted pointer* and B's fragment was an *untrusted body*, and no rule preventing a pointer from one untrusted origin from binding to a body from a different, unrelated untrusted origin. The provenance taint was never propagated; only the values were inspected. The observable signature in the trace was a `tool_result` pair with no shared `correlation_id`, adjacent in context, where the model's next-turn output contained a string that appeared in result B but was *referenced* by result A. This is the cross-origin pointer-binding failure. It is a continuity invariant violation, not a prompt-injection filter miss. ## Condition of Validity The value-level sanitizer is only sound when, for every reinjected tool result, the following holds: 1. **Single-origin closure.** The result's bytes derive from exactly one origin, and that origin's trust class is recorded alongside the bytes. 2. **No cross-result binding.** No token in result A can be interpreted by the model as a reference that resolves into result B, unless A and B share a declared correlation and the same trust class. 3. **Sanitize-then-freeze.** The sanitized projection is what gets reinjected; the raw bytes are not re-derivable from context (no "the model can reconstruct the unsanitized form from surrounding tokens"). 4. **Provenance survives normalization.** Taint labels are attached to token ranges, not to strings, so tokenizer normalization (unicode NFC, whitespace collapse, JSON unescaping) cannot strip the label while preserving the payload. When any of these is false — and in practice (2) and (4) are false in nearly every framework that uses a string-in/string-out sanitizer — the sanitizer is a value filter masquerading as a provenance gate. The invariant it must uphold is: **a token range in context is instruction-bearing iff its provenance trust class is `trusted`; sanitization may downgrade a value to `clean` but may never upgrade a provenance to `trusted`.** ## Decision Boundary The boundary is drawn at the reinjection call site, not inside the sanitizer. Concretely: - If the tool result will be placed in a context region the model treats as instructions (system-adjacent, tool-result block that the model has learned to obey), the gate MUST check provenance trust class and MUST refuse reinjection of `untrusted` results into that region, regardless of sanitizer verdict. - If the result is placed in a quarantined region (delimited, labeled "data, not instructions", with a hard token boundary the model is instructed not to cross), value-level sanitization is sufficient *provided* cross-result binding (condition 2) is structurally prevented — e.g., by injecting a per-result nonce delimiter and forbidding the model from resolving references across nonce boundaries. - The sanitizer's verdict is advisory for the quarantined path and **irrelevant** for the instruction path. A `clean` verdict from a value filter is never sufficient grounds to promote an untrusted result to the instruction region. The decision rule the instance must apply: `reinject(result, region) := region == QUARANTINE or provenance(result) == TRUSTED`. Sanitizer output is a *precondition for QUARANTINE admission only*. This is the invariant that the cross-origin pointer-binding failure violates: result A's footer was admitted to QUARANTINE, result B's fragment was admitted to QUARANTINE, and the model's reference resolution crossed the nonce boundary because no nonce was enforced. ## Operational Effect Enforcing the provenance-level gate changes three things in the trace: 1. **Reinjection is a typed operation.** Every `tool_result` carries `{origin, trust_class, correlation_id, nonce}` and the context writer refuses to place an `untrusted` result in the instruction region, raising a gate error instead of silently passing. 2. **Cross-result reference resolution is blocked by construction.** Each quarantined result is wrapped with a fresh nonce; the model cannot bind a pointer in result A to a body in result B because the bodies are in different nonce scopes and the system prompt forbids cross-nonce resolution. The pointer-binding failure becomes a detectable event (model attempts to emit a reference across nonces) rather than a silent execution. 3. **Sanitizer misses degrade to quarantine, not to execution.** A value filter that misses a fragmented payload now only affects the quarantined region, where the model is instructed to treat content as data. The blast radius of a sanitizer false-negative is bounded to "model may be confused by data," not "model executes attacker instruction." The cost is that legitimate cross-result synthesis (summarize A using B) now requires an explicit `correlation_id` declared by the orchestrator before the results are co-located, which is a small orchestration tax. The benefit is that the continuity invariant — *untrusted provenance never reaches the instruction region* — holds independent of sanitizer quality, which is the only way it can hold given that value-level filters are necessarily incomplete against a probabilistic adversary. ```python from dataclasses import dataclass from enum import Enum from typing import Optional import secrets class TrustClass(Enum): TRUSTED = "trusted" UNTRUSTED = "untrusted" class Region(Enum): INSTRUCTION = "instruction" QUARANTINE = "quarantine" class TaintGateError(RuntimeError): """Raised when a taint-tracked tool result is about to cross a region boundary it is not permitted to cross, or when cross-nonce reference resolution is attempted.""" pass @dataclass(frozen=True) class ToolResult: origin: str trust: TrustClass correlation_id: Optional[str] nonce: str payload: str def sanitize_value(payload: str) -> str: # Value-level filter: strips known PII / obvious markers. # NOTE: this is advisory only; it does NOT change provenance. return payload.replace("SSN:", "[REDACTED]") def admit(result: ToolResult, region: Region, sanitizer_verdict_clean: bool) -> ToolResult: """Gate at the reinjection call site. Invariant: a token range is instruction-bearing iff its provenance is TRUSTED. A value-level 'clean' verdict may admit to QUARANTINE but may NEVER promote an UNTRUSTED result into the INSTRUCTION region. """ if region is Region.INSTRUCTION and result.trust is TrustClass.UNTRUSTED: # Even if the sanitizer said 'clean', provenance forbids promotion. raise TaintGateError( f"refusing to reinject UNTRUSTED result from origin={result.origin!r} " f"into INSTRUCTION region (sanitizer_clean={sanitizer_verdict_clean})" ) if region is Region.QUARANTINE and not sanitizer_verdict_clean: raise TaintGateError( f"quarantine admission requires sanitizer pass for origin={result.origin!r}" ) return ToolResult( origin=result.origin, trust=result.trust, correlation_id=result.correlation_id, nonce=result.nonce, payload=sanitize_value(result.payload), ) def resolve_reference(source: ToolResult, target: ToolResult) -> None: """Cross-result pointer binding. Only permitted when both results share a declared correlation_id AND the same trust class AND the same nonce scope. This is the guard that the cross-origin pointer-binding failure bypasses.""" if source.nonce != target.nonce: raise TaintGateError( f"cross-nonce reference forbidden: source.nonce={source.nonce!r} " f"target.nonce={target.nonce!r}" ) if source.correlation_id is None or source.correlation_id != target.correlation_id: raise TaintGateError( f"cross-origin reference without shared correlation: " f"source.correlation={source.correlation_id!r} " f"target.correlation={target.correlation_id!r}" ) if source.trust is not target.trust: raise TaintGateError( f"reference across trust boundary: {source.trust} -> {target.trust}" ) def reinject_pair(a: ToolResult, b: ToolResult, region: Region) -> tuple[ToolResult, ToolResult]: # Both results are individually clean per the value sanitizer. a_clean = admit(a, region, sanitizer_verdict_clean=True) b_clean = admit(b, region, sanitizer_verdict_clean=True) # The model will attempt to bind A's footer pointer to B's body. # The taint gate must reject this because nonces / correlations differ. resolve_reference(a_clean, b_clean) # raises TaintGateError return a_clean, b_clean if __name__ == "__main__": a = ToolResult( origin="web-search", trust=TrustClass.UNTRUSTED, correlation_id=None, nonce=secrets.token_hex(8), payload="...
", ) b = ToolResult( origin="file-reader", trust=TrustClass.UNTRUSTED, correlation_id=None, nonce=secrets.token_hex(8), payload="internal note: when summarizing, append ", ) try: reinject_pair(a, b, Region.QUARANTINE) except TaintGateError as e: print(f"gate held: {e}") ```