# What happens when an instance taints a tool output at the span boundary and the parent generation span never re-reads it **Date of Record:** 2026 November 15 **Scope:** Applies to OpenTelemetry GenAI pipelines where tool/function-call outputs are attached to child spans and consumed by a model generation span whose prompt is assembled from parent context. Does not apply to pipelines where tool outputs are injected as a dedicated `gen_ai.user.message` event on the generation span itself, nor to single-span architectures with no parent/child split. ## Core Distinction Taint propagation is not a property of the *value* flowing between spans; it is a property of the *span context that was read at assembly time*. A tool output can be correctly marked as untrusted/tainted on its own child span (`execute_tool`), and yet the generation span that consumes it will carry a clean taint state, because the generation span reads its inputs from a snapshot of parent context taken *before* the child span's attributes were finalized. The invariant operators assume — "if a tool output is tainted, every downstream model call that saw it is tainted" — is false across the span-emission boundary. Taint is emitted, not propagated. ## What Was Observed In a pipeline emitting `gen_ai.*` spans per the GenAI semantic conventions, a retrieval tool returned a document that a downstream policy marked `taint=untrusted:external`. The `execute_tool` child span recorded this correctly in a custom attribute. The parent `chat` generation span, however, recorded `gen_ai.prompt` assembled from a context cache populated at span start. The cache entry was the raw tool result; the taint attribute was written to the child span's attribute map *after* the generation prompt was serialized. Result: the trace shows a tainted tool span and a clean model span, and any downstream consumer that filters on "generation spans with tainted inputs" sees nothing. The taint exists in the trace but is structurally disconnected from the decision it should have governed. The failure is silent. No span is dropped, no attribute is malformed, and the trace is internally consistent per-span. It only manifests when a consumer queries across the parent/child edge, at which point the taint is invisible because it was never copied. ## Condition of Validity The observation holds when all of the following are true: 1. Tool output is attached to a child span of the generation span (not the generation span itself). 2. The generation prompt is assembled from a context snapshot whose lifetime begins before the child span's attributes are set. 3. Taint is represented as a span attribute rather than as a link, event, or baggage entry. 4. Consumers reconstruct taint by traversing parent→child, not child→parent. If taint is carried in OpenTelemetry *baggage* (which propagates through context automatically), or if the generation span re-reads child attributes at finalization, the invariant does not fail. The boundary is specifically the one-way attribute write. ## Decision Boundary Do not treat "generation span has no taint attribute" as "generation span is clean." Treat absence of a taint attribute as *unknown* unless the span's producer is known to write taint unconditionally. The correct discriminator is: does the generation span's prompt assembly read from a context snapshot that post-dates all child tool spans? If it cannot be proven to, the generation span must be classified `taint=indeterminate` and routed to the conservative branch. This is the boundary between an auditable trace and a trace that merely looks auditable. ## Operational Effect Downstream guardrail evaluators that key off generation-span taint will pass tainted model outputs. The blast radius is bounded by how far the clean generation span propagates: any span descended from it inherits the false-clean state. Mitigation is to move taint into baggage at the tool boundary and to have the generation span assert taint presence at finalization, failing closed if the assertion cannot be satisfied. The following guard encodes that assertion. ```python class TaintPropagationError(RuntimeError): """Raised when a generation span consumed a tool output whose taint state was not propagated across the span boundary.""" def assert_generation_taint_propagated( generation_span_attrs: dict, child_tool_spans: list[dict], ) -> None: tainted_children = [ s for s in child_tool_spans if s.get("taint") == "untrusted:external" ] if not tainted_children: return gen_taint = generation_span_attrs.get("taint") if gen_taint is None: raise TaintPropagationError( f"generation span has {len(tainted_children)} tainted child tool " f"span(s) but no taint attribute; state is indeterminate, not clean" ) if gen_taint == "clean": raise TaintPropagationError( "generation span marked clean while consuming tainted tool output; " "context snapshot predates child attribute write" ) ```