Skip to main content
Applies to:
  • Plan - Any
  • Deployment - Any
  • Use case - A custom scorer returns metadata, and you want that data on the span being scored so you can filter, group, or chart it.

Summary

When a scorer returns metadata, Braintrust logs it on the scorer’s own span. It isn’t merged into the metadata of the span being scored. To attach categorical values to the scored span, use a classifier. To attach other values, log them as metadata from your application or eval task.

What is happening

Every scorer run creates its own scorer span in the trace it scores. Where the returned metadata ends up on that scorer span depends on how the scorer runs:
  • Online scoring rules: The scorer span’s output holds the scorer’s full return value, so returned metadata appears at output.metadata on the scorer span.
  • Experiments run with Eval(): The TypeScript and Python SDKs log the returned metadata to the scorer span’s top-level metadata field and the remaining score fields to its output.
In both cases, the metadata stays on the scorer span. An online scoring rule writes only the score values to the span being scored, under scores. See View scoring results for where scorer spans appear in the trace. Classifiers work differently. Each classification has an id, an optional label, and optional metadata. Braintrust writes the classification, including its metadata, to the scored span’s classifications field. In the logs and experiments tables, each classifier appears as its own column under a classifications. prefix that you can sort and filter.

Solutions

Option 1: Return a classification instead of a score

Use a classifier when the value you want to attach is a category, such as an intent, a bucket, or a pass reason. A custom code classifier can return any id your logic computes, plus metadata with supporting values.
Braintrust stores classifier results in an array under classifications.length_bucket on the scored span, even when the classifier returns one result. The first result’s metadata is at classifications.length_bucket[0].metadata. For production traces, select a saved classifier in an online scoring rule the same way you select a scorer. You can build an LLM-as-a-judge classifier in the UI, or follow Apply classification labels to write a custom code classifier. Classifiers require TypeScript SDK v3.9.0 or later, or Python SDK v0.16.0 or later. See Classifiers for other SDKs.

Option 2: Log the values as metadata on the span itself

If you can compute the value in your application or eval task, log it directly as metadata on the span instead of returning it from a scorer. Filters and aggregations on top-level metadata fields are more efficient than on values nested in input or output. See Add metadata and tags. In an Eval() task, add fields to hooks.metadata. The SDK logs them as the eval row’s top-level metadata.
In production logging, log metadata on the span that does the work, for example with span.log({ metadata: { ... } }) in TypeScript or span.log(metadata={...}) in Python. See Wrap a custom LLM client for an example of logging metadata on a span.

How to confirm it worked

  • For a classifier, open a scored trace and confirm the scored span shows the classification under classifications. In the logs or experiments table, confirm the classifier’s classifications. column appears and can be filtered.
  • For logged metadata, open the span and confirm the fields appear under its top-level metadata.
  • To read metadata that a scorer already returned, open the scorer span in the trace. Check output.metadata for online scoring rules, or metadata for Eval() runs.

Notes

  • Scorer spans have span_attributes.purpose set to 'scorer'. Use this to select scorer spans when you query scorer output with SQL.
  • An online scoring rule writes only scores or classifications to the span being scored. It doesn’t update that span’s metadata. Use a classifier for values that must come from the scoring step.
  • To query classification fields with SQL, see Query by classifications.