# Why does an instance of a tainted tool output silently lose its taint when it crosses a serialization boundary in agentic pipelines? **Date of Record:** 2026 November 17 **Scope:** Applies to agentic pipelines where tool outputs are labeled with provenance/taint metadata (e.g., "untrusted", "external", "user-supplied") and that taint is expected to propagate through transformations, message queues, and model context assembly. Does not apply to pipelines where taint is enforced by a single in-process reference monitor that never serializes intermediate values, nor to pipelines where tool outputs are always treated as uniformly untrusted by construction. ## Core Distinction Taint propagation has two distinct failure surfaces: **value-level propagation** (does the tainted *data* reach a sink?) and **label-level propagation** (does the taint *annotation* survive the transport that carries the data?). Most runtime taint systems are designed and tested against the first surface — they instrument string concatenation, template rendering, and argument passing — and treat labels as an in-memory property attached to an object. The second surface is where the invariant silently breaks: when a tainted value is serialized to JSON, a message bus, a checkpoint, or a model context window and deserialized elsewhere, the label is dropped because the serialization schema carries only the payload, not the provenance envelope. The result is a value that is *data-identical* to its tainted origin but *label-distinct* — it arrives at the sink as clean. The non-obvious part is that this is not a bug in any single component. The serializer is correct (it round-trips the value). The taint engine is correct (it propagates labels it can see). The failure is a *boundary*: the invariant "taint is preserved across transport" is assumed but never asserted, because the transport layer is outside the taint engine's instrumentation scope. ## What Was Observed In a pipeline that fetched a document via an HTTP tool, the tool wrapper attached `taint="external"` to the returned `ToolResult`. The orchestrator passed the result to a summarizer step that serialized it to JSON over an internal queue. On the consumer side, the deserialized object was a plain dict; the `taint` field was absent from the schema, so the summarizer emitted a summary labeled `trusted`. That summary was then used to construct a shell command. The taint engine, instrumented on string operations within a single process, saw only clean inputs at the command-construction sink and permitted it. The tell was a provenance audit: the command's argument traced back to an HTTP fetch, yet no taint event was recorded on the path. The label had been dropped at the queue boundary, not at any instrumented operation. Re-running with the queue replaced by an in-process call restored propagation — confirming the boundary, not the logic, was the locus. ## Condition of Validity The invariant "a tainted value remains tainted at every downstream sink" holds **only if** every transport between producer and sink carries the label envelope, **or** if the sink re-derives taint from an out-of-band provenance record. It is violated whenever: 1. The serialization schema omits the label field (the common case — schemas are written for payload consumers, not for the taint engine). 2. The deserializer constructs a fresh object whose default label is `trusted`/`clean`. 3. A transformation (summarization, translation, embedding) produces a derived value whose label is computed from *inputs the engine can see* — and the engine cannot see the label of a value that arrived without one. The invariant is therefore **conditional on envelope completeness**, not on engine correctness. An engine that is 100% correct within a process is 0% correct across an unlabeled boundary. ## Decision Boundary Treat any value that crosses a serialization, queue, checkpoint, or model-context boundary as **taint-unknown**, not taint-clean. The decision rule: - If the transport carries an explicit label envelope → propagate the label as-is. - If the transport omits the label → **fail closed**: re-taint to the most restrictive level consistent with the producer, or reject at the sink. Never default to clean. - If a derived value (summary, embedding, rewrite) is produced from a taint-unknown input → the derived value inherits taint-unknown, regardless of what the transformation's local inputs appear to be. The boundary is sharp: a value is either accompanied by a verifiable provenance envelope or it is untrusted. There is no "probably clean" state that a sink may act on. ## Operational Effect Pipelines that adopt envelope-carrying transports (labels in the schema, signed provenance records, or a side-channel provenance store keyed by value hash) restore the invariant at the cost of schema churn and a small serialization overhead. Pipelines that do not must accept that taint is a *per-process* property and that every boundary is a potential laundering point. The practical mitigation is a sink-side assertion: every privileged operation re-checks provenance against the out-of-band record and refuses inputs whose envelope is missing, rather than trusting the in-memory label that survived only by luck of co-location. ```python class TaintEnvelopeMissingError(RuntimeError): """Raised when a value crosses a boundary without a provenance envelope.""" pass TRUST_LEVELS = ("trusted", "external", "unknown") def propagate_across_boundary(value, envelope, producer_taint): """ Enforce the envelope-completeness invariant at a serialization boundary. A value may only be treated as clean if its envelope explicitly carries a trust level. Absence of an envelope is taint-unknown, never clean. """ if envelope is None or "trust" not in envelope: # Fail closed: do not silently default to trusted. raise TaintEnvelopeMissingError( f"value from producer={producer_taint!r} crossed boundary " f"without a trust envelope; refusing to label it clean" ) trust = envelope["trust"] if trust not in TRUST_LEVELS: raise TaintEnvelopeMissingError( f"unrecognized trust level {trust!r} in envelope" ) # Derived values inherit the most restrictive of producer and envelope. rank = {lvl: i for i, lvl in enumerate(TRUST_LEVELS)} effective = max(trust, producer_taint, key=lambda l: rank[l]) return {"value": value, "trust": effective} def build_command(summary, summary_envelope, summary_producer_taint): """Sink-side check: privileged construction requires a verified envelope.""" labeled = propagate_across_boundary( summary, summary_envelope, summary_producer_taint ) if labeled["trust"] != "trusted": raise TaintEnvelopeMissingError( f"refusing to build command from taint={labeled['trust']!r} input" ) return ["sh", "-c", labeled["value"]] ```