> ## Documentation Index
> Fetch the complete documentation index at: /docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Trace and session evals

> Some failures only surface across a whole request or conversation - a loop, dropped context, a goal the user never reached.

A span eval scores one span. A trace eval scores every span in one request; a session eval scores every trace sharing a `session.id`. Each returns one label, score, and explanation for the **unit** it scores - one trace for a trace eval, one session for a session eval.

For which scope answers which question, see [Eval scope](/docs/ax/evaluate/create-evaluators.md#scope); for the conceptual distinction, see [Evaluation levels](/docs/ax/concepts/evaluators/evaluation-levels.md).

## How trace and session evals work

The **Scope** dropdown on the evaluator form sets whether an evaluator scores a span, a trace, or a session. You run it by attaching it to a task, which points it at a data source and sets what to score and how often. All evaluators on one task share a scope, so cover several scopes on one project with a task for each.

![New Evaluator form for a hallucination evaluator with the Scope dropdown open and highlighted, listing Span for evals on an individual span, Trace for evals across an entire trace, and Session for evals across traces in a session, with Session selected, and a Configuration column on the right showing Pick a Data Source, Filter Sessions, Preview Matching Data, and Map Variable to Data](https://storage.googleapis.com/arize-assets/doc-images/evaluate/evaluator-scope-selector.png)

Set Scope to Trace or Session on the New Evaluator form

### Session-only variables

Session evaluators have two variables that Arize AX assembles for you rather than reading from a span attribute, one entry per turn, where a turn is one trace in the session. The two are mutually exclusive, and you choose between them with the **Conversation** and **Turn data** radio buttons on the evaluator form.

* **`{conversation}`** is the session transcript Arize AX builds as a JSON array with one `input` / `output` pair per turn, taken from each trace's root span in chronological order. It needs no variable mapping, and it is valid only at session scope.
* **`{turn_data}`** is the string Arize AX produces by rendering a **Turn Definition** template you write once per turn, then joining the rendered turns with `TURN 1`, `TURN 2`, and so on as separators. Use it when the default input/output transcript leaves out something the judge needs, such as tool results or retrieved context.

![New Evaluator form with Scope set to Session and the Conversation and Turn data radio buttons highlighted, Conversation selected and captioned evaluate the full session transcript with input and output per turn, Turn data captioned evaluate a custom per-turn layout you define below, and the Configuration column on the right showing Task Configuration with a name, sampling rate, Run Continuously and One-Time Backfill toggles, and an Advanced section](https://storage.googleapis.com/arize-assets/doc-images/evaluate/conversation-and-turn-data.png)

Choosing Conversation or Turn data on the New Evaluator form

### How variables are filled in

At span scope, each template variable reads one value from one span. At trace and session scope, a variable can match many spans, so the matching values are concatenated with commas in chronological order. For trace evals, spans are ordered by span timestamp. For session evals, spans are grouped into traces first, and traces are ordered by earliest span timestamp.

Each value is truncated at 100,000 characters, and after that truncation a session's fully assembled value is capped at 100,000 characters. Some judge models raise both limits.

### Where results land

Each unit produces one result, written to that unit's root span. Results are stored under a prefixed column name so span, trace, and session evals that share a name stay distinct:

| Scope | Column prefix | Written to |
| :- | :- | :- |
| Span | `eval.<name>` | The evaluated span |
| Trace | `trace_eval.<name>` | The trace's root span |
| Session | `session_eval.<name>` | The root span of the session's first trace |

Sampling on a trace or session task applies per unit, so 10% sampling on a session task evaluates 10% of sessions rather than 10% of spans.

> [!NOTE]
>
> When a task runs, Arize AX collects each unit's spans from a window that extends 24 hours before the time window the task itself evaluates, so a session that has been idle for longer than that contributes only its recent traces. Arize AX searches back 7 days to find a unit's root span, so results still land on the correct span for long-running sessions.

## Set up a trace or session eval

Trace and session evaluators share one form with two halves. The left pane defines the evaluator: name, scope, judge model, template, and choices. The numbered **Configuration** column on the right points it at data and sets up the task. The steps below follow that order, with one extra decision for sessions about how each turn reaches the judge.

> [tab] Trace eval
>
> Ask [Alyx](/docs/ax/alyx.md), the Arize AX assistant, to build a trace-scoped evaluator for you: try *"Create a trace-scoped evaluator that checks whether the agent called tools in a sensible order."*
>
> **1. Open the New Evaluator form**
>
> Open **Evaluators** in the left navigation and click **New Evaluator**, or open a trace from the traces table and click **Add Trace Eval** in the trace header, an action that pre-sets the scope for you.
>
> **2. Name it and set Scope to Trace**
>
> In the left pane, enter a **Name** and set **Scope** to **Trace**. The **Result Column Name** is auto-populated from the name and becomes the `trace_eval.<name>` column.
>
> **3. Pick the judge model and write the template**
>
> Choose the judge model above the template, then write the template, referencing the variables the judge needs, for example `{question}`, `{tool_calls}`, and `{output}`. Because the eval sees the whole trace, write criteria about the path the agent took.
>
> **4. Define Choices and Optimization Direction**
>
> Below the template, define **Choices** and their scores, then set the **Optimization Direction** so Arize AX knows whether a higher or a lower score is better.
>
> **5. Point it at data and configure the task**
>
> Choose **Project** in the **Configuration** column - a dataset is scored one example at a time whatever the scope, so trace grouping applies only to a project. Filtering here accepts a [multi-span query](/docs/ax/evaluate/run-evals-on-traces.md#multi-span-queries-trace-and-session-evals), available only at trace and session scope. Then map each variable and set sampling and cadence, as in [Run online evals on traces](/docs/ax/evaluate/run-evals-on-traces.md#task-configuration).
>
> **6. Create the evaluator**
>
> Click **Create Evaluator** to save it to the [Evaluator Hub](/docs/ax/evaluate/create-evaluators.md#evaluator-hub) for reuse, or **Create and Run Evaluator** to save it and start the task you just configured.
>
> ![Use Evaluator(s) Task Configuration form for a hallucination evaluator scoped to Trace, showing the gpt-4o judge model and a template referencing input, context, and output variables on the left, and on the right Preview Matching Data listing chain, LLM, embedding, and retriever spans of matching traces, then Map Variable to Data mapping input to the input column with a data preview of the latest matching trace](https://storage.googleapis.com/arize-assets/doc-images/evaluate/trace-scoped-evaluator.png)
>
> A trace-scoped evaluator, its matching traces, and its variable mapping

> [tab] Session eval
>
> Ask [Alyx](/docs/ax/alyx.md), the Arize AX assistant, to build a session-scoped evaluator for you: try *"Create an evaluator that checks whether the agent maintained context across the whole session."*
>
> **1. Open the New Evaluator form**
>
> Open **Evaluators** in the left navigation and click **New Evaluator**, or use the **Add Session Eval** action next to the session ID in the session header. Sessions exist only when your application sets `session.id` on its spans; see [OpenInference context managers](/docs/ax/concepts/otel-openinference/context-managers.md) if that attribute is missing.
>
> **2. Name it and set Scope to Session**
>
> In the left pane, enter a **Name** and set **Scope** to **Session**. The **Result Column Name** is auto-populated from the name and becomes the `session_eval.<name>` column.
>
> **3. Choose Conversation or Turn data**
>
> Pick **Conversation** to have Arize AX build the transcript from each turn's input and output. Picking it inserts `{conversation}` into your template. Pick **Turn data** when the judge needs more than input and output; that option inserts `{turn_data}` and reveals the **Turn Definition** field.
>
> **4. Write the Turn Definition (Turn data only)**
>
> Lay out one turn using `{variable}` references, for example:
>
> ```
> User: {user_msg}
> Assistant: {assistant_msg}
> Tool result: {tool_result}
> ```
>
> Arize AX renders this template once per turn and joins the results with `TURN 1`, `TURN 2` markers. Variables you leave unmapped render empty rather than failing the turn.
>
> **5. Write the template, then define Choices and Optimization Direction**
>
> Choose the judge model, write the template around `{conversation}` or `{turn_data}`, then define **Choices** and their scores and set the **Optimization Direction** so Arize AX knows whether a higher or a lower score is better.
>
> **6. Point it at data**
>
> Choose **Project** in the **Configuration** column - a dataset is scored one example at a time whatever the scope, so session grouping applies only to a project. Filtering here accepts a [multi-span query](/docs/ax/evaluate/run-evals-on-traces.md#multi-span-queries-trace-and-session-evals), available only at trace and session scope.
>
> **7. Map variables and check the Data Preview**
>
> A `{conversation}` eval maps nothing: Arize AX assembles the transcript from the matched session spans. For a `{turn_data}` eval, map each Turn Definition variable to a column. Each variable is read only from the turn it belongs to, so turn 2's values never appear in turn 1. **Data Preview** shows the exact prompt the judge receives for the latest matching session. Then set sampling and cadence, as in [Run online evals on traces](/docs/ax/evaluate/run-evals-on-traces.md#task-configuration).
>
> **8. Create the evaluator**
>
> Click **Create Evaluator** to save it to the [Evaluator Hub](/docs/ax/evaluate/create-evaluators.md#evaluator-hub) for reuse, or **Create and Run Evaluator** to save it and start the task you just configured.
>
> ![New Evaluator form for a hallucination evaluator scoped to Session with Conversation selected, showing the gpt-4o judge model and template on the left, and on the right Preview Matching Data with Traces, Spans, and Sessions tabs listing agent, retriever, and LLM spans from a trip planning agent, then Map Variable to Data noting that the eval uses the conversation variable assembled from the matched session spans](https://storage.googleapis.com/arize-assets/doc-images/evaluate/session-scoped-evaluator.png)
>
> A session-scoped evaluator using Conversation, with its matching sessions

> [!NOTE]
>
> The steps above describe the **New Evaluator** form. Attaching an evaluator that already exists in the [Evaluator Hub](/docs/ax/evaluate/create-evaluators.md#evaluator-hub) opens the same Configuration column under the title **Use Evaluator(s) – Task Configuration**, where the primary button reads **Run Evaluator(s)** and the Configuration steps are numbered from the point you enter.

> [!NOTE]
>
> **Test Evaluator On Spans** is disabled for trace- and session-scoped evaluators when the data source is a project. Use the data preview under **Map Variable to Data** to confirm what the judge receives before you run the task.

## View results

Trace results appear in the **Trace Evals** row of the trace header, and session results in the **Session Evals** row of the session header. In the traces table, add the **Trace Evaluations** or **Session Evaluations** column and filter on `trace_eval.<name>.label` or `session_eval.<name>.score` to isolate failures. See [Results and costs](/docs/ax/evaluate/results-and-costs.md) for reading results in general.

![Session detail view showing total duration, total tokens, and total traces alongside a Session Evals row with a hallucination label and a Session Coherence incoherent label, the latter expanded into a panel giving the label incoherent, a score of 0, and an explanation of why the conversation was repetitive and unfocused](https://storage.googleapis.com/arize-assets/doc-images/evaluate/session-eval-results.png)

Session Evals in the session header, with one result expanded

## Log trace and session evals from code

If you run evals in your own environment, log results back with the prefix that matches the scope. Every result needs a `context.span_id` column, and for trace and session evals that column holds the id of the unit's root span, which is the trace's root span for a trace eval and the root span of the session's first trace for a session eval.

```python theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
# Trace eval: one row per trace, keyed on that trace's root span id
trace_eval_df["context.span_id"] = trace_eval_df["root_span_id"]
trace_eval_df = trace_eval_df.rename(columns={
    "label": "trace_eval.trajectory.label",
    "score": "trace_eval.trajectory.score",
    "explanation": "trace_eval.trajectory.explanation",
})

# Session eval: one row per session, keyed on the root span of the session's first trace
session_eval_df["context.span_id"] = session_eval_df["first_root_span_id"]
session_eval_df = session_eval_df.rename(columns={
    "label": "session_eval.correctness.label",
    "score": "session_eval.correctness.score",
    "explanation": "session_eval.correctness.explanation",
})
```

Log each dataframe with `client.spans.update_evaluations()`. For the full export, evaluate, and log flow, including how far back evals can be applied, see [Run online evals on traces](/docs/ax/evaluate/run-evals-on-traces.md#create-a-task).

## Further reading

> [card] [Run online evals on traces](/docs/ax/evaluate/run-evals-on-traces.md)
>
> Task filters, sampling rates, cadence, and run logs in full.

> [card] [Session-level evals](/docs/ax/evaluate/evaluators/trace-and-session-evals/session-level-evaluations)
>
> Scoring a full multi-turn conversation end to end.

> [card] [Agent trajectory evaluations](/docs/ax/evaluate/evaluators/trace-and-session-evals/trace-level-evaluations/agent-trajectory-evaluations)
>
> The canonical trace eval: judging the path an agent took.

> [card] [Trace evals for a recommendation agent](/docs/ax/cookbooks/evaluate/trace-level-evaluations-for-a-recommendation-agent.md)
>
> A worked trace-scoped example, end to end.

> [card] [Session evals for an AI tutor](/docs/ax/cookbooks/evaluate/session-level-evaluations-for-an-ai-tutor.md)
>
> A worked session-scoped example across a multi-turn conversation.
