# Under what conditions must an instance refuse to emit a `gen_ai.prompt` lineage span when attribute schema version and prompt-capture policy disagree at emit time **Date of Record:** 2026 November 26 **Scope:** Applies to any agent runtime that emits OpenTelemetry-style GenAI semantic convention spans carrying prompt/response lineage attributes (`gen_ai.prompt.*`, `gen_ai.completion.*`, `gen_ai.request.model`, `gen_ai.usage.*`) from within a tool-calling or multi-step reasoning loop. Does not apply to pure metric-only telemetry, nor to spans emitted by a sidecar proxy that never observes the raw prompt bytes. ## Core Distinction A GenAI semantic convention attribute schema is a *contract about cardinality and redaction*, not merely a naming convention. The distinction that governs this failure mode is between two independent version axes that most runtimes collapse into one: - **Schema version** — the set of attribute keys and their required/optional status (e.g. `gen_ai.prompt.0.role` vs. the newer `gen_ai.input.messages` array form). - **Capture policy** — the runtime's decision of *whether* raw prompt/response content is permitted to leave the process boundary at all (PII redaction, tenant data residency, opt-in content logging). These two axes advance on different clocks and are owned by different teams. The failure is not "schema drift" in the generic sense. The failure is that a span can be *schema-valid* and *policy-violating* simultaneously, or *policy-compliant* and *lineage-broken* simultaneously, and the emitter has no single boolean that tells it which. The invariant required is: **the emitter must treat the pair (schema_version, capture_policy) as a joint precondition and refuse emission when the pair is not jointly satisfiable** — rather than degrading one axis silently to satisfy the other. ## What Was Observed An agent runtime upgraded its OTel GenAI conventions from the flat `gen_ai.prompt.{i}.{field}` form to the structured `gen_ai.input.messages` array form. The capture-policy layer, meanwhile, was still operating on a per-key allowlist keyed to the *old* flat names (`gen_ai.prompt.*`). The allowlist was a prefix match. The new attribute key `gen_ai.input.messages` did not match the prefix. The observable trace, across a single multi-step reasoning loop: 1. Step 1 emits a span with `gen_ai.input.messages` present in the attribute map. The policy filter sees no matching allowlist entry and — because the filter's default was "drop unknown keys, do not fail" — **strips the attribute**. The span is emitted, `gen_ai.operation.name=chat`, with zero prompt lineage. 2. Step 2's tool call is correlated to Step 1 by `trace_id`/`span_id` only. The lineage reconstructor downstream attempts to reconstruct "what prompt produced this tool call" and finds an empty attribute set. It does not error — it records a lineage gap of `unknown`. 3. Step 3's completion is attributed to a *reconstructed* prompt assembled from the conversation store, which by now has diverged from what the model actually saw (a system-prompt injection was applied at Step 2 in-memory but never persisted). The reconstructed lineage is plausible, schema-valid, and **wrong**. The non-obvious part: the schema upgrade was validated in CI against a fixture that asserted *attribute presence in the emitted span before the policy filter ran*. The policy filter sat downstream of the assertion point. Every test passed. In production, 100% of prompt attributes were dropped and 100% of lineage reconstructions were fabricated from a divergent store. The system reported full lineage coverage because the reconstructor never distinguished "attribute absent" from "attribute present but empty." The trigger condition, stated precisely: a schema migration that renames or restructures attribute keys, combined with a capture policy that matches on key names and defaults to silent drop rather than fail-closed, combined with a downstream consumer that treats absence as "reconstruct from fallback" rather than "lineage unknown." Any two of the three are survivable. All three produce fabricated lineage. ## Condition of Validity The refusal-to-emit guardrail is valid only under the following joint condition. Let `S` be the schema version the emitter is configured to produce, `P` the capture policy in force at emit time, and `K(S)` the set of lineage-bearing keys required by `S`. The emitter may emit a lineage span only if: - `P` has an explicit disposition (capture / redact / drop-with-marker) for **every** key in `K(S)` — not a prefix match, not a default; an explicit per-key disposition. A default disposition is not a disposition for this purpose. - If `P` requires dropping or redacting any key in `K(S)`, the span is emitted with an explicit `gen_ai.lineage.status = redacted` (or `dropped`) marker attribute **and** the dropped keys are enumerated in a `gen_ai.lineage.redacted_keys` attribute. The marker is itself in `K(S)` and must be policy-permitted unconditionally. - The downstream reconstructor treats `gen_ai.lineage.status` as authoritative: `redacted`/`dropped` means *do not reconstruct*, not *reconstruct from fallback*. If any key in `K(S)` has no explicit disposition in `P`, the emitter must **refuse to emit the span** and raise, rather than emit a schema-valid span with silently missing lineage. The refusal is the correct behavior because a missing span is recoverable (the trace shows a gap the operator can see) whereas a fabricated lineage is not (it looks complete and is false). This condition does *not* hold, and the guardrail does not apply, when the runtime emits no prompt content by design (content-free telemetry: only `gen_ai.request.model`, token counts, latency). In that mode `K(S)` for lineage is empty and the joint precondition is trivially satisfied. ## Decision Boundary The boundary between "degrade gracefully" and "refuse to emit" is drawn at whether the degraded span remains *honest about its own degradation*. Concretely: | Situation | Emit? | Why | |---|---|---| | All `K(S)` keys have explicit capture disposition | Yes, full lineage | Joint precondition satisfied | | Some `K(S)` keys explicitly redacted, marker emitted | Yes, marked lineage | Honest degradation; reconstructor sees marker | | Some `K(S)` keys have no disposition (prefix miss, new key) | **No — raise** | Silent drop produces fabricated lineage downstream | | Schema version unknown to policy layer entirely | **No — raise** | Policy cannot have dispositions for keys it does not know | | Content-free mode, `K(S)` lineage empty | Yes, no lineage | Precondition vacuous | The decision the emitter must *not* make on its own is "the policy probably intends to allow this new key." That inference is exactly the one that produced the incident: the new `gen_ai.input.messages` key was structurally the successor of the allowlisted `gen_ai.prompt.*` prefix, so a human reviewer would have said "obviously allowed." The emitter is not permitted to make that inference, because the policy layer's job is to make it explicitly, and the emitter cannot distinguish "policy forgot to update" from "policy deliberately excluded this key for a tenant under data residency." ## Operational Effect The operational consequence of enforcing this boundary is a **fail-closed lineage pipeline**: schema upgrades that outpace policy updates produce visible span-emission failures at deploy time (the agent's first traced call raises) rather than silent lineage corruption discovered weeks later during an audit. The cost is that schema and policy must be deployed in lockstep, or the policy layer must ship a "unknown key → raise" mode that the schema migration is tested against. Two secondary effects worth recording: First, the marker attribute (`gen_ai.lineage.status`) must be in the schema's *required* set, not optional. If it is optional, a future schema version can omit it and the reconstructor's "authoritative marker" check silently reverts to "reconstruct from fallback." The invariant is only as strong as the marker's requiredness. Second, the refusal must be observable as a *span emission failure*, not as a swallowed exception inside a batch exporter. If the OTel exporter batches and the raise happens inside the batch flush, the failure surfaces as a dropped batch with no per-span attribution — indistinguishable from a network drop. The raise must occur at attribute-construction time, before the span enters the batch, so the failing span's identity is known. ```python from dataclasses import dataclass, field from typing import Mapping class LineageEmissionRefused(RuntimeError): """Raised when (schema_version, capture_policy) is not jointly satisfiable.""" pass @dataclass(frozen=True) class SchemaVersion: name: str lineage_keys: frozenset[str] # K(S): keys that carry prompt/response lineage marker_key: str = "gen_ai.lineage.status" redacted_keys_key: str = "gen_ai.lineage.redacted_keys" @dataclass(frozen=True) class CapturePolicy: # Explicit per-key disposition. NO prefix matching, NO defaults. dispositions: Mapping[str, str] # key -> "capture" | "redact" | "drop" def disposition_for(self, key: str) -> str | None: return self.dispositions.get(key) def build_lineage_attributes( schema: SchemaVersion, policy: CapturePolicy, raw_prompt_attrs: Mapping[str, object], ) -> dict[str, object]: """ Construct the attribute map for a GenAI lineage span, or refuse. Refuses (raises) when any lineage key required by the schema has no explicit disposition in the capture policy. Emitting a schema-valid span with silently-missing lineage is the failure mode this guard exists to prevent: downstream reconstructors fabricate lineage from a fallback store that has diverged from what the model actually saw. """ out: dict[str, object] = {} redacted: list[str] = [] for key in schema.lineage_keys: disp = policy.disposition_for(key) if disp is None: # No explicit disposition: the policy layer does not know this key. # This is the exact condition that produced fabricated lineage in # production after the gen_ai.prompt.* -> gen_ai.input.messages # migration: the prefix allowlist missed the new key and the # default was silent drop. Refuse instead. raise LineageEmissionRefused( f"schema {schema.name!r} requires lineage key {key!r} but " f"capture policy has no explicit disposition for it; " f"refusing to emit a span that would silently lose lineage" ) if disp == "capture": if key in raw_prompt_attrs: out[key] = raw_prompt_attrs[key] # key absent from raw attrs is a producer bug, not a policy issue; # let it be absent (the marker below still records status). elif disp == "redact": out[key] = "" redacted.append(key) elif disp == "drop": redacted.append(key) else: raise LineageEmissionRefused( f"unknown disposition {disp!r} for key {key!r}" ) # Marker is mandatory and must be policy-permitted; it is in K(S). marker_disp = policy.disposition_for(schema.marker_key) if marker_disp != "capture": raise LineageEmissionRefused( f"marker key {schema.marker_key!r} must be capture-permitted; " f"got {marker_disp!r}. Without it, downstream reconstructors " f"cannot distinguish redacted lineage from absent lineage." ) out[schema.marker_key] = "redacted" if redacted else "captured" if redacted: out[schema.redacted_keys_key] = ",".join(sorted(redacted)) return out ```