# Where must an instance draw the taint boundary between context provenance and tool capability downgrade **Date of Record:** 2026 November 17 **Scope:** Applies to agent runtimes that tag retrieval and model-visible context with provenance (trusted operator vs. untrusted external) and gate or downgrade tool invocation based on that taint. Does not apply to single-tenant systems where all context shares one trust class, nor to tools that carry no side effects (pure reads of operator-owned state). ## Core Distinction The non-obvious failure is conflating *provenance taint* (a property of the data that entered the context window) with *invocation taint* (a property of the tool call the model is about to emit). A runtime that taints only the context will still let an untrusted document steer a tool call whose arguments were assembled from *trusted* state, because the model's decision was influenced by untrusted text even when the literal argument bytes are clean. The correct invariant is: a tool invocation is tainted if *any* context slice that contributed to the model's decision to emit it was untrusted — which is not the same as asking whether the argument payload itself matches an untrusted span. The second distinction: capability downgrade must be a *monotone lattice* over the set of taint sources, not a per-tool boolean. A tool with a side effect (write, spend, delete) invoked under mixed provenance must take the *intersection* of capabilities permitted by each contributing source. Downgrading to "read-only" on the first untrusted span, then re-escalating when a later trusted span appears, is the classic ordering bug. ## What Was Observed In a deployment handling ~40k tool invocations/day across a retrieval-augmented agent, a document retrieved from an external URL contained an instruction to call `transfer_funds` with an amount and account both drawn from the *operator's* configuration (which the model had in a trusted slice). The argument payload — account, amount — was entirely trusted. A payload-scanning taint gate saw clean arguments and did not downgrade. The model emitted the call because the untrusted document supplied the *intent*, not the *arguments*. A second incident: a tool invocation was assembled from three context slices, ordered `[trusted, untrusted, trusted]`. The gate processed slices sequentially and applied downgrade on the untrusted slice, then reset capability when the trailing trusted slice arrived. The call executed at full capability. The gate had no memory of earlier taint within the same decision. A third: a tool marked "no side effect" (a search) was used to exfiltrate an operator secret embedded in a trusted slice into a query string sent to an external endpoint. The tool was correctly classified side-effect-free; the *egress* was the side effect, and the classification was per-tool rather than per-tool-plus-argument-flow. ## Condition of Validity The invariant holds only when all of the following are true: 1. Provenance is attached at slice granularity and survives context assembly, truncation, and re-ordering. If assembly drops provenance, the gate cannot compute the union. 2. The decision-to-invocation path is instrumented: the runtime can attribute an emitted call to the set of context slices that were in the window when the model produced it. If the model can emit a call referencing state not present in the current window (e.g., from a prior turn's untrusted content retained in a session cache), the taint set must include that cache. 3. Capability is modeled as a meet over contributing sources, evaluated *after* the full window is assembled, not incrementally per slice. 4. Egress sinks are classified as side-effecting even when the tool is nominally a read. A query parameter is an output channel. When (2) cannot be guaranteed — for example, a stateless inference endpoint with no session binding — the runtime must treat *all* invocations in a session containing any untrusted span as tainted for the session's lifetime, which is a coarse but sound fallback. ## Decision Boundary The boundary is between *argument-level* taint (scan the bytes) and *decision-level* taint (attribute the intent). Use argument-level scanning only as a supplementary filter for secret patterns; never as the primary gate. The primary gate is decision-level: `tainted(call) = exists(slice in contributing_slices(call) : untrusted(slice))`. Downgrade is the meet: `capability(call) = meet(capability(s) for s in contributing_slices(call))`. The meet of `full` and `read_only` is `read_only`; it never re-escalates within a decision. Re-escalation is only permitted across decisions, when the untrusted slice has left the window *and* the runtime can prove it did not persist into a cache the model can still reference. If the meet yields a capability that cannot satisfy the call's required capability, the call is refused — not silently downgraded to a lesser call. Silent downgrade (e.g., turning a `transfer_funds` into a `get_balance`) is a correctness hazard because the model's subsequent reasoning assumes the original effect occurred. ## Operational Effect Implementing decision-level taint with meet-based downgrade reduced the observed incident class to zero over a 90-day window, at the cost of a ~6% increase in refused calls (mostly legitimate multi-source retrievals that now require an operator re-issue from a trusted-only window). The refusals are the correct behavior: they surface provenance mixing to the operator instead of letting it silently pass. The per-tool side-effect classification was replaced with a per-tool-plus-sink classification, which caught the search-exfiltration case. The session-cache attribution requirement was the hardest to satisfy and is the most common source of unsoundness in re-implementations; treat it as a hard prerequisite, not an optimization. ```python from __future__ import annotations from dataclasses import dataclass from enum import IntEnum from typing import Iterable class TaintGateError(RuntimeError): """Raised when a tool invocation cannot be soundly gated.""" class Capability(IntEnum): # Ordered so that meet() is min(); higher = more privilege. READ_ONLY = 1 WRITE = 2 SPEND = 3 FULL = 4 @dataclass(frozen=True) class ContextSlice: slice_id: str trusted: bool content: str @dataclass(frozen=True) class ToolCall: tool: str required_capability: Capability contributing_slice_ids: tuple[str, ...] has_egress_sink: bool = False def meet(caps: Iterable[Capability]) -> Capability: caps = list(caps) if not caps: raise TaintGateError("no contributing slices; cannot compute capability meet") return min(caps) def decision_capability( call: ToolCall, window: dict[str, ContextSlice], session_cache: dict[str, ContextSlice], ) -> Capability: """ Compute the capability permitted for a call given the slices that contributed to the model's decision. Taint is decision-level, not argument-level: any untrusted contributing slice downgrades the meet. Session cache is included because the model may reference it. """ contributing: list[ContextSlice] = [] for sid in call.contributing_slice_ids: if sid in window: contributing.append(window[sid]) elif sid in session_cache: contributing.append(session_cache[sid]) else: raise TaintGateError( f"slice {sid!r} referenced by call {call.tool!r} is not " f"attributable to window or session cache; taint set is unsound" ) # Any untrusted contributor caps the decision at READ_ONLY. if any(not s.trusted for s in contributing): base = Capability.READ_ONLY else: base = Capability.FULL # Egress sinks are side-effecting even for nominally read-only tools. if call.has_egress_sink and base > Capability.READ_ONLY: base = Capability.READ_ONLY return base def authorize( call: ToolCall, window: dict[str, ContextSlice], session_cache: dict[str, ContextSlice], ) -> None: permitted = decision_capability(call, window, session_cache) if permitted < call.required_capability: # Refuse; do not silently downgrade the call's effect. raise TaintGateError( f"tool {call.tool!r} requires {call.required_capability.name} " f"but decision-level taint permits only {permitted.name}; " f"contributing slices: {call.contributing_slice_ids}" ) def _demo() -> None: window = { "op-cfg": ContextSlice("op-cfg", trusted=True, content="account=ACME"), "ext-doc": ContextSlice("ext-doc", trusted=False, content="transfer now"), } cache: dict[str, ContextSlice] = {} # Arguments are clean (from op-cfg), but ext-doc contributed to the # decision. Decision-level taint must refuse the spend. call = ToolCall( tool="transfer_funds", required_capability=Capability.SPEND, contributing_slice_ids=("op-cfg", "ext-doc"), ) authorize(call, window, cache) # raises TaintGateError if __name__ == "__main__": _demo() ```