Applies to:
- Plan -
- Deployment -
Summary
Goal: Query sibling traces by shared metadata fields to reconstruct multi-turn agent conversations inside a custom scorer. Features: SQL queries via the/btql API endpoint, metadata.thread_id filtering, subfield indexing, trace-scope scoring helpers.
Configuration steps
Step 1: Choose a tracing model
Two patterns are supported. Single-trace is preferred when possible. Option A — Single trace per conversation (recommended) Model each conversation as one Braintrust trace with multiple spans (one per turn). Usespan.export() to continue the same trace across turns. Trace-scope helpers then work without any cross-trace queries.
metadata.thread_id and query them with SQL.
Step 2: Set metadata.thread_id on every trace
Step 3: Query sibling traces via SQL inside a scorer
Custom Python scorers receiveBRAINTRUST_API_KEY automatically. Use it to call /btql.
Always bound the query with a time window and LIMIT to control latency and cost.
BRAINTRUST_API_URL to https://api-eu.braintrust.dev. For self-hosted deployments, set it to your Braintrust data-plane URL.
Step 4: Enable subfield indexing on metadata.thread_id
If metadata.thread_id is high-cardinality and queried frequently, enable subfield indexing in your project settings. This reduces lookup latency for that specific filter. Still pair with a time range and LIMIT — indexing speeds up lookups but doesn’t eliminate duplicated scorer work.