# Evaluation results on spans, traces and sessions

**Last updated:** 2026-11-24T13:32:58-03:00 (UTC-3)

With **evaluation results** on, every score the gateway stores, whether an LLM judge wrote it, a code evaluator, a reviewer, your application through the API or your end users as feedback, becomes an **evaluation result** attached to what it judged: a span, a whole trace or a session. Each result carries a normalized verdict (`pass`, `fail` or `none`), a typed value, a run status, the evaluator and the exact version that produced it, who submitted it, and the same key, principal, team and organization as the traffic it judged. Results show on the request log, in the trace drawer and on the session, become events on the trace's spans, and leave over OTLP with the trace and span IDs of what they judged, so your tracing backend joins them to the request too.

Nothing changes for the request path: results are written by the judge workers, the review screens and the API, never while a request is served.

## Turn it on

```yaml
storage:
  provider_encryption_key_env: GATEWAY_PROVIDER_ENCRYPTION_KEY   # judge reasoning is stored encrypted
features:
  evals: true
  evaluation_results: true
  span_store: true          # recommended: results attach to the exact span
```

| Flag | Default | What it turns on |
| --- | --- | --- |
| `evaluation_results` | `false` | Evaluation results: the new fields on every score, the `/evaluations` API, span, trace, session and feedback targets on `POST /v1/scores`, results on the request log, the trace drawer and sessions, OTLP export, and the background migration of older scores. Requires `evals` and `storage.provider_encryption_key_env`. A tenant action: with `feature_plan_entitlements` a team's plan must include it. Changeable at runtime from **Settings → Features** or `PUT /api/v1/admin/features/evaluation_results` |

With `feature_plan_entitlements`, a write whose team plan cannot be read fails (503 `entitlement_unavailable`, or a judge retries) rather than guessing. The gateway refuses to start with `evaluation_results` on and no `storage.provider_encryption_key_env`: a judge's reasoning is content and is never stored in clear.

With the flag off the gateway stores scores exactly as before, and `POST /v1/scores` accepts exactly the payloads it accepted before. The same holds, with the flag on, for a team whose plan does not include `evaluation_results`: its scores, judges and reviews keep the old behavior, and the migration leaves its scores alone.

### What happens when you turn it on

1. New results are written with all the fields below.
2. The gateway builds the result indexes on the score table without blocking writes (`CREATE INDEX CONCURRENTLY`), then a background migration converts older scores, 500 every two seconds, until none is left. It is resumable (a restart continues where it stopped) and safe with several replicas. Follow it with `GET /api/v1/admin/evaluations/backfill` (global roles: it counts every team):

   ```json
   {"started_at":"2026-11-23T14:00:02Z","finished_at":"2026-11-23T14:00:09Z","migrated":1840,"batches":4,"remaining":0}
   ```

   Each older score gets its scope from its target, its trace ID from the latest request log row of the same request ID and team (a reused request ID names its latest request, as the request journey does), its span from the span store when it holds the request, its evaluator and version from its metadata, and an assessment from the evaluator's **current** pass criteria (`none` without them). Every migrated row is marked `assessment_backfilled: true`, so you can tell a derived verdict from one recorded when it was judged. A judge's explanation moves from the clear-text comment to encrypted reasoning; human comments stay where they are.

## What a result holds

| Field | Values | Meaning |
| --- | --- | --- |
| `scope` | `span`, `trace`, `session`, `run_item`, `run` | What was judged. A request is its own span (`scope: span`). |
| `trace_id`, `span_id` | W3C hex | The judged span; a trace result has only the trace (it judges the whole trace and shows on its root span) |
| `request_id`, `session_id` | | The judged request and its session |
| `assessment` | `pass`, `fail`, `none` | The verdict. From the evaluator's pass criteria, or what the API or a reviewer said |
| `metric_type` | `boolean`, `score`, `categorical`, `json`, `text` | The kind of value |
| `value`, `string_value`, `value_json` | | A number (boolean as 0 or 1), a label (with its mapped number when the label defines one), a JSON value of at most 8 KiB, or a text |
| `status` | `ok`, `error`, `skipped` | Whether the evaluator could judge. Only `ok` results are counted, averaged or included in a pass rate |
| `status_reason`, `error` | lowercase code; `{type, message}` | Why a result is `error` or `skipped`: `judge_failed`, `judge_refused`, `output_unparseable`, `content_not_captured` (the request's capture expired, or [the team keeps it for audit alone](/docs/features/content-capture/#one-policy-for-audit-and-evaluation-content_capture_evaluation)), `content_truncated` (the request or its answer is longer than the capture policy's `max_bytes`), `content_unreadable`, or your own code from the API |
| `source` | `llm`, `code`, `human`, `api`, `feedback` | Who produced it |
| `evaluator_id`, `evaluator_version` | | The evaluator and the exact version that produced it |
| `submitter`, `join_key` | | For feedback: who gave it, and the external key it was joined on |
| `origin` | `app`, `experiment` | Tells experiment results apart from results on production traffic |
| `judge_trace_id`, `judge_request_id`, `judge_cost_usd`, `judge_cost_state` | | The judge run that produced the result and what it cost, filled with [evaluation tracing](/docs/features/evaluation-tracing/#the-judge-fields-of-a-result) |
| `key_id`, `principal`, `team_id`, `organization_id`, `model` | | The judged traffic's identity, from its request log row |
| `valid`, `revision`, `edited`, `updated_at`, `updated_by` | | Edit state; see [Edit a result](#edit-a-result) |
| `reasoning`, `reasoning_state` | `shown`, `reader_grant_required`, `expired` | The judge's reasoning. A judge writes it from the sent view of what it judged, so it is shown to readers with `content_sent:read` of the result's team ([the content ladder](/docs/features/content-capture/#who-can-read)): administrators, organization admins and team administrators by role, anyone else with a `content:read` grant. `reader_grant_required` means the session lacks that permission. Showing explanations writes one audit row per team and answer (`evaluation.reasoning.read`) before any is decrypted; if it cannot be written, none is shown |

A failed judgement is no longer silent: when an evaluator's judge fails for good, is refused (budget, quota, model), or finds the request's capture expired, the request gets an `error` or `skipped` result with the reason, visible next to the others and left out of every count. A later successful judgement of the same rule replaces it and keeps it as an earlier revision.

### Pass criteria on an evaluator

Give an evaluator's output a `pass` rule and each of its results gets `pass` or `fail`:

```json
{"data_type": "numeric", "min": 0, "max": 1, "pass": {"op": "gte", "value": 0.7}}
{"data_type": "boolean", "pass": {"op": "eq", "value": 1}}
{"data_type": "categorical", "categories": ["good", "neutral", "bad"], "pass": {"labels": ["good"]}}
```

`op` is `gte`, `gt`, `lte`, `lt` or `eq`. Without `pass` the assessment is `none`.

## Send results from your application

`POST /v1/scores` with a key of scope `scores:write` keeps accepting the payloads it always did. With the flag on it also accepts:

```bash
curl -s https://gateway.example.com/v1/scores \
  -H "Authorization: Bearer $GATEWAY_KEY" -H "Content-Type: application/json" \
  -d '{"name":"thumbs","metric_type":"boolean","value":0,"assessment":"fail",
       "trace_id":"5bf92f3577b34da6a3ce929d0e0e4736","span_id":"00f067aa0ba902b7",
       "source":"feedback","submitter":"user-123"}'
```

Name exactly one target:

| Target | Fields | Notes |
| --- | --- | --- |
| A span | `span_id` with `trace_id` | W3C hex, exactly as the gateway returns them in `traceparent` and OTLP (no decimal conversion; uppercase is read as lowercase). The span must be one of the team's; a span the span store does not hold (an application's own span) is accepted when its trace contains a request of the team, and a span another team's request holds never is |
| A trace | `trace_id` | The trace must contain a request of the team |
| A request | `request_id`, or `target: {"type":"request","id":…}` | The request's own span |
| A session | `session_id`, or `target: {"type":"session","id":…}` | The team must have requests in the session |
| An external entity | `join_key` | Every request of the team that carried `X-Gateway-Feedback-Key` with that value (see [Feedback keys](#feedback-keys)), the 100 newest: one result on each. Only when no request carried the header, the requests tagged with the usage tag `feedback_key` (compatibility, same bound). A key on no request is refused (400) |
| An experiment item or run | `target` as before | |

An unknown target, or another team's, is refused with 400: results never attach to traffic the key cannot see.

### Feedback keys

To attach feedback to requests by your own ID (a support ticket, an incident, an order), send it on the requests:

```bash
curl -s https://gateway.example.com/v1/chat/completions \
  -H "Authorization: Bearer $GATEWAY_KEY" -H "X-Gateway-Feedback-Key: INC-2026/42" \
  -d '{"model":"chat-default","messages":[{"role":"user","content":"My order is late"}]}'
```

and later send the feedback with the same value as `join_key`:

```bash
curl -s https://gateway.example.com/v1/scores -H "Authorization: Bearer $GATEWAY_KEY" \
  -d '{"id":"csat-INC-2026-42","name":"csat","metric_type":"score","value":2,"join_key":"INC-2026/42","source":"feedback","submitter":"support-bot"}'
```

- `X-Gateway-Feedback-Key` takes one value of 1–200 printable ASCII characters without spaces; anything else answers 400 `invalid_feedback_key` before the request is sent. It is read whenever `evaluation_results` is on for the gateway, whatever the team's plan (with the flag off the header is ignored). A request answered by a semantic fallback alias keeps it.
- It is stored on the request log row (`feedback_key`, also sent with the record to [log destinations](/docs/features/observability/)) and on the request span (attribute `feedback_key`, in the database or the analytics store, whichever holds spans). It is never a usage tag, a metric label or an analytics dimension, and needs no entry in `usage_tags.allowed_values`. Browser apps may send it: it is in the built-in CORS request headers.
- A `join_key` matches only requests of the writer's team (and so of its organization): the same key in another team or organization is never joined. When several requests carried it, the result is written on each of the 100 newest and the answer is `{"data":[...]}`, one result per request; a key joins only rows of the team's current organization. With a client `id`, each result gets `<id>-<10 hex>` derived from its request (the first 117 characters of the `id` are kept), however many requests match, so a replay never duplicates.

Other fields: `metric_type` (or the older `data_type`), `value`, `string_value`, `value_json`, `assessment`, `status` (`ok`, `error`, `skipped`; an `error` needs `error: {"type", "message"}`), `status_reason`, `source` (`api` by default, or `feedback`, which needs `submitter`), `evaluator_id`, `evaluator_version`, `comment` (≤2000 characters, stored in clear), `reasoning` (≤8000 characters, stored encrypted and never echoed), `metadata` (≤4 KiB) and `id` (a client ID makes retries safe). A name that has a label (score configuration) is validated against it: its type, range or categories.

Send up to 1000 results in one call as `{"scores": [ … ]}`. The batch is validated whole before anything is stored; an invalid item answers 400 naming it (`scores[3]: …`).

## Read and edit results

The console session API, with `evals:read` to read and `evals:manage` to write, always within the session's teams:

| Method and path | Purpose |
| --- | --- |
| `GET /api/v1/admin/evaluations` | Results, newest first. Filters: `scope`, `trace_id`, `span_id`, `request_id` (up to 200, comma-separated), `session_id`, `name`, `source`, `assessment`, `status`, `evaluator_id`, `metric_type`, `join_key`, `run_id`, `ids`, `team_id`, `lens=feedback`, `include_invalid=true`. A value outside the set of `scope`, `source`, `assessment`, `status` or `metric_type` answers `400 invalid_request` with the set. `limit` 1–200 (50); page with the returned `next_cursor` |
| `GET /api/v1/admin/evaluations/{id}` | One result |
| `POST /api/v1/admin/evaluations` | A reviewer's result (`source: human`), with `team_id` and a target as above |
| `PATCH /api/v1/admin/evaluations/{id}` | Edit a result |
| `GET /api/v1/admin/evaluations/{id}/revisions` | The earlier values of an edited result |
| `GET /api/v1/admin/evaluations/backfill` | Progress of the migration of older scores |

`GET /api/v1/admin/evals/scores` keeps answering for one minor version with the same rows, a `Deprecation: true` header and a link to `/evaluations`. `GET /api/v1/admin/evals/evaluators` also lists, under `external`, the result names your applications send without an evaluator, with their scopes, sources and pass rate (`pass / (pass + fail)` over `ok` results).

### Edit a result

`GET` and `PATCH /api/v1/admin/evaluations/{id}` read and edit one result of the session's teams; another team's result answers 404.

```bash
PATCH /api/v1/admin/evaluations/score_6e00c3cc62819318f4ae5895
{"value": 0.5, "assessment": "fail", "reason": "too generous", "revision": 0}
```

Send any of `value`, `string_value`, `value_json`, `assessment`, `comment` and `valid`, with an optional `reason` (≤500 characters). The earlier values are kept as a revision, the result reads `edited: true` and the console marks it **edited** with its history, and the edit is in the audit log (`eval.result_edit`). Pass the `revision` you read to refuse an edit that raced another one (409 `revision_conflict`). `"valid": false` withdraws a result: it leaves lists and counts (read it with `include_invalid=true`) and its values stay in the history. A result produced again by the same evaluator on the same target (a resumed run, a rule judging again) replaces its value the same way and keeps the previous one as a revision, so a target never has two results of the same evaluator; a withdrawn result stays withdrawn.

## In the console

- **Request log:** each request shows chips for its results (name, value, pass in green, fail and **ERROR** in red, **SKIPPED** in amber, *edited*).
- **Trace drawer:** a span with results has an eval count in the tree; the span's panel lists its results with their source, scope, evaluator version, reason, reasoning (for readers with `content_sent:read`) and, for an edited result, its history.
- **Session:** filtering the request log by a session shows the session's results, on the session itself and on its requests.

Every view works at phone width: chips wrap under the request ID and lists stack.

## On spans and over OTLP

When you read a trace, each result appears as a `gen_ai.evaluation.result` event on the span it judged (its own span, else its request's span, else the trace's root), and the span gains `gateway.evaluation.count` and `gateway.evaluation.fail_count`. With an [OTLP trace exporter](/docs/features/observability/#logs-and-traces-otlp) configured, every stored or edited result with a trace is also exported as a short `evaluation <name>` span, a child of the span it judged (a trace result is a span of the trace without a parent), carrying the same event. Both use one bounded set of attributes:

`gen_ai.evaluation.name`, `gen_ai.evaluation.score.value` (numbers and booleans), `gen_ai.evaluation.score.label` (labels, at most 128 characters), `gateway.evaluation.id`, `gateway.evaluation.assessment`, `gateway.evaluation.status`, `gateway.evaluation.status_reason`, `gateway.evaluation.source`, `gateway.evaluation.scope`, `gateway.evaluation.metric_type`, `gateway.evaluation.evaluator.id`, `gateway.evaluation.evaluator.version`, `gateway.evaluation.revision`, `gateway.evaluation.valid` (only when false), plus `request.id` (empty for a trace result) and the identity attributes (`gateway.key.id`, `gateway.principal`, `gateway.team.id`, `gateway.organization.id`).

Text and JSON values, comments and reasoning never become attributes: they may hold what a person wrote. A session result has no trace and is not exported as a span. An edit exports the result again with its new `revision`. The exporter is bounded and never waits: a full queue drops and counts (`gateway_otel_dropped_total{signal="traces"}`).

## Where results are stored

Results follow the [span store engine](/docs/features/traces/#where-spans-are-stored):

- `spans.engine: database` (and whenever no analytics store is configured): every result is in PostgreSQL, in `gateway_eval_scores`, with its revisions in `gateway_eval_score_revisions`.
- `spans.engine: analytics_store`: results from judges, code evaluators, the API and feedback on a span, trace or session are written straight to the analytics store (`gateway_evaluation_results_v1`, a versioned ReplacingMergeTree, with `gateway_evaluation_revisions_v1`). Human results and experiment results stay in PostgreSQL, because annotated-trace retention, review queues, corrections and experiment runs read them there. A result in the database before the switch stays there and is still read and edited there, and an ID the analytics store holds stays in the analytics store; every read answers from both, each result once. If the analytics store cannot be read, results answer `503 analytics_store_unavailable`, never an empty list. Switching back to `spans.engine: database` stops reading the analytics store: results written there are no longer shown (as for spans); move back only after exporting them if you need them.

In both cases judge reasoning stays in PostgreSQL (`gateway_eval_reasoning`), encrypted with the provider encryption key and included in key re-encryption; an end-user or customer erasure removes their results and reasoning in both engines. With the analytics store engine, edits of one result are serialized within a replica; two replicas editing the same result at the same instant can both succeed: the later edit wins, and the history keeps the value both edits replaced, not the first edit's value. Pass `revision` and edit from one place when that matters.

## Limits

| Limit | Value |
| --- | --- |
| `value_json` | 8 KiB |
| `comment` / `reasoning` | 2000 / 8000 characters |
| `submitter`, `join_key` | 200 characters |
| Batch | 1000 results |
| List page | 200 results; `request_id` and `ids` filters 200 values |
| Results shown on one trace | 500; events on one span 20 (more are counted in `gateway.evaluation.events_dropped`) |
| Encrypted reasoning | the capture's retention for live judgements, 90 days otherwise (also for reasoning the migration moved); deleted with its result |

## Upgrade notes

- Migration 201 adds columns, constraints (`NOT VALID`) and tables only; no existing row is rewritten or scanned by it. The indexes and the background migration start when the flag is turned on.
- During a rolling upgrade an older replica keeps writing scores the old way; the migration converts them as it finds them.
- Source names change from `eval` and `annotation` to `llm`/`code` and `human`; filters by either name return both.
- Before downgrading, turn `evaluation_results` off: older versions ignore the new columns.
