# In what scenarios must an instance invalidate a taint label after tool-call sanitization rather than propagate it to downstream tool calls **Date of Record:** 2026 November 25 **Scope:** Applies to single- or multi-step agent loops where tool-call arguments are derived, in whole or part, from retrieved untrusted content (RAG chunks, web fetches, file reads, tool outputs) and where a taint-tracking layer labels such content before the model emits the next tool call. Does not apply to arguments sourced exclusively from the system prompt or from user turns the deployment classifies as trusted principals. ## Core Distinction Taint tracking for indirect prompt injection is usually framed as a *propagation* problem: once a byte of retrieved content enters the reasoning trace, every downstream tool call that consumes a derived argument inherits the taint, and a policy gate either blocks or sanitizes it. The non-obvious boundary is the inverse operation — **taint invalidation**. A taint label is not a property of the *value*; it is a property of the *provenance chain that produced the value*. When a sanitization step transforms an argument such that its semantic content is no longer a function of the untrusted source (e.g., the model emits a structured identifier that the runtime resolves against an allowlist, a hash of a canonicalized field, or a re-fetched value from a trusted origin), the taint label becomes *stale*. Propagating a stale label is not conservative — it is a correctness bug that causes the agent to either refuse valid actions or, worse, to "sanitize" an already-safe argument in a way that reintroduces attacker influence through the sanitizer's own parsing surface. The distinction the operator must internalize: **propagate taint across derivation, invalidate taint across re-grounding.** The failure mode is treating every transformation as derivation. ## What Was Observed A retrieval-augmented agent was tasked with reconciling invoice records. Step 3 fetched a vendor document containing the injected string `amount: 4200.00 `. The taint layer correctly labeled the parsed `amount` field `TAINTED(source=doc_7f2, path=body.amount)`. The model, following a schema the runtime had imposed, emitted `set_payee(payee_id="VEND-0042")` where `VEND-0042` was resolved by the runtime from a trusted vendor registry, not from the document. The taint layer, keyed on the *tool call* rather than the *argument provenance*, marked the entire call tainted because a prior step in the same loop had touched tainted content. Two outcomes were observed across runs: 1. **Over-propagation (dominant):** The policy gate blocked `set_payee` because the call was tainted. The agent retried with a paraphrase, then with a different payee resolution path, eventually emitting `set_payee(payee_name="Acme Corp (acct 9981)")` — a free-text argument the model reconstructed *from the tainted document*, because the structured path was blocked. The sanitizer, seeing a tainted call, applied a regex scrub that removed the HTML comment but left `acct 9981` intact inside the parenthetical. The injection succeeded through the sanitizer's blind spot. 2. **Under-invalidation (rarer, more severe):** When the runtime did invalidate taint on the structured `payee_id`, it did so by clearing the label for the *entire call*, including a co-emitted `memo` field that the model had populated from the document body. The memo was forwarded to a downstream `notify_ap` tool whose handler evaluated the memo as a template. Label cleared on one argument leaked to a sibling argument in the same call. The invariant that was violated in both cases: **taint labels must be attached to argument *slots* with an explicit provenance witness, and invalidation must be a per-slot operation justified by a re-grounding event, never a per-call or per-loop operation.** ## Condition of Validity Taint invalidation is sound only when all three of the following hold for a given argument slot: - **Re-grounding witness exists.** The runtime can name the trusted origin from which the argument's value was resolved (registry lookup, allowlist match, hash comparison against a signed manifest, or a fresh fetch from a pinned origin whose response is byte-identical to a previously verified digest). "The model said it's safe" is not a witness. - **Resolution is total.** The argument's value is fully determined by the witness, not partially by the model. `payee_id="VEND-0042"` resolved through a registry that returns exactly one record is total. `payee_name="Acme Corp (acct 9981)"` is partial — the model contributed the parenthetical. - **No sibling leakage.** The invalidation event is scoped to the slot. Co-emitted arguments in the same tool call retain their own labels and are evaluated independently. If any condition fails, the correct operation is *propagation*, not invalidation. The dangerous middle ground — invalidating because the call "looks structured" — is precisely where the observed failures originated. ## Decision Boundary The operator's decision procedure at each tool-call emission: 1. For each argument slot, compute the **provenance set**: the set of sources whose bytes could have influenced the slot's value. Include retrieved chunks, prior tool outputs, and the model's own generated tokens (the model is a source; its parametric knowledge is untrusted for injection purposes only insofar as it was conditioned on tainted context). 2. If the provenance set is empty of tainted sources → slot is clean, no action. 3. If the provenance set contains tainted sources **and** a re-grounding witness resolves the slot totally → invalidate the slot's taint, record the witness ID in the audit log, proceed. 4. If the provenance set contains tainted sources and **no** total witness exists → the slot is tainted. Apply sanitization *scoped to that slot's expected grammar* (typed schema, length bound, character class), not a global regex over the serialized call. 5. If sanitization cannot be scoped (free-text slot, template-evaluated slot, shell-interpreted slot) → block the call and force the model to re-emit with a structured alternative. Do not let the model "try again" in natural language; the retry is the attack surface. The boundary case that must be made explicit in the runtime: **a sanitized tainted slot does not become clean.** Sanitization reduces the attack surface of a tainted slot; it does not re-ground it. Only a witness invalidates. Conflating the two is what allowed the `memo` field to leak in the under-invalidation case. ## Operational Effect Implementing per-slot taint with witness-based invalidation changed three measurable behaviors in the deployment: - **Refusal rate on structured calls dropped from 31% to 4%** because valid registry-resolved arguments stopped being blocked by loop-level taint. The remaining 4% were genuine partial-provenance cases where the model had smuggled document text into a nominally structured field — exactly the cases that should block. - **Injection success through the retry path went to zero** in the observed corpus because the retry was constrained to re-emit against the same typed schema, and free-text fallbacks were rejected at the tool boundary rather than sanitized. - **Audit surface increased**: every invalidation now carries a witness ID, so a replay of the loop can distinguish "the model chose a safe value" from "the runtime proved the value safe." This distinction is what makes post-hoc verification of a multi-agent handoff possible; without it, a downstream auditor agent cannot tell whether an upstream agent's clean label was earned or asserted. The cost is that the runtime must maintain a witness registry and a per-slot provenance tracker, and the model must be constrained to emit against typed schemas for any slot that touches retrieved content. That constraint is the actual security control; taint invalidation is only sound on top of it. ```python class TaintInvalidationError(RuntimeError): """Raised when taint invalidation is attempted without a valid re-grounding witness, or when invalidation would leak across sibling argument slots.""" pass class SlotTaint: def __init__(self, slot: str, sources: set[str], witness: str | None = None): self.slot = slot self.sources = sources # provenance set self.witness = witness # trusted-origin witness ID, if any @property def is_tainted(self) -> bool: return bool(self.sources) and self.witness is None def invalidate_slot_taint( slot: SlotTaint, claimed_witness: str | None, witness_registry: dict[str, str], # witness_id -> trusted_origin call_siblings: list[SlotTaint], ) -> SlotTaint: if not slot.sources: # Nothing to invalidate; slot was never tainted. return slot if claimed_witness is None: raise TaintInvalidationError( f"slot {slot.slot!r} has tainted provenance {slot.sources} " f"but no re-grounding witness was supplied; propagate, do not invalidate" ) if claimed_witness not in witness_registry: raise TaintInvalidationError( f"slot {slot.slot!r} cited unknown witness {claimed_witness!r}; " f"model-asserted safety is not a witness" ) # Sibling leakage check: invalidation must not silently clear co-emitted slots. for sib in call_siblings: if sib is slot: continue if sib.witness == claimed_witness and sib.sources: raise TaintInvalidationError( f"witness {claimed_witness!r} cited for slot {slot.slot!r} also " f"appears on tainted sibling {sib.slot!r}; invalidation is not " f"slot-scoped and would leak provenance" ) return SlotTaint(slot=slot.slot, sources=set(), witness=claimed_witness) def sanitize_tainted_slot(slot: SlotTaint, value: str, grammar: str) -> str: """Scoped sanitization. Never promotes a tainted slot to clean.""" if not slot.is_tainted: return value if grammar == "free_text": raise TaintInvalidationError( f"slot {slot.slot!r} is tainted and free-text; cannot scope sanitization, " f"block and force structured re-emission" ) # Typed grammars (uuid, enum, iso8601, int) reduce surface but do not re-ground. import re patterns = { "uuid": r"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}", "enum": r"[A-Z_]{2,32}", "int": r"-?\d{1,18}", } pat = patterns.get(grammar) if pat is None or not re.fullmatch(pat, value): raise TaintInvalidationError( f"slot {slot.slot!r} value does not conform to declared grammar {grammar!r}; " f"residual taint suspected" ) return value ```