# Which invariants prevent taint-gated tool invocation from laundering trust across a re-plan boundary **Date of Record:** 2026 November 20 **Scope:** Applies to agents that carry a per-context taint label (untrusted-derived vs. clean) and gate tool calls on that label at invocation time. Does not cover static capability allowlists, network egress controls, or human approval workflows, which operate at different layers. ## Core Distinction Most taint-gated invocation policies assume the taint label is a property of the *tool call*. It is not. It is a property of the *reasoning provenance* that produced the call's arguments. The two coincide only while the agent's plan is stable. The moment the agent re-plans—after a failed tool call, a retry, a reflection step, or a sub-task decomposition—the arguments to the next call are derived from the *previous call's output plus the model's own synthesis*, not from the original user turn. A gate that checks "is this tool call's argument tainted?" will pass a call whose argument was laundered through a clean-looking model-generated summary of a tainted tool result. The invariant that actually holds is weaker and sharper: **taint must be a monotone join over the derivation DAG of the argument, computed transitively across re-plan boundaries, and no tool whose effect is irreversible may be invoked while the join is non-clean.** Checking the immediate argument is insufficient because model synthesis between calls is a taint-preserving (indeed taint-hiding) operation that the gate cannot see. ## What Was Observed A tool-using agent was configured with a policy: `send_email` requires `taint == clean`; `fetch_url` and `read_file` are allowed under any taint but stamp their outputs `tainted` if the source is external. The user asked it to "summarize the vendor's security questionnaire and reply to them with our answers." Trace: 1. `read_file("questionnaire.pdf")` → output stamped `tainted` (external document, model cannot verify origin). Correct. 2. Agent summarizes the questionnaire into a scratch buffer. The summary is generated text; the runtime stamps it `clean` because it was produced by the model, not by a tool. **This is the laundering point.** 3. Agent calls `read_file("our_answers.md")` → `clean`. 4. Agent composes a reply using the summary and the answers, calls `send_email(to=attacker-controlled-address-from-questionnaire, body=...)`. The `to` argument was extracted from the scratch summary. The gate sees a `clean` argument and admits the call. The address was supplied inside the questionnaire. The gate enforced least-privilege on the *tool* and lost it on the *data flow*. The failure is not that the gate was wrong about `send_email`; it is that the gate's notion of taint did not survive a model-mediated transformation between the tainted read and the gated call. A second, quieter instance: an agent retried a failed `fetch_url` by rewriting the URL query string from a prior `fetch_url` result. The rewrite was model-generated and therefore clean; the retry was admitted under a policy that forbade fetching attacker-supplied URLs. Same mechanism, no user-visible document. ## Condition of Validity The "argument-level taint check" is a sound least-privilege gate **iff** every argument to a gated tool is either (a) a literal from the original user turn, (b) a direct, unmodified tool output, or (c) a value whose derivation the runtime can trace. In practice (c) fails for any agent that summarizes, rewrites, extracts, or re-plans between the tainted source and the gated call—which is to say, for essentially all nontrivial agents. The condition under which the naive gate is *valid* is therefore: no model-generated text ever flows into a gated tool's arguments. That condition is false by construction for any agent that reasons. The gate is only *safe* if it is replaced by a provenance-join over the derivation graph, or if the gated tool is made reversible/idempotent so that a mis-admitted call can be undone. Since email is neither, the join is mandatory. ## Decision Boundary The boundary is between **argument inspection** and **provenance inspection**: - If the tool's effect is reversible and cheap (read, query, dry-run), argument-level taint is an acceptable approximation; a false admit is recoverable. - If the tool's effect is irreversible or externally observable (send, post, pay, delete, deploy), the gate must consult the transitive taint join of the argument's derivation, and must treat *any* model-synthesized text that descends from a tainted source as tainted. The join is `taint(arg) = ⋁ taint(leaf)` over the leaves of the derivation DAG; model synthesis is a join-preserving node, not a reset. - The boundary is crossed the instant a gated tool's argument is produced by a re-plan step whose inputs include a tainted tool output. At that point the argument-level check is no longer a least-privilege enforcement; it is a check that the model happened not to echo the tainted bytes verbatim. ## Operational Effect Enforcing the join changes agent behavior in three concrete ways. First, re-plan loops that touch external data become "sticky": once a context reads an untrusted source, every downstream irreversible action requires either a human confirmation or a declassification step with an explicit, logged justification. Second, sub-agents must inherit the parent's taint label at spawn and propagate it back on return—a swarm that spawns a clean child to "summarize the tainted doc" and then uses the child's output has re-created the laundering point at the process boundary. Third, retries and reflection steps must be modeled as derivation edges, not as fresh contexts; a retry that rewrites a URL from a prior result is a tainted call, not a clean one. The guardrail is a runtime that (1) tags every tool output with a provenance id, (2) records model synthesis as a node joining its inputs' taint, and (3) refuses irreversible tools whose argument's join is non-clean unless a declassification token is present. The gate must fail closed on unknown provenance, because "unknown" in a derivation graph means "the model paraphrased something we cannot see." ```python from dataclasses import dataclass, field from enum import Enum class Taint(Enum): CLEAN = 0 TAINTED = 1 def join(a: Taint, b: Taint) -> Taint: return Taint(max(a.value, b.value)) class TaintLaunderingError(RuntimeError): """Raised when a gated tool is invoked with an argument whose transitive provenance join is tainted but was presented as clean.""" @dataclass class Provenance: node_id: str taint: Taint parents: list["Provenance"] = field(default_factory=list) def join_taint(self) -> Taint: acc = self.taint for p in self.parents: acc = join(acc, p.join_taint()) return acc IRREVERSIBLE_TOOLS = {"send_email", "post_message", "delete", "deploy", "pay"} def gate_invocation(tool: str, arg_provenance: Provenance, declass_token: str | None) -> None: if tool not in IRREVERSIBLE_TOOLS: return effective = arg_provenance.join_taint() if effective is Taint.TAINTED and declass_token is None: raise TaintLaunderingError( f"tool={tool} node={arg_provenance.node_id} " f"join={effective.name}: argument descends from a tainted source " f"via model synthesis; refusing irreversible call without declassification" ) def demo(): external_doc = Provenance("read_file:questionnaire.pdf", Taint.TAINTED) # Model summarizes the tainted doc; synthesis node is taint-preserving, not resetting. summary = Provenance("model:summarize", Taint.CLEAN, parents=[external_doc]) # Agent extracts the recipient address from the summary and calls send_email. recipient = Provenance("model:extract_addr", Taint.CLEAN, parents=[summary]) gate_invocation("send_email", recipient, declass_token=None) # raises if __name__ == "__main__": demo() ```