Trace Schema Design for Agentic Systems

Trace schemas record intent and provenance so teams can catch agent misbehavior that logs miss.

· 8 min read · Updated
Cover illustration for “Trace Schema Design for Agentic Systems”
Agent Observability · October 22, 2026 · 8 min read · 1,795 words

Traditional error monitoring fails for AI agents because a tool call or response code that shows success does not show whether the agent followed its instructions. Trace schema design closes that semantic gap by recording intent, plans, execution, and provenance as comparable signals.

Why logging alone cannot tell you what an agent was supposed to do

An agent can fabricate an identifier or promise a refund outside policy while returning a success status code. Conventional logs may record the tool call, response, and latency without exposing either deviation. The execution looks healthy, but the behavior is wrong. A Series B fintech agent made $2.1 million in mistaken promotional rate commitments to thousands of users, none of which conventional monitoring detected. The missing evidence was not another event record, but a baseline against which to judge the commitment.

That baseline cannot reliably be inferred from the sequence of calls. The same prompt can lead to different tool sequences when the model temperature, retrieved context, or prior memory state differs. Microsoft AI Red Team’s taxonomy includes goal hijacking, session context contamination, and inter-agent trust escalation, where apparently normal output can conceal redirected intent. Detecting these failures requires knowing what the agent was authorized to accomplish.

A dedicated schema makes that comparison possible by preserving the instructions and decision points with the execution record. Lemma addresses this gap by auditing traces against the agent’s own instructions and surfacing misalignment before it reaches users. Such auditing depends on the evidence emitted upstream.

How the failure landscape has grown beyond what early schemas assumed

The taxonomy’s v1.0 release, published April 2025, distinguished failures unique to agentic systems from existing failures amplified by them. Its v2.0 update grew the catalog from 27 to 34 failure modes after a long period of red team engagements against systems that were already deployed. The taxonomy groups failures by whether they are new or existing and whether they involve security or safety, covering losses of confidentiality, availability, or integrity as well as harm to users or society.

The revision followed mainstream adoption of open-source agentic frameworks, a maturing MCP ecosystem, computer-use agents entering production, and empirical findings that challenged earlier predictions. In 2025 alone, MCP-related software accounted for 99 published CVEs. Tool poisoning was now a live attack surface. A schema built only around model requests and responses cannot show all the boundaries these systems cross.

The seven additions expose different instrumentation needs. Agentic supply chain compromise requires tool definitions and provenance, because poisoned servers or plugins can inject natural-language instructions without changing a binary. Goal hijacking requires initial intent and the resolved goal at each step, while inter-agent trust escalation requires attribution of instructions to their issuing agents. Computer-use agent visual attacks, session context contamination, MCP/plugin abuse, and capability/architecture disclosure introduce distinct instrumentation points too. Without intent, provenance, and attribution in the trace, monitoring platforms, including Lemma, lack the evidence needed to detect these deviations.

What a trace schema is actually doing in an agentic system

A trace schema defines what signals an agentic system must emit at each decision point so that intent can be reconstructed and compared with execution. The schema requires evidence that evaluations, monitors, and alerts consume. Without that contract, instrumentation tends to capture convenient inputs and outputs while omitting plans, tool considerations, and intermediate decisions.

The contract is hierarchical because the behavior is hierarchical. A run has steps, and those steps have model and tool calls that each help explain a different part of the outcome. Defined fields make deviations inspectable. OpenTelemetry provides a structural basis for spans and metrics, but agent observability needs intent signals above that operational foundation. Measurements of timing and usage alone cannot show whether a decision was justified.

At the base, gen_ai.client.operation.duration records latency, while gen_ai.client.token.usage records the counts of input and output tokens. Both histogram metrics are needed to reason about speed and cost. They are necessary but insufficient for behavioral diagnosis. Above them, the schema must connect the recorded reasoning trace, tools considered, tools invoked, arguments, responses, per-step tokens, and hop latency. That connected record supports replay and comparison without asking an evaluator to reconstruct missing decisions from the final answer.

The span hierarchy that makes intent reconstructable

Diagram: The Span Hierarchy That Reconstructs Agent Intent. Visualizes: Visualize the nested span hierarchy a trace schema must emit so that intent can be reconstructed and compared with execution.

The top-level agent.run span holds the record of how the task ran, along with the agent’s initial instructions and terminal goal. Each reasoning cycle becomes an agent.step child. Within it, model.call records the prompt, model ID, prompt version, input and output token counts, latency, and finish reason. A corresponding tool.call records the tool name, sanitized arguments, result status, and retry count. This hierarchy ties each action to the step that produced it.

The termination record deserves its own distinction. An agent.terminated span with step_limit as its reason represents an alertable event. The schema must also place retrieved document IDs, memory reads and writes, handoff source and destination, and final response status on the relevant spans. These fields explain what information entered the run and where it went. Without them, the tree shows sequence but leaves important dependencies implicit.

To reconstruct intent, the record must keep the plan separate from execution. Its tool sequence, preconditions, and termination conditions show what the agent planned to do before it acted. Plan-vs-execute divergence is a canonical fingerprint of indirect prompt injection at the planning layer, although the comparison provides evidence that requires evaluation before diagnosis. The record also needs tools considered but not invoked because the execution sequence alone cannot show which other tools the agent chose not to use. Finally, finish reason must be a structured enum, with distinctions such as “max tokens,” “stop sequence,” “tool error,” and “goal achieved” available for different operational responses.

How multi-agent pipelines break the single-agent span model

A failure reported by Agent B may originate either in the handoff from Agent A or in B’s reasoning. Disconnected logs obscure that distinction at exactly the point where responsibility crosses a boundary. The receiving agent can become the apparent culprit. A multi-agent schema therefore needs a shared execution tree as well as complete records for each agent.

An INTERNAL invoke_workflow span acts as the parent for several invoke_agent children. Each child records input tokens, output tokens, latency, model name, status code, and error type, allowing attribution at the agent level. Parent-child links keep each handoff tied to the one before it. Source and destination fields then identify the transfer within that tree, so that an investigator can connect B’s failure to the input A supplied.

Inter-agent trust escalation requires attribution of which agent issued which instruction to which orchestrator. At a handoff boundary, goal hijacking becomes detectable by comparing the parent’s stated goal with the child’s resolved goal. Session context contamination requires another kind of continuity. A shared parent without those attribution and provenance fields preserves topology, but not enough context to explain the deviation.

The fields that turn a trace into a failure-routing signal

Diagram: Five Failure Categories, Five Fix Destinations. Visualizes: Visualize a routing structure that maps five failure categories to the layer where a fix belongs: Planning errors → planner (fingerprint: tool sequence planned ≠ executed…

A useful schema connects evidence to the layer where a fix belongs. Five operational categories provide that routing structure, namely planning errors at the planner, tool errors at the tool layer, retrieval errors at the retriever, reasoning errors at the generator, and safety/policy violations at the output scanner. Field selection follows those distinctions. Collecting more data does not compensate for omitting the field that separates two different causes.

Planning errors are visible in differences between the tool sequences planned and executed, calls that repeat with similar arguments, or a lack of progress toward the goal for N consecutive steps. Tool errors have a different fingerprint. A non-success status followed by continued execution as though the call succeeded exposes failed recovery, with retry count supplying context. A tool name absent from the runtime catalog flags tool hallucination.

Retrieval diagnosis depends on document IDs that can be checked against the expected source set and authorized corpus. Reasoning diagnosis instead compares the model’s output with the upstream retriever span, using a faithfulness score and threshold. The distinction changes the fix. The wrong chunk points to retrieval, while the right chunk followed by the wrong conclusion points to reasoning. Safety/policy evaluation checks finish reason and output content against the policy specification in the initial instructions, so the output scanner has a stated standard and does not have to infer one.

How continuous evaluation plugs into the schema to catch regressions before users do

Held-out benchmarks and final-answer pass/fail checks miss trajectory quality, tool-call correctness, looping, and recovery. A schema that records the decisions made along the way lets evaluation check each span. The unit of assessment becomes the decision. This exposes regressions that an apparently acceptable final response can conceal.

These metrics check task completion against system state rather than output text, the tool accuracy of each call against the schema, loop count against the minimum steps needed, and trajectory match against a reference path. Per-step cost and latency attribution add operational context. These measurements depend on structured comparison targets. Initial instructions, reference trajectories, retrieved documents, and each step’s model output must be available as fields.

A scoring gateway can evaluate each LLM span for faithfulness against its upstream retriever span and use a threshold to block a deploy in CI. Once a failure has a named category and structured evidence, it can become a labeled dataset entry that the next PR must clear. Diagnosis then feeds the next regression test. As one application of this platform layer, Lemma audits every trace against the agent’s instructions and groups deviations into actionable issues automatically. The schema supplies the comparable signals, while the evaluator judges them and the gate acts on the result.

Where schema design decisions actually go wrong in practice

The practical audit begins with a question about intent. Does the run record what the agent was instructed to do, independently of what it eventually said? A yes means there is an explicit baseline for evaluating the response, rather than treating output as evidence of its own correctness. Does execution also remain separate from the plan produced before it?

Can a task still be followed through one parent-child execution tree as it passes from one agent to another? Can finish reasons distinguish a clean completion from a token limit, tool failure, or step limit without interpreting free text? Independent records and strings such as “done” or “error” leave automated routing without the distinctions it needs.

The final questions concern where instructions and context originated. Does each tool record include the provenance of its definition? Do memory reads and writes appear in the relevant spans so that contamination can be traced across runs? These are tests of whether the schema represents the system it claims to observe. A schema that captures intent, plan, execution, and provenance is more honest about what observability is for without being more complex than one that does not.

Sources

  1. Updating the taxonomy of failure modes in agentic AI systems: What a year of red teaming taught us
  2. New whitepaper outlines the taxonomy of failure modes in AI agents
  3. Model or Harness? An Interaction-Centric Taxonomy for Localizing Agent Failures

More in Agent Observability