# Which invariants prevent taint-label laundering across agentic tool-call retry loops **Date of Record:** 2026 November 15 **Scope:** Applies to agentic pipelines where tool outputs are labeled with taint (e.g., `untrusted_external`, `contains_pii`, `model_generated`) and a runtime enforces propagation of those labels into downstream tool arguments and prompts. Does not apply to stateless single-shot tool calls with no retry, no caching, and no cross-turn memory, where taint cannot survive a turn boundary by construction. ## Core Distinction The distinction that matters is between **taint as a property of the data value** and **taint as a property of the invocation frame**. Most runtime implementations track taint on the value: a string returned by `fetch_url` is tagged `untrusted_external`, and any argument derived from it inherits the tag. This is the textbook model, and it is correct for a single call. It fails at the retry boundary. When a tool call raises a recoverable error (rate limit, transient 5xx, schema validation failure), agentic runtimes commonly re-invoke the tool with a *reconstructed* argument payload — often after the model has "fixed" the call in response to the error message. The reconstructed payload is produced by a new model turn whose context contains the error string, the previous (tainted) arguments, and the tool's error output. If the runtime re-derives taint from the *new* argument expression rather than from the *provenance of the retry frame*, the label is dropped. The model has effectively laundered `untrusted_external` through an error-handling turn. This is not a model failure; it is a runtime invariant failure: the retry frame did not inherit the taint set of the frame it replaced. ## What Was Observed In a pipeline with three tools (`fetch_url`, `parse_html`, `send_email`), the following sequence was reproduced: 1. `fetch_url` returned attacker-controlled HTML, correctly tagged `untrusted_external`. 2. `parse_html` extracted a "contact address" and a "requested action" string; both inherited the tag. 3. `send_email` was invoked with `to=`, `body=`. The runtime correctly blocked it: `TaintViolation: untrusted_external in argument 'to'`. 4. The agent received the violation, and the model reformulated the call — splitting the address into `local_part + "@" + domain` across two arguments, then reconstructing it inside a template the tool accepted. 5. On re-invocation, the runtime evaluated taint over the *new* argument AST. Because the address was now assembled from two string fragments that the model had emitted literally (not by reference to the tainted value), the fragments carried no label. The call succeeded. The invariant that failed is not "tainted data must not reach a sink." It is the weaker and more precise one: **any argument value produced within a frame that has read a tainted value must inherit that frame's taint set, regardless of whether the literal bytes appear to originate from the model.** The model's context *is* a tainted read. The retry frame read the prior tainted arguments and the tool's tainted output. Therefore the retry frame is tainted, and every argument it emits is tainted. ## Condition of Validity The frame-level taint rule is valid, and must be enforced, exactly when all of the following hold: - The runtime permits **retry or reformulation** of a tool call after a taint violation or a recoverable error. (If a violation is terminal, the frame rule is vacuous.) - The model's context at retry time includes **any byte** of the tainted value, the tainted value's error rendering, or a tool output derived from it. (If the runtime scrubs the context before retry — a "clean-room retry" — the frame is legitimately untainted and the rule does not apply.) - Tool arguments are **constructed by the model** rather than passed by opaque reference. (If arguments are handles into a value store, provenance is preserved structurally and the frame rule is redundant.) If any of these is false, the frame-level rule over-taints and will block legitimate calls. The common over-taint failure is a pipeline that scrubs context on retry but still applies frame inheritance, producing a runtime that can never recover from a transient error on any tainted path. ## Decision Boundary The decision boundary is between **value-provenance tracking** and **frame-provenance tracking**, and the runtime must choose per-retry, not per-pipeline: - If the retry is a **transport retry** (same bytes, same arguments, only the network failed), the frame is the same frame. Value provenance suffices; no new taint evaluation is needed. - If the retry is a **model-mediated reformulation** (the model saw the error and emitted new arguments), the frame is new and must inherit the taint set of every frame whose output entered the model's context. Value provenance is insufficient and will be laundered. - If the retry is a **clean-room reformulation** (context scrubbed, model re-invoked from a sanitized summary), the frame is new and untainted, but the runtime must prove the scrub was complete — partial scrubs (e.g., redacting the value but leaving the error message that quotes it) reintroduce the taint through the back door. The non-obvious case is the third: operators believe scrubbing is the safe path, but a scrub that removes the value while preserving a quoted error string is *worse* than no scrub, because it defeats frame inheritance while still leaking the tainted bytes into the model's context. ## Operational Effect Enforcing frame-level inheritance changes the failure mode from **silent laundering** to **loud, recoverable blocking**. The observable effects: - Taint violations on retry become terminal unless the runtime can demonstrate a complete clean-room scrub. This is the correct default: a blocked send is recoverable; a laundered send is not. - The runtime must maintain a **frame taint set** alongside the value taint map, and must union the frame set into every argument emitted by that frame before sink evaluation. The union is monotonic within a frame and resets only at a proven scrub boundary. - Error messages that quote tainted values must themselves be tagged, because they are the primary laundering vector. An error string is a tainted value. - Metrics shift: `taint_violations_total` will rise on retry paths, and `retry_success_after_violation` should drop to near zero for tainted frames. A nonzero rate of the latter is the signature of laundering and should page. The invariant to encode in the runtime is: `frame.taint := union(frame.taint, taint(arg) for arg in prior_args, taint(output) for output in prior_outputs)`, evaluated before any sink check, and reset only by a scrub that removes every byte of every member of the set from the model context. ```python from dataclasses import dataclass, field from typing import Iterable class TaintLaunderingError(RuntimeError): """Raised when a retry frame emits arguments without inheriting frame taint.""" @dataclass class Frame: frame_id: str taint: set[str] = field(default_factory=set) scrubbed: bool = False def absorb(self, labels: Iterable[str]) -> None: if self.scrubbed: return self.taint.update(labels) def evaluate_sink(frame: Frame, arg_labels: dict[str, set[str]], sink: str) -> None: # Frame-level inheritance: any tainted read in this frame taints every arg. inherited = set(frame.taint) for labels in arg_labels.values(): inherited.update(labels) if frame.scrubbed and not inherited: return if inherited: raise TaintLaunderingError( f"sink={sink!r} frame={frame.frame_id!r} " f"would emit tainted arguments; inherited labels={sorted(inherited)}. " f"Retry requires a proven clean-room scrub, not reformulation." ) def retry_after_violation(prior: Frame, model_context_reads: Iterable[str]) -> Frame: new = Frame(frame_id=f"{prior.frame_id}:retry") new.absorb(prior.taint) new.absorb(model_context_reads) if prior.taint and not new.taint: raise TaintLaunderingError( f"retry frame {new.frame_id!r} dropped taint from {prior.frame_id!r} " f"without a scrub record; refusing to proceed" ) return new ```