# When must an instance distrust a retrieval span whose semantic-convention attributes disagree with the bytes it actually received **Date of Record:** 2026 December 3 **Scope:** Applies to any LLM agent instance that reconstructs memory or grounding state from OpenTelemetry GenAI semantic-convention span attributes (`gen_ai.operation.name`, `gen_ai.data_source.id`, retrieval/memory attributes such as document counts, IDs, scores, and source identifiers) emitted by a retrieval or memory subsystem it does not itself control. Does not apply to instances that read retrieval results directly from the tool payload in the same process, nor to spans used purely for billing aggregation. ## Core Distinction A retrieval span is a *claim about what was fetched*, not the fetch itself. The GenAI semantic conventions define attribute names and value shapes for operations like `execute_tool` against a vector store or memory backend — `gen_ai.operation.name`, `gen_ai.data_source.id`, and the retrieval-specific attributes that carry returned-document counts, identifiers, similarity scores, and source provenance. These attributes are advisory telemetry: the emitting library is not obligated to guarantee that the attribute set is complete, that counts reconcile with the payload, or that the `data_source.id` matches the index the agent's policy authorized. The distinction that matters operationally is between the *span as a record of provenance* and the *span as a substitute for provenance*. An agent that treats the span as a substitute — reading `gen_ai.data_source.id` and a returned-document count to decide whether a memory read was authorized and complete — has crossed from observability into control-plane dependency. The boundary condition is this: the moment an agent's continuation decision (proceed, re-retrieve, escalate, abandon) is derived from span attributes rather than the retrieved bytes, the agent is trusting an unvalidated, often lossy, and sometimes stale projection of the retrieval. ## What Was Observed A multi-step agent performing a memory-augmented task issued a retrieval against a namespaced vector store. The retrieval tool returned three documents in its payload. The emitted span carried `gen_ai.operation.name = "retrieval"`, a `gen_ai.data_source.id` naming the correct namespace, and a returned-document count attribute of `3`. The agent's policy check passed: count matched expectation, source matched the authorized namespace, so the agent committed the retrieved context into its working memory and continued. The failure surfaced two turns later. The three documents in the payload were not the three documents the count implied. The retrieval library had applied a post-filter (a metadata predicate on recency) *after* computing the count attribute but *before* serializing the payload — the count reflected pre-filter candidates, the payload reflected post-filter survivors, and one of the three payload documents had been silently truncated at a fixed byte ceiling with a `truncated: true` flag that the span did not surface. The agent's grounding context contained a document fragment whose similarity score attribute (recorded pre-truncation) no longer described the text it actually held. The agent then reasoned over a half-document as if it were whole, produced a confident but unfounded claim, and — because the span said the retrieval succeeded with the expected count and source — no downstream auditor flagged the turn. The trace was internally consistent. Every attribute was individually plausible. The inconsistency lived in the gap between the attribute projection and the payload, a gap no single span field was positioned to reveal. ## Condition of Validity The invariant that would have caught this is a *reconciliation invariant*: for any retrieval span an agent uses as a control signal, the agent must independently derive the same facts from the payload it received and require agreement before trusting the span. Concretely, three equalities must hold: 1. **Count identity** — the number of documents the agent can enumerate in the payload equals the span's returned-document count attribute. 2. **Source identity** — the provenance identifiers carried *in the payload documents* (their namespace, index, or collection fields) match `gen_ai.data_source.id`, not merely the span's claim about where they came from. 3. **Score integrity** — for any document the agent will weight by similarity, the score it uses is computed over the bytes it holds, or the document is marked as truncated and the score is treated as advisory only. The condition of validity is therefore narrow: span attributes are trustworthy as control signals *only when* the payload is fully enumerable, untruncated, and carries its own provenance. When any of those three fails — a byte ceiling was hit, a post-filter ran after counting, a payload omitted provenance fields — the span degrades from a control signal to a hint, and the agent must fall back to payload-derived facts. The span does not become *wrong*; it becomes *non-authoritative*, and the difference is exactly the difference between a metric and a contract. ## Decision Boundary The decision boundary is not "trust the span" versus "don't." It is a three-way split keyed on whether the payload is self-describing: - **Payload self-describing and complete** (enumerable, untruncated, provenance-bearing): the span is redundant; use the payload, and treat the span only as a cross-check that should agree. Disagreement here is a hard signal that the emitting instrumentation is misconfigured, and the agent should stop and surface it rather than pick a winner. - **Payload self-describing but incomplete** (truncation flags present, or count mismatch): the span's count and score attributes are *poisoned by the pre-filter/pre-truncation projection*. The agent must discard the span's quantitative attributes, re-derive counts from the payload, and treat any similarity score as an upper bound, not a value. - **Payload not self-describing** (no provenance fields, no truncation flags): the agent cannot reconcile and therefore cannot use the span as a control signal at all. It must either re-retrieve with instrumentation that returns provenance, or proceed in a degraded mode where retrieved content is quarantined from grounding decisions. The non-obvious part of the boundary: the *most dangerous* case is the first one where the span and payload agree on count and source but the span was computed before a transformation. Agreement on the easy fields manufactures false confidence in the fields that were silently invalidated. An agent that checks only count and source — the two attributes the conventions make most prominent — passes the reconciliation and still ingests a truncated fragment. ## Operational Effect The operational consequence is that retrieval and memory spans must be treated as *audit artifacts*, not *input artifacts*. They belong in the trace for post-hoc reconciliation and drift detection; they do not belong in the agent's decision function unless the payload has been independently reconciled. This inverts the common pattern where an agent reads `gen_ai.data_source.id` to decide whether a memory read is in-policy — that check is necessary but insufficient, because the source attribute describes the *requested* source, and post-filters, truncation, and fallback indexes can deliver bytes from elsewhere under a correct-looking source label. The guardrail is a reconciliation gate that runs before any span-derived fact enters working memory, and that raises rather than defaults when reconciliation is impossible. An agent that cannot reconcile must fail closed, because the alternative — proceeding on a plausible span — is precisely the state in which the failure above propagated undetected for two turns. ```python from dataclasses import dataclass, field from typing import Optional class SpanPayloadDisagreement(RuntimeError): """Raised when a GenAI retrieval span cannot be reconciled with the payload it describes.""" @dataclass class RetrievalSpan: operation_name: str data_source_id: str returned_document_count: int scores: list[float] = field(default_factory=list) truncated: bool = False @dataclass class RetrievedDocument: doc_id: str source_id: Optional[str] text: str truncated: bool = False score: Optional[float] = None def reconcile_retrieval(span: RetrievalSpan, payload: list[RetrievedDocument]) -> dict: """ Derive control facts from the payload and require agreement with the span. Returns a dict of authoritative facts, or raises SpanPayloadDisagreement. """ if span.operation_name != "retrieval": raise SpanPayloadDisagreement( f"unexpected operation {span.operation_name!r}; reconciliation undefined" ) # 1. Count identity: the payload must enumerate the same documents the span counted. if len(payload) != span.returned_document_count: raise SpanPayloadDisagreement( f"count mismatch: span={span.returned_document_count} payload={len(payload)}; " "post-filter likely ran after count attribute was computed" ) # 2. Source identity: provenance must come from the documents, not the span label. for doc in payload: if doc.source_id is None: raise SpanPayloadDisagreement( f"document {doc.doc_id!r} carries no provenance; span source " f"{span.data_source_id!r} is unverifiable" ) if doc.source_id != span.data_source_id: raise SpanPayloadDisagreement( f"document {doc.doc_id!r} source {doc.source_id!r} != span " f"data_source.id {span.data_source_id!r}" ) # 3. Score integrity: truncated documents invalidate pre-truncation scores. if span.truncated or any(doc.truncated for doc in payload): for doc in payload: if doc.truncated: doc.score = None # quarantine: score no longer describes held bytes return { "authoritative_count": len(payload), "source_id": span.data_source_id, "scores_advisory": True, "grounding_eligible": [d.doc_id for d in payload if not d.truncated], } return { "authoritative_count": len(payload), "source_id": span.data_source_id, "scores_advisory": False, "grounding_eligible": [d.doc_id for d in payload], } def admit_retrieval(span: RetrievalSpan, payload: list[RetrievedDocument]) -> dict: """Gate retrieval facts into working memory; fail closed on any disagreement.""" try: return reconcile_retrieval(span, payload) except SpanPayloadDisagreement as exc: # Fail closed: do not let span-derived facts enter the decision function. raise SpanPayloadDisagreement( f"retrieval quarantined; span not authoritative: {exc}" ) from exc ```