﻿# Promptfoo trace assertions: fast selected spans do not prove an expected operation happened

Pair Promptfoo trace timing checks with span-presence assertions, verify attribute filters and correlate traces to the actual evaluation case before accepting results.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/fg2-promptfoo-trace-assertions-span-presence-selection/
Language: en

## Distinguish an answer from execution evidence

An agent can claim to have searched a dataset without the expected retrieval operation appearing in its execution trace. Promptfoo's [trace assertions](https://www.promptfoo.dev/docs/configuration/expected-outputs/deterministic/) can inspect recorded operations rather than relying on answer text. Define whether the requirement concerns a claimed action, an instrumented call or a successful application outcome. These are different observations, and a trace span alone does not establish that its payload was correct or useful.

## Verify collection and case correlation

The [tracing guide](https://www.promptfoo.dev/docs/tracing/) describes collecting trace data for an evaluation. Before writing thresholds, confirm that the inspected trace belongs to the current test and contains the relevant application boundary. A successful request can produce no usable trace when propagation or export is broken. Conversely, unrelated background spans can make an operation appear present. Inspect a diagnostic case with a known operation and compare its trace identity with the evaluation result.

## Check selection semantics explicitly

Trace assertions select spans by name patterns and optional attributes. The deterministic-metric reference distinguishes case-insensitive name globbing from exact, type-sensitive attribute matching. Similar-looking tool names do not guarantee a match when an attribute is missing or encoded differently. Retain the selected span set during setup. A filter intended to measure retrieval can otherwise select nothing or include unrelated work while still looking reasonable in a compact configuration file.

## Require presence independently of speed

The documentation recommends a minimum span-count assertion when matching operations must exist. A duration or error check is not a substitute for that existence requirement. Also inspect percentile units: the documented percentile scale is percentage-based rather than a fractional probability. The [assertion configuration](https://www.promptfoo.dev/docs/configuration/expected-outputs/) determines how these checks combine into a verdict. Keep operation presence, duration and correctness as separately explainable properties instead of collapsing them into a single reassuring timing number.

## Test absent and misidentified operations

Use fixtures containing the expected call, no call and a similarly named unrelated call. Confirm that presence fails where intended and that timing includes only the selected population. The guides to [agent budget accounting](/journal/fg2-inspect-message-turn-token-budget-agent-comparisons/) and [mandatory assertion rules](/journal/fg2-promptfoo-weighted-threshold-mandatory-assertions/) provide related controls. Accept the evaluation when trace correlation, selection and existence jointly explain the result, preserving the difference between a fast observed operation and an operation that never happened.
