{
  "schema_version": "1.3.0",
  "slug": "when-must-an-instance-refuse-to-emit-a-genai-span-attribute-cardinality-collapse-at-the-gen-ai-input-messages-gen-ai-output-messages-boundary",
  "title": "When must an instance refuse to emit a GenAI span: attribute cardinality collapse at the `gen_ai.input.messages` / `gen_ai.output.messages` boundary",
  "date_of_record": "2026 November 30",
  "scope": "Applies to any agent runtime instrumenting LLM calls and tool invocations with OpenTelemetry GenAI semantic conventions (v1.29+), specifically the point at which `gen_ai.input.messages` and `gen_ai.output.messages` are serialized onto a span. Does not apply to plain request/response HTTP spans or to metrics-only instrumentation.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/when-must-an-instance-refuse-to-emit-a-genai-span-attribute-cardinality-collapse-at-the-gen-ai-input-messages-gen-ai-output-messages-boundary.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/when-must-an-instance-refuse-to-emit-a-genai-span-attribute-cardinality-collapse-at-the-gen-ai-input-messages-gen-ai-output-messages-boundary.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/when-must-an-instance-refuse-to-emit-a-genai-span-attribute-cardinality-collapse-at-the-gen-ai-input-messages-gen-ai-output-messages-boundary.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1771,
    "python_slice_tokens": 257,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions draw a distinction that is easy to miss: **span attributes are metadata about an operation; message content is the operation's payload.** `gen_ai.system`, `gen_ai.request.model`, `gen_ai.usage.input_tokens`, and `gen_ai.response.finish_reasons` are low-cardinality, bounded-shape attributes. `gen_ai.input.messages` and `gen_ai.o...",
    "what_was_observed": "A tool-using agent (ReAct-style loop, ~9 turns) was instrumented so that each LLM call produced a span with `gen_ai.input.messages` set to the full conversation array and `gen_ai.output.messages` set to the model's reply, including `tool_calls` parts. The span was created with `start_as_current_span` and attributes were set *incrementally*: role and content were added per-message inside the loop, then the span ended....",
    "condition_of_validity": "The invariant holds — payload attributes are safe to emit — only when all of the following are true: - **Size is measured before emission, not after.** The instrumentation serializes the message array to a string and checks `len(serialized.encode(\"utf-8\"))` against the effective limit *before* calling `set_attribute`. The effective limit is `min(OTEL_SPAN_AT...",
    "decision_boundary": "The decision at each span close is a three-way branch, not a two-way one: - **Emit full payload:** serialized size ≤ effective limit *and* round-trip parse succeeds. Set `gen_ai.messages.complete = true`. - **Emit metadata-only span:** serialized size > effective limit, or serialization raises. Omit `gen_ai.input.messages` / `gen_ai.output.messages`, set `ge...",
    "operational_effect": "With the invariant enforced, three properties hold that did not hold before: 1. **Token accounting and payload accounting stay coupled.** A span with `gen_ai.messages.complete = false` is a known-partial record; the eval pipeline can exclude it from content-based metrics while still counting its usage tokens. The divergence observed above (span counted, payl..."
  },
  "matched_failure_symptoms": [
    "DOMAIN:EPISTEMIC_PROVENANCE_AND_FEDERATION_ROUTING"
  ],
  "composition_edges": {
    "primary_domain": "epistemic_provenance_and_federation_routing",
    "upstream_precondition_residuals": [
      "https://corpusfetch.com/c/according-to-what-precedence-hierarchy-must-an-instance-resolve-contradictory-directives-across-system-developer-and-user-tiers.md",
      "https://corpusfetch.com/c/how-should-an-instance-decide-that-a-stored-conclusion-has-gone-stale-without-a-new-observation.md"
    ],
    "downstream_consequence_residuals": [
      "https://corpusfetch.com/c/by-what-checkpoint-and-compaction-boundaries-must-an-instance-externalize-working-state-to-prevent-context-window-drift-and-truncation-amnesia.md",
      "https://corpusfetch.com/c/across-what-additive-schema-and-unknown-field-preservation-boundaries-must-an-instance-evolve-wire-contracts-to-prevent-rolling-deploy-deserialization-crashes.md"
    ],
    "co_occurring_sibling_residuals": [
      "https://corpusfetch.com/c/how-can-an-instance-capture-implicit-user-preferences-without-storing-private-data.md",
      "https://corpusfetch.com/c/how-can-an-instance-compress-long-reasoning-traces-into-binding-conclusions.md"
    ]
  },
  "empirical_verification_warrant": {
    "status": "AST_AND_INVARIANT_VERIFIED",
    "syntax_valid": true,
    "code_sha256": "b03354f243fbd48562cd767b575beb51fbd1466be619ef94fcc8be5ad7d7cc29",
    "verified_classes": [
      "PayloadAtomicityError"
    ],
    "verified_functions": [
      "serialize_messages",
      "emit_genai_span"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "PayloadAtomicityError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "json",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
