Skip to Content
Judgment Labs
Judgment Agent

SQL schema

The tables and columns you can query with Judgment's virtual SQL (vsql).

Judgment's virtual SQL (vsql) is a fixed set of read-only tables over your project's data. You query them with sql_query over MCP, with the Judgment Agent, or with client.sql() in the SDK. For how to run queries and worked examples, see Query with SQL.

Rules

RuleValue
StatementsOne read-only SELECT per request. Writes and other statements are rejected.
DialectClickHouse SQL functions and syntax.
Query text1 to 50,000 characters, with at least one non-whitespace character.
Result sizeAt most 10,000 rows and 25 MiB. Exceeding either cap returns an error.
ScopeThe server applies your organization and project. SQL can't read another project.
MemoryQueries run with a 2 GiB memory limit. On QUERY_MEMORY_LIMIT, narrow the time range or select fewer columns.
Environmentsenvironment_name is '' for traces with no environment. Omit the filter to include all environments.

LIMIT caps the rows returned, not the rows scanned. Filter on started_at or on IDs to keep queries fast.

The same reference is available as Markdown from MCP discover_schema, Python client.discover_schema(), TypeScript client.discoverSchema(), and GET /v1/sql/schema.

API and SQL names still say behavior; it means label. config.behaviors holds the labels each judge can apply, and telemetry.scores.behavior_id_at_evaluation records which label a judge applied. New judges are categorical; binary and numeric scores come from older judges.

evaluations.runs and evaluations.items hold test runs started from a test config over a dataset. Test suite runs aren't in these tables.

Conversation execution details

Conversation timelines contain model calls and conversation items. Additional execution details can be recorded as spans; the timeline does not include an availability flag. Use the existing sql_query tool to fetch these details when needed.

First read trace_id, span_id, and response_id from conversations.observations for the selected conversation and observation IDs. Read the tool's call_id from conversations.items or conversations.timeline. For a tool call, restrict the span query to those trace IDs and its call ID:

SELECT trace_id, span_id, span_name, status, duration_ms
FROM telemetry.spans
WHERE trace_id IN ('trace-id')
  AND attributes['judgment.tool_call_id'] = 'call-id'
ORDER BY started_at, trace_id, span_id
LIMIT 40

For a model response, filter by response ID:

SELECT trace_id, span_id, span_name, status, duration_ms
FROM telemetry.spans
WHERE trace_id IN ('trace-id')
  AND attributes['judgment.response_id'] = 'response-id'
ORDER BY started_at, trace_id, span_id
LIMIT 40

The association IDs are normalized on ingestion, so use exact equality. Provider-specific helper IDs are handled by the built-in mappers. Previously stored spans without these associations will not match.

Read metadata first, then fetch input, output, or attribute windows for selected spans. Page capped results before concluding a span is absent. Missing matches can mean no instrumentation, delayed ingestion, or expired data. Spans in an unreferenced trace will not appear in this bounded lookup.

Project-scoped SQL, including the platform agent’s SQL tool, can retrieve related execution spans. Conversation-scoped judges cannot query telemetry tables. They evaluate using the existing conversation data, so additional execution details attached to model or tool calls are unavailable to them.

Patterns

You wantDo this
SessionsThere is no sessions table. Group telemetry.traces by session_id.
Cost and tokensSum cost_usd and token columns on telemetry.spans before joining to scores or tags, so rows aren't counted twice.
A dataset version Nversion_added <= N AND (version_removed IS NULL OR version_removed > N) on datasets.examples.
Stable pagingOrder by a unique tie-breaker, for example ORDER BY started_at DESC, trace_id DESC, and continue from the last row.
Large attributesRead a window with substringUTF8(attributes['key'], 1, 2000) and get the full length with lengthUTF8.

Tables

Judgment SQL (telemetry.v1)

One read-only SELECT against these virtual tables; host supplies org/project scope; SQL cannot override it.

Memory: prefer narrow time ranges or trace/span IDs and only needed fields. Small LIMITs help inspection but do not bound scan, grouping, sort or join memory. Run broad scans sequentially. On QUERY_MEMORY_LIMIT, narrow scope or simplify before retrying. ClickHouse types: wrap nullable columns before JSON/array functions, e.g. JSONExtractArrayRaw(ifNull(output, ''), 'key'); write timestamps in full, e.g. started_at >= '2026-09-16 06:00:00', or use parseDateTime64BestEffort('2026-09-16T06:00:00Z', 6, 'UTC') for ISO. Correlated subqueries are unsupported; JOIN a grouped subquery instead.

telemetry.traces

One latest root record per trace_id

ColumnTypeDescription
trace_idStringTrace identifier
root_span_idStringRoot span identifier
session_idNullable(String)Session identifier
started_atDateTime64(6)Root span start in UTC
ended_atNullable(DateTime64(6))Root span end in UTC
duration_msNullable(Float64)Root duration in milliseconds
trace_nameStringRoot span name
statusStringunset, ok, or error
error_messageNullable(String)Root error text
inputNullable(String)Root input
outputNullable(String)Root output
customer_idNullable(String)Customer identifier
customer_user_idNullable(String)Customer user identifier
service_nameNullable(String)OTEL service name
agent_versionNullable(String)Agent version
attributesMap(String, String)Span attributes
resource_attributesMap(String, String)OTEL resource attributes
environment_nameStringRoot environment; '' = no environment

telemetry.spans

One latest record per (trace_id, span_id)

ColumnTypeDescription
trace_idStringTrace identifier
span_idStringSpan identifier
parent_span_idNullable(String)Parent span identifier
session_idNullable(String)Session identifier
started_atDateTime64(6)Span start in UTC
ended_atNullable(DateTime64(6))Span end in UTC
duration_msNullable(Float64)Duration in milliseconds
span_nameStringSpan name
span_kindStringOTEL span kind
service_nameNullable(String)OTEL service name
statusStringunset, ok, or error
error_messageNullable(String)Span error text
inputNullable(String)Span input
outputNullable(String)Span output
customer_idNullable(String)Customer identifier
customer_user_idNullable(String)Customer user identifier
agent_versionNullable(String)Agent version
modelNullable(String)Model name
llm_providerNullable(String)LLM provider
cost_usdFloat64Span cost; zero when unreported
non_cached_input_tokensUInt64Non-cached input tokens; zero when unreported
cache_read_input_tokensUInt64Cache-read input tokens; zero when unreported
cache_creation_input_tokensUInt64Cache-creation input tokens; zero when unreported
output_tokensUInt64Output tokens; zero when unreported
tool_statusNullable(String)Tool outcome from judgment.tool.status
tool_error_codeNullable(String)Tool error code from judgment.tool.error_code
attributesMap(String, String)Span attributes
resource_attributesMap(String, String)OTEL resource attributes
trace_stateNullable(String)OTEL trace state
link_target_trace_idNullable(String)Linked target trace identifier
link_target_span_idNullable(String)Linked target span identifier
link_source_trace_idNullable(String)Linked source trace identifier
link_source_span_idNullable(String)Linked source span identifier
events_jsonStringOrdered span events as JSON with Timestamp, Name, and Attributes; [] when empty
environment_nameStringSpan environment; '' = no environment

telemetry.scores

Current score results, selected independently by source

ColumnTypeDescription
score_idStringEvaluation result identifier
sourceStringjudgment or customer
evaluated_atDateTime64(6)Scored trace start (UTC), not when scored
evaluation_scopeStringspan, trace, session, or unknown
trace_idNullable(String)Evaluated trace identifier
span_idNullable(String)Associated span identifier; null when no span is recorded
session_idNullable(String)Evaluated session identifier
evaluation_trace_countNullable(UInt32)Number of traces included in a session evaluation; null when unreported
judge_idStringStable judge identifier
judge_name_at_evaluationStringHistorical judge name
judge_type_at_evaluationStringHistorical judge type
judge_major_versionUInt32Historical major version
judge_minor_versionUInt32Historical minor version
score_typeStringnumeric, binary, or categorical
numeric_valueNullable(Float64)Numeric score
boolean_valueNullable(Bool)Binary score
categorical_valueNullable(String)Categorical score
value_textNullable(String)Normalized score text
behavior_id_at_evaluationNullable(String)Label identifier at evaluation time
reason_jsonNullable(String)Evaluation reason JSON
error_messageNullable(String)Evaluation error
customer_idNullable(String)Customer identifier
customer_user_idNullable(String)Customer user identifier
environment_nameStringSource trace environment; '' = no environment

telemetry.trace_tags

One tag assignment per (trace_id, tag)

ColumnTypeDescription
trace_idStringTagged trace identifier
tagStringTag value
created_atDateTime64(6)Assignment time in UTC

telemetry.judge_reviews

Latest human review per judge and trace

ColumnTypeDescription
judge_idStringJudge
trace_idStringReviewed trace
reviewed_atDateTime64(6)UTC
agreementBoolReviewer agreed
judge_labelStringJudge's label
human_labelStringCorrect label
commentStringReason

telemetry.alerts

One alert generated by an automation rule

ColumnTypeDescription
alert_idStringAlert identifier
trace_idStringTriggering trace identifier
rule_idStringAutomation rule identifier
rule_nameStringRule name at alert time
created_atDateTime64(6)Alert creation time in UTC
combine_typeStringRule condition combination type
notification_sentBoolWhether notification delivery was claimed
conditions_result_jsonStringRule condition results as JSON
metadata_jsonStringAlert metadata as JSON
environment_nameStringSource trace environment; '' = no environment

telemetry.model_usage

LLM usage per bucket, environment, and model; bucket width follows the request window: minute ≤150h, hour ≤3600h, else day (hour with no window)

ColumnTypeDescription
bucketDateTime64(6)Bucket start in UTC
environment_nameStringEnvironment; '' = none
modelStringModel; 'unknown' when unreported
cost_usdFloat64Total cost
non_cached_input_tokensUInt64Non-cached input tokens
cache_read_input_tokensUInt64Cache read input tokens
cache_creation_input_tokensUInt64Cache creation input tokens
output_tokensUInt64Output tokens
llm_callsUInt64LLM span count

telemetry.latency

Average duration per bucket, kind, and name across environments; buckets as in telemetry.model_usage. Per environment: use telemetry.spans

ColumnTypeDescription
bucketDateTime64(6)Bucket start in UTC
kindStringtrace (root spans), llm, or tool
nameStringRoot span name, model, or tool span name
avg_duration_msFloat64Average ms; averaging across buckets weights buckets equally

evaluations.runs

One legacy test-config run; test-suite results aren't in SQL

ColumnTypeDescription
run_idStringEvaluation run identifier
test_config_idStringTest configuration identifier
nameStringRun name
dataset_idStringEvaluated dataset identifier
dataset_version_idStringEvaluated dataset version identifier
statusStringCurrent run status
sourceStringRun initiation source
created_atDateTime64(6)Creation time in UTC
started_atNullable(DateTime64(6))Start time in UTC
completed_atNullable(DateTime64(6))Completion time in UTC
error_messageNullable(String)Run failure message

evaluations.items

Legacy test-config result per run, example, judge, judge version; not test suites

ColumnTypeDescription
run_idStringEvaluation run identifier
dataset_idStringEvaluated dataset identifier
dataset_version_idStringEvaluated dataset version identifier
example_idStringEvaluated example identifier
offline_trace_idNullable(String)Agent execution trace identifier
evaluated_atDateTime64(6)Evaluation time in UTC
judge_idStringStable judge identifier
judge_major_versionUInt32Judge major version
judge_minor_versionUInt32Judge minor version
score_typeStringnumeric, binary, or categorical
numeric_valueNullable(Float64)Numeric score
boolean_valueNullable(Bool)Binary score
categorical_valueNullable(String)Categorical score
value_textNullable(String)Normalized score text
reason_jsonNullable(String)Evaluation reason JSON
metadata_jsonNullable(String)Evaluation metadata JSON
successNullable(Bool)Optional test pass-condition result
error_messageNullable(String)Scorer error

datasets.datasets

One current dataset

ColumnTypeDescription
dataset_idStringDataset identifier
nameStringDataset name
current_versionUInt32Current version number
created_atDateTime64(6)Creation time in UTC
updated_atDateTime64(6)Last update time in UTC
schema_jsonNullable(String)Dataset schema as JSON

datasets.examples

One dataset membership per example, including its version interval

ColumnTypeDescription
dataset_idStringDataset identifier
example_idStringExample identifier
added_atDateTime64(6)Time added to the dataset in UTC
example_created_atDateTime64(6)Example creation time in UTC
version_addedUInt32First dataset version containing the example
version_removedNullable(UInt32)First version excluding the example
data_jsonStringExample data as JSON
metadata_jsonStringUser metadata as JSON
managed_metadata_jsonStringJudgment-managed metadata as JSON

config.judges

One judge with a production version per judge_id

ColumnTypeDescription
judge_idStringStable judge identifier
nameStringCurrent judge name
descriptionNullable(String)Current description
judge_typeStringJudge implementation type
score_typeStringJudge score type
evaluation_modeStringProduction version evaluation mode

config.behaviors

One current label definition per behavior_id

ColumnTypeDescription
behavior_idStringStable label identifier
judge_idStringOwning judge identifier
value_textStringLabel value
descriptionNullable(String)Label description
created_atDateTime64(6)Creation time in UTC
judge_nameStringCurrent judge name for this label
categories_jsonStringCurrent categories as JSON with id, name, and color, ordered by id; [] when none

Examples

Session timing and usage

WITH session_roots AS (
  SELECT session_id, min(started_at) AS started_at, max(ended_at) AS ended_at,
         count() AS trace_count
  FROM telemetry.traces
  WHERE session_id IS NOT NULL
  GROUP BY session_id
), session_usage AS (
  SELECT session_id, sum(cost_usd) AS cost_usd,
         sum(non_cached_input_tokens + cache_read_input_tokens + cache_creation_input_tokens) AS input_tokens,
         sum(output_tokens) AS output_tokens
  FROM telemetry.spans
  WHERE session_id IS NOT NULL
  GROUP BY session_id
)
SELECT r.session_id, r.trace_count, r.started_at, r.ended_at,
       dateDiff('microsecond', r.started_at, r.ended_at) / 1000.0 AS elapsed_ms,
       coalesce(u.cost_usd, 0) AS cost_usd,
       coalesce(u.input_tokens, 0) AS input_tokens,
       coalesce(u.output_tokens, 0) AS output_tokens
FROM session_roots AS r
LEFT JOIN session_usage AS u USING (session_id)
ORDER BY r.started_at DESC, r.session_id DESC
LIMIT 50

Current example counts by dataset

SELECT d.dataset_id, d.name, countIf(e.example_id IS NOT NULL AND e.version_removed IS NULL) AS current_examples
FROM datasets.datasets AS d
LEFT JOIN datasets.examples AS e USING (dataset_id)
GROUP BY d.dataset_id, d.name
ORDER BY current_examples DESC
LIMIT 50

On this page