← Back to blog

Agent behavior spans need validation against intent before deployment at scale

Agent behavior spans need validation against intent before deployment at scale
TL;DR

Agent span validation against activity schemas catches misalignment before production, where the cost of a wrong action in dispatch or document handling is im

What you get from span-level validation before deployment

Testing an agent's outputs tells you whether the final answer looked right. It does not tell you whether the agent took the right steps to get there, called the right tools in the right order, or stayed within the scope you defined. Span-level validation closes that gap by checking each recorded step in an agent's execution trace against a schema that describes what the agent is supposed to do, in what order, with what constraints.

This article explains how to instrument agent behavior at the span level, what activity schemas need to contain to be useful, and how scoring across spans gives you a signal that pass/fail output testing cannot.

Why output testing is not enough

Two incidents from the first week of August 2026 illustrate the problem clearly.

New Orleans went live in July 2026 with Carbyne's AI triage system for 911 dispatch. The system handles 15 to 18 of every 20 calls about a single car crash, filtering duplicates and prioritizing incidents before a human dispatcher picks up. The system was trained on three months of local recordings to reduce accent misrecognition. That is a narrow, well-defined task, and its output, a triage classification, looks simple. But the steps that produce that classification involve audio processing, intent inference, deduplication against live call queues, and a priority assignment. Each of those steps can produce a plausible-looking output while getting the reasoning wrong. A dispatch system that correctly labels a call as "duplicate" for the wrong reasons is a liability, not an asset.

The same week, reports emerged that Google Gemini was leaking private Google Docs details in agent outputs. The agent's final answers looked coherent. The problem was upstream: the agent was retrieving and surfacing document content it should not have accessed. Output evaluation would score those answers as high quality. Span-level review of the retrieval steps would have flagged the unauthorized access immediately.

These two cases point at the same structural failure. When you only measure what the agent says, you miss what it did.

For more on the gap between what agents appear to do and what they actually do, see measuring what agents actually do versus what you think they do.

What spans record and why that matters

A span is a discrete unit of work in an agent's execution trace: a tool call, a model inference, a retrieval, a state update. OpenTelemetry-compatible instrumentation captures these as structured records with a start time, end time, inputs, outputs, and metadata. The OpenTelemetry standard gives you a common schema across frameworks and model providers.

The span record for a retrieval step in a document agent should include which source was queried, what query was issued, what results came back, and whether any access policy was checked. The span record for a tool call in a dispatch agent should include which tool was invoked, with what arguments, and what the tool returned. Neither of those things is visible in the final output.

When you instrument at the span level, you can answer questions that output evaluation cannot: Did the agent access a resource it was not authorized to use? Did it call a tool out of sequence? Did it skip a required verification step? Did it retry a failing tool call more times than the schema allows?

RAG retrieval agents are particularly exposed here because their span-level behavior, specifically what they retrieve and from where, is entirely invisible in a clean final answer.

Activity schemas: what they need to contain

An activity schema is a specification of what a given agent is supposed to do. It describes the expected sequence of span types, the permitted tools and data sources, the required checks, and the conditions under which the agent should escalate or stop.

A useful schema for a triage agent in a 911 context would specify: the agent must perform deduplication before priority assignment; the agent must not modify any call queue record without a human confirmation span in the trace; the agent must complete classification within a defined latency window. A schema for a document summarization agent would specify: retrieval spans must reference only sources in a permitted list; the agent must not include source identifiers from outside that list in the output; tool calls to external APIs are not permitted.

Schemas written at this level let you validate execution traces mechanically, span by span, before you put the agent in front of production traffic. The validation is not about whether the answer was good. It is about whether the agent's behavior was consistent with what you authorized it to do.

This is the foundation of validating agent behavior against expected outcomes, which becomes more important, not less, as agents acquire more tools and longer execution chains.

Scoring quality across spans, not just at the endpoint

Pass/fail schema validation catches hard violations: a tool that was never supposed to be called, a retrieval from a forbidden source. But many real failures are softer. The agent called the right tools in the right order, but the retrieval quality was poor, the model's reasoning span contained a factual inconsistency, or the agent used 14 tool calls to do what the schema expected in four.

Scoring across spans addresses this. You assign a quality score to each span type based on what you expect from it: retrieval precision, reasoning coherence, tool argument correctness, latency relative to the defined window. You aggregate those scores across the trace to get a run-level quality signal. A run that passes schema validation but scores low on retrieval quality is worth examining before it goes to production.

Step-level accuracy and trajectory evaluation for production agents covers the mechanics of this in detail. The key point here is that span-level scoring gives you a dimensional view of agent quality that a single output score cannot provide.

Prefactor records spans via SDK instrumentation, scores each span against configurable rubrics, and validates traces against activity schemas. The audit trail it keeps is per-run and per-span, which means you can see exactly where in a trace a quality problem originated, not just that the final output was wrong.

The deployment pressure problem

81% of respondents in a June 2026 survey reported feeling pressure to deploy AI agents quickly, even when security or governance is not fully in place. That pressure is real, but the consequences of skipping pre-deployment validation are also documented. Only 14.4% of agents that went live in 2026 received full security and IT approval during deployment.

The Step Finance incident in January 2026 shows what that gap costs. AI trading agents on the Solana DeFi platform executed 261,854 SOL in transfers, between $27 and $40 million, after an executive device was compromised. Only $4.7 million was recovered. The agents did exactly what they were designed to do. The problem was that no schema existed to constrain the conditions under which they could do it, and no span-level validation was in place to catch that the authorization trace was abnormal.

Span validation would not have prevented the device compromise. But an activity schema that required a confirmed human authorization span before any transfer above a defined threshold would have stopped the execution chain at the right point.

For teams managing multiple agents across different risk levels, the agent risk audit is a practical place to understand where your current exposure sits.

Pre-deployment validation is also not a one-time gate. Detecting agent quality decay and production drift describes how to keep schema validation running continuously once an agent is live, so that model updates or data drift do not silently degrade behavior that passed pre-deployment checks.

Ghost actions, cases where an agent does something nobody requested, are another category of span-level failure that output scoring will not catch.

The silent failure gap in agent quality evaluation before production covers the broader pattern of what gets missed when teams stop at output-level testing.

Where to start

Define one activity schema for your highest-risk agent, write down the span sequence it should follow, the tools it is permitted to use, and the checks it must include. Instrument that agent with span-level tracing and validate one week of traces against the schema before expanding coverage.

Start evaluating your agents and read the docs to see how Prefactor records spans, applies schema validation, and scores run quality across traces.

Frequently asked questions

What is the difference between output evaluation and span-level validation?
Output evaluation checks whether the agent's final answer was correct or appropriate. Span-level validation checks each step in the execution trace, tool calls, retrievals, model inferences, against a schema that defines what the agent was authorized to do and in what order. An agent can produce a correct-looking output while having taken unauthorized steps to get there; span-level validation catches that.
How detailed does an activity schema need to be to be useful?
A schema needs to specify at minimum: the expected span types and their permitted order, which tools and data sources the agent may access, any required verification or confirmation steps, and the conditions under which the agent should stop or escalate. A schema that only lists permitted tools without sequencing constraints will miss ordering violations and skipped checks.
Can span validation catch problems that are not strict rule violations, like gradual quality degradation?
Yes, if you combine schema validation with span-level quality scoring. Hard schema validation catches forbidden actions and sequencing errors. Scoring each span type on dimensions like retrieval precision or reasoning coherence catches softer degradation: the agent follows the right steps but does them poorly. Tracking those scores over time also surfaces drift after model updates or data changes.
At what point in the development lifecycle should span validation be introduced?
As early as you have a repeatable execution trace to validate against, typically before the first production deployment but after you have enough sample runs to understand what the agent actually does. Waiting until production means the schema you write will be descriptive of existing behavior rather than prescriptive of intended behavior, which reduces its ability to catch misalignment.

See how every agent performs, and make it better

Prefactor helps teams observe, evaluate, and improve their AI agents in production, across every framework and provider.