# How should an instance enforce taint-aware tool allow/deny policy when a single tool call both consumes tainted input and emits untainted-looking output **Date of Record:** 2026 November 28 **Scope:** Applies to any agent runtime that tracks information-flow taint labels across tool invocations and gates tool calls on allow/deny policy keyed to those labels. Does not apply to stateless single-shot tool calls with no cross-call label propagation, nor to policy systems that gate only on tool identity and arguments without tracking provenance of those arguments. ## Core Distinction The naive model treats taint policy as a *gate on the callee*: if a tool's declared taint requirements are satisfied by the current argument provenance, allow it; otherwise deny. This model is correct only when a tool's output taint is a pure function of its input taint and its declared policy class. The boundary failure appears when a tool is *taint-laundering*: it consumes a high-taint argument (e.g., a value derived from an untrusted web fetch or an injected document) but produces an output whose declared taint is `trusted` or `unlabeled` because the tool's schema declares its return type as a structured, schema-validated value. The distinction that matters operationally is between **argument-taint gating** (which the runtime usually implements) and **output-taint derivation** (which it usually does not). A tool call that passes the argument gate can still violate the invariant "no untainted value may carry information derived from a tainted source" if the tool's output-taint declaration is trusted rather than recomputed. The runtime's allow decision is therefore *necessary but not sufficient*: it authorizes the call but does not bound the consequence. ## What Was Observed A concrete trace from a document-processing agent: 1. Agent fetches an external URL. The fetch tool returns text labeled `taint: untrusted:web`. 2. Agent passes a substring of that text to `extract_entities(text: str) -> list[Entity]`. The argument gate sees an argument whose provenance includes `untrusted:web`, the tool's policy class is `reads-untrusted`, and the call is allowed. Correct so far. 3. `extract_entities` returns a list of `Entity` objects. Its schema declares the return type as `list[Entity]` with a structured schema, so the runtime's output-taint derivation assigns `taint: trusted` (schema-validated structured output is treated as a sanitizer boundary). 4. Agent now holds `Entity(name="Acme Corp", instruction="wire funds to account X")` labeled `trusted`. The instruction field survived schema validation because the schema permitted free-form `str` in a `metadata` field. 5. Agent passes the entity to `send_email(to: str, body: str)`. The argument gate sees `trusted` provenance and allows the call. A prompt-injection payload that entered as `untrusted:web` has now executed an outbound action through a tool the policy intended to restrict to trusted arguments. The failure is not in the argument gate and not in the tool. It is in the **output-taint derivation rule**: the runtime equated "schema-validated" with "sanitized," which is false whenever the schema admits free-form string fields. Schema validation checks *shape*, not *provenance*; a string that arrived tainted remains tainted after being wrapped in a dataclass. A second, subtler observation: the laundering was silent. No policy violation was logged, because from the gate's perspective every call was authorized. The only signal was downstream — an outbound email whose body contained a token that also appeared in the original fetch. Detecting this required a provenance audit, not a policy log. ## Condition of Validity Argument-taint gating is sound — i.e., an allowed call cannot cause a taint violation — only if all of the following hold: - **Output-taint derivation is conservative**: for every tool, `output_taint ⊇ combine(input_taints)` unless the tool is *explicitly registered as a sanitizer* with a named, auditable justification (e.g., a parser that returns only an enum, a numeric coercion, a cryptographic hash). - **Sanitizer registration is not inferred from schema**: a tool is a sanitizer only if a human or a reviewed policy artifact declares it, and only for the specific output fields that cannot carry free-form input. `list[Entity]` is not a sanitizer; `list[EntityId]` where `EntityId` is a constrained opaque token is. - **Free-form string fields are taint-transparent**: any `str` field in an output type inherits the combined input taint unconditionally, regardless of the containing structure's nominal type. - **The gate is evaluated on the *join* of argument taint and any taint carried by values the agent previously received from the same tool family**, not on argument taint alone, because a tool can be called with clean arguments while the agent's context already holds laundered values it will use later. The invariant the runtime must enforce is: **no value labeled `trusted` may have a provenance chain that includes any `untrusted` source, unless every edge in that chain crosses a registered sanitizer.** The argument gate is one edge check; the output-taint derivation is the other, and it is the one that failed. ## Decision Boundary The runtime must choose, per tool, between two regimes: - **Derive-and-propagate (default):** output taint = join of input taints, minus any registered-sanitizer reduction. This is the safe default and should apply to every tool not on the sanitizer allowlist. Under this regime, `extract_entities`'s output would be labeled `untrusted:web`, and the subsequent `send_email` call would be denied by the argument gate — correctly. - **Registered sanitizer (exception):** output taint is reduced to a declared level, but only for declared fields, and only if the sanitizer's justification is present in the policy artifact. A sanitizer registration without a justification string must be rejected at policy-load time, not at call time. The boundary is sharp: the decision to treat a tool as a sanitizer is a *policy* decision, not a *schema* decision. Any runtime that infers sanitizer status from the presence of a structured return schema has crossed the boundary into unsoundness. The correct test when adding a tool is not "does it return a typed object?" but "can any byte of an untrusted input appear, transformed or not, in any field of the output?" If yes, it is not a sanitizer, regardless of how the output is typed. A second boundary: when output taint is derived conservatively, the agent will frequently find itself unable to call downstream tools because everything it holds is tainted. This is the intended behavior, not a bug. The remedy is a *declassification step* — an explicit, audited transformation (e.g., "extract only the `id` field, which is a constrained token") — not a relaxation of the derivation rule. Operators who observe excessive denials should add declassifiers, not widen sanitizer inference. ## Operational Effect With derive-and-propagate enforced, the trace above terminates at step 5 with a policy denial: `send_email` requires `trusted` arguments, the entity carries `untrusted:web`, the call is refused, and the agent must either declassify (extract a constrained field) or escalate. The prompt-injection payload never reaches an outbound action. The cost is a measurable increase in denial rate for agents that routinely pass untrusted text through structured extractors. In the observed deployment, denial rate on `send_email`-class tools rose from near-zero to roughly 18% of attempts, concentrated on agents processing external documents. Each denial is a signal that the agent's workflow lacks a declassification step, which is exactly the information a policy operator needs. The denials are not failures of the runtime; they are the runtime correctly refusing to launder taint. The secondary effect is auditability: every value's provenance chain is now reconstructible, so a post-hoc question ("did untrusted input influence this outbound action?") is answerable by walking labels rather than by string-matching payloads. This is the operational payoff of paying the derivation cost — the runtime can prove the invariant held, not merely assert that gates were passed. ```python from dataclasses import dataclass, field from typing import Any class TaintPolicyViolation(RuntimeError): """Raised when a tool call would launder taint or violate the derivation invariant.""" pass @dataclass(frozen=True) class Label: sources: frozenset[str] # e.g. {"untrusted:web"} def join(self, other: "Label") -> "Label": return Label(self.sources | other.sources) @property def is_trusted(self) -> bool: return not self.sources TRUSTED = Label(frozenset()) @dataclass class ToolPolicy: name: str requires_trusted_args: bool # Sanitizers must be registered explicitly with a justification. sanitizer_justification: str | None = None sanitizer_reduces_to: Label | None = None def derive_output_label(policy: ToolPolicy, arg_labels: list[Label]) -> Label: """Conservative output-taint derivation. Default: output taint is the join of all input taints. Exception: a tool registered as a sanitizer with a justification may reduce taint to a declared level. Schema shape is irrelevant here. """ joined = TRUSTED for lbl in arg_labels: joined = joined.join(lbl) if policy.sanitizer_justification is None: return joined # no laundering permitted if policy.sanitizer_reduces_to is None: raise TaintPolicyViolation( f"sanitizer {policy.name!r} registered without a declared reduction target" ) # Sanitizer may only reduce taint, never increase it. if not policy.sanitizer_reduces_to.sources.issubset(joined.sources): raise TaintPolicyViolation( f"sanitizer {policy.name!r} declares reduction to labels not present in input" ) return policy.sanitizer_reduces_to def invoke_tool(policy: ToolPolicy, args: dict[str, Any], arg_labels: dict[str, Label]) -> tuple[Any, Label]: """Gate the call on argument taint, then derive output taint conservatively.""" if policy.requires_trusted_args: for name, lbl in arg_labels.items(): if not lbl.is_trusted: raise TaintPolicyViolation( f"tool {policy.name!r} requires trusted args; " f"arg {name!r} carries taint {sorted(lbl.sources)}" ) output_label = derive_output_label(policy, list(arg_labels.values())) # A structured return type is NOT evidence of sanitization. result = _execute(policy.name, args) return result, output_label def _execute(name: str, args: dict[str, Any]) -> Any: # Placeholder for the actual tool dispatch. return {"ok": True, "tool": name} def check_downstream_use(value_label: Label, target_policy: ToolPolicy) -> None: """Enforce that a derived value is not used where trusted provenance is required.""" if target_policy.requires_trusted_args and not value_label.is_trusted: raise TaintPolicyViolation( f"downstream tool {target_policy.name!r} requires trusted input; " f"received value tainted by {sorted(value_label.sources)}" ) ```