A hands-on guide to tracing AI agents with OpenTelemetry, span design, and SDK-level instrumentation for production systems.

Span-Level Correctness Signals That Surface Wrong Answers in Clean Traces

Attaching semantic scores to spans exposes wrong answers that clean traces hide.

· 8 min read
Cover illustration for “Span-Level Correctness Signals That Surface Wrong Answers in Clean Traces”
Agent Tracing · November 16, 2026 · 8 min read · 1,731 words

To detect silent failures in AI agents in production, semantic judgments must be attached to the spans that produce answers, retrieve context, and call tools. A clean trace shows that execution completed. Span-level correctness signals show where the agent went wrong, while trajectory evaluation catches failures that arise across steps that are valid on their own.

Why a clean trace cannot tell you if the agent was right

An agent issues a refund against invoice #4417 instead of #4471 after hallucinating a transposed ID inside a single tool call. Nothing crashes or times out, and every line in the log reads success. The trace is structurally flawless, but the refund is wrong. The team learns of the mistake two days later through an angry email. The failure was present at execution time, but none of the recorded health signals distinguished it from success.

An HTTP 200 on a tool span records successful completion of the network call, leaving open the question of whether the call fetched the right invoice, routing record, or policy document. Flat latency and zero exceptions cannot answer that second question either. In a multi-step agent, a wrong argument at one step can corrupt the next step’s input and then the final answer. Each operation can complete successfully while the error propagates through the entire task.

How failure hides inside a structurally valid trace

A supply-chain routing agent produced incorrect decisions for days in March 2026 without triggering alerts. A downstream API had renamed incident_count to num_incidents, leaving the tool schema stale. The agent read empty results as “no incidents” and routed accordingly. Every span was structurally clean the whole time.

Standard tracing inherits its data model from distributed systems monitoring. A span records timing, status, and attributes for one unit of work, while a trace assembles those spans into an execution graph. That model answers whether a call completed, how long it took, and whether an exception fired. It does not, by itself, judge the meaning of the returned data. In the routing case, successful execution concealed a broken agreement between the API response and the agent’s interpretation.

A structurally valid call to the wrong tool can return without an error code. The right tool can also accept an argument that is wrong for the task and pass bad data downstream. Retrieval adds a subtler case because the tool selection can be correct while the supplied context is wrong or stale. The agent may then reason soundly from what it was given, even though that input makes its answer hard to trust.

What span-level correctness signals are and how they differ from trace health metrics

A span is the recorded unit of work being judged, such as a tool invocation, retrieval step, or model call. A health metric describes its execution, including timing and status. A correctness signal instead judges semantic quality, including correctness, groundedness, or policy adherence. It attaches that judgment directly to the span responsible for the output. The distinction is between completing an operation and completing the right operation with an acceptable result.

The criterion depends on the work that span performed. Tool-call correctness asks whether the agent chose the right tool, gave it the right arguments, and got a response with the expected shape. Context relevancy asks whether the retrieved material helps answer the query or gives the agent context that is irrelevant or stale. Faithfulness asks whether a model’s output follows from its input, while policy adherence tests whether it stays within operating constraints. These are separate judgments.

That separation makes the trace useful for diagnosis. A final-answer score can establish that the agent was wrong without locating the faulty step. Scores on individual spans can instead connect a poor retrieval result to a poor downstream model output. They can also distinguish an upstream context failure from a model that ignored adequate context.

OpenTelemetry GenAI semantic conventions provide a portable substrate for this evidence. They define span names such as invoke_agent, chat, and execute_tool, together with the gen_ai.* attribute namespace. Correctness scores written as custom span attributes can flow to an OTel-compatible backend without re-instrumentation.

Trajectory evaluation versus single-step scoring: when each applies

The engineering decision is whether the error belongs to one operation or to the relationship between operations. Single-step scoring works for a wrong tool argument, a retrieved chunk that is irrelevant, or a model call that ignores its system prompt. Each failure can be judged within the responsible span. Its diagnosis is local, so the resulting fix can be targeted. This is the white-box end of the evaluation spectrum.

Trajectory evaluation catches failures that show up only when steps are viewed together. A tool call can be individually correct yet advance the wrong plan. A long reasoning chain can drift away from the goal, and a sub-agent handoff can lose context required later. Glass-box evaluation judges the path.

Single-step scoring on tool and retrieval spans provides a practical starting point because retrieval failures are a common upstream cause of multi-layer agent failures. Trajectory evaluation comes next when agents take more than three steps or use sub-agent handoffs. For multi-agent systems, tool accuracy measures the percentage of calls that have correct parameters and valid responses. Agent handoff success rate measures the percentage of handoffs that preserve required context. Both use span-level attributes, so they do not depend on a review of the final output.

Sampling addresses the cost of evaluating production trajectories. Scoring a share of traces on an ongoing basis can reveal failures that keep happening without checking every run. Grouping those failures by category then makes the sample useful for action.

Attaching correctness signals in practice: instrumentation across LangGraph, OpenAI Agents SDK, Vercel AI SDK, and Mastra

The implementation pattern is consistent across these frameworks. Spans use OTel GenAI conventions where supported, and correctness scores become custom attributes on the relevant span. The framework determines how execution becomes a trace. The evaluator supplies the semantic judgment attached to it. Keeping these roles separate lets the same span checks work for graph nodes, handoffs, tool calls, and model completions.

LangGraph supports stateful, multi-agent applications with built-in persistence for error recovery and human-in-the-loop workflows. It does not emit OTel spans natively, so manual instrumentation or third-party bridges produce spans for its nodes. Correctness attributes attach to the node span, linking a bad output to the graph node that produced the wrong state.

OpenAI Agents SDK packages agents, tools, handoffs, and guardrails, with sessions and tracing as additional built-in features. Its tracing supports visibility into execution, while auto-instrumentation handles context propagation for in-process handoffs. Correctness scores on handoff spans expose lost context before downstream steps compound the error.

Vercel AI SDK provides a TypeScript toolkit for AI applications in Next.js, React, and Node.js, including tool calling and agentic loops. Its optional OTel telemetry lives in @ai-sdk/otel and uses GenAI semantic conventions. Correctness scores attach as additional span attributes within that same telemetry pipeline.

Mastra records spans for agent runs, workflow steps, tool calls, and model calls. Storage options include DuckDB for development and ClickHouse, PostgreSQL, MSSQL, MongoDB, or LibSQL for production, as well as the hosted Mastra platform. Correctness attributes travel with the span to the selected backend.

Cross-framework instrumentation also supports this separation of tracing and evaluation. OpenLLMetry, through traceloop-sdk, and OpenLIT emit traces using OTel GenAI conventions. OpenInference uses its own complementary specification instead. That distinction remains relevant when interpreting the trace structure, but custom correctness attributes remain readable in OTel-compatible backends. The score need not bind the diagnostic workflow to one vendor.

What correctness signals surface that health metrics never will: three production cases

In the routing agent’s March 2026 failure, a tool-call correctness check on the retrieval span could have compared returned fields with the expected schema. It would have fired on the first malformed response. That check would not need to decide whether the final route was sensible to detect the broken input contract. The existing health signals could not make that distinction because the API call itself completed.

The supplied evidence does not include a healthcare case. No named healthcare agent, observed failure, or responsible span is available to support a third production account. The general distinction between health and correctness still applies, but it does not establish a healthcare incident. Presenting one as observed would substitute plausibility for evidence.

The consumer-facing refund example shows a different semantic failure. Here, the defective element was the invoice argument. A tool-call correctness judgment would need to check whether the invoice ID was the one the refund was meant for. A response-shape check alone would not establish that.

These two accounts support a narrower, concrete conclusion. In one, the tool response failed to match the expected schema. In the other, the tool argument failed to match the intended invoice. The useful signal measures the gap between what the operation returned or acted on and what the task required.

Turning span-level scores into alerts, issue groups, and a fix loop

A correctness score becomes operationally useful when it triggers a response. That response needs an alert before users complain, a way to group recurring failures, and a path from diagnosis to a verified fix. An isolated low score is not enough. Alerting on every score drop creates noise without establishing whether a failure is recurring.

The recommended pattern is continuous sampling of production traces, with an evaluator from a different model family than the generating model. Alerts then fire on consecutive failures in the same category. When tool-call correctness failures recur across dozens of traces, they can point to a stale schema, a prompt regression, or a data-pipeline change. Reviewing each trace separately obscures that common cause.

AgentPProf frames the broader problem as a need for semantic profiling. Its semantic operation stack model groups activities by what the task is meant to do, using more than code paths alone. Operations must identify which kind of work repeatedly fails and where responsibility for that failure belongs.

The fix loop continues when a grouped failure passes its diagnostic context to a coding agent over MCP. A prompt regression or schema mismatch can then move toward a fix and a PR. Verification closes the loop after the proposed change. Captured production failures become new evals automatically, so recurrence after a fix triggers a regression alert. The endpoint is not a cleaner-looking trace, but evidence that the previously silent failure is now detectable.

Sources

  1. AgentPProf: Semantic Profiler for Long Horizon AI Agents
  2. Detecting Silent Failures in Multi-Agentic AI Trajectories
  3. TRAJDEBUG: Tracing Error Lifecycle to Identify Critical Failures in Long-Horizon Agent Trajectories
Filed underAgent Tracing

More in Agent Tracing