Skip to main content
Query all your Laminar data directly with SQL. Find patterns, debug issues, and answer questions the dashboard doesn’t anticipate.

What You Can Query

Only SELECT queries are allowed.

Getting Started

Open the SQL Editor from the sidebar. Write a query:
Results appear in a table or raw JSON view. Export results to a dataset or labeling queue for further use. You can also query from outside the UI:
  • API: POST /v1/sql/query — authenticate with your project API key and pass { "query": "..." }.
  • CLI: lmnr-cli sql query "<query>" --json — see CLI.
  • MCP: connect an MCP client (Claude Code, Cursor, Codex) and call query_laminar_sql — see MCP Server.

Writing Queries

Laminar uses ClickHouse, a columnar analytics database. The basics work like standard SQL (SELECT, FROM, WHERE, GROUP BY, ORDER BY, LIMIT), with a few differences.

Always filter by time

Spans are ordered by start_time. Adding a time filter dramatically speeds up queries and prevents memory issues:

Avoid joins

ClickHouse isn’t optimized for joins. Instead, run two queries and combine results in your application:

Working with dates

Truncate timestamps for grouping with toStartOfInterval:
Works with any interval: INTERVAL 15 MINUTE, INTERVAL 1 HOUR, etc. Shortcuts exist for common intervals: toStartOfDay(value), toStartOfHour(value), toStartOfWeek(value).

Working with JSON

Many columns (like attributes) store JSON as strings. Use simpleJSONExtract* functions for fast extraction:
Check if a key exists with simpleJSONHas:
For complex operations (array indexing, nested paths), use JSONExtract* functions—more flexible but slower.

Working with tuples

Some columns store data as arrays of named tuples. The most common examples are:
  • spans.events: Array(Tuple(timestamp Int64, name String, attributes String))
  • evaluation_datapoints.trace_spans: Array(Tuple(name String, duration Float64, type String))
Use tupleElement(tuple, 'fieldName') to extract fields from tuples:
Use arrayExists to filter arrays by tuple field values:
Use ARRAY JOIN to unnest tuple arrays into separate rows:
Combine arrayMap and tupleElement for transformations:

Data types

Cast with CAST(value AS Type) or toDateTime64('2025-01-01 00:00:00', 9, 'UTC').

Table Schemas

These are the logical tables exposed in the SQL Editor. The schemas below reflect the columns available for queries.

spans

Path

Laminar span path is stored as an array of span names in span attributes. However, in SQL queries, it is stored as a string with items joined by a dot. For example, if the span path is ["outer", "inner"], the path column will be "outer.inner". If needed, you can still access the array value by reading attributes with simpleJSONExtractRaw(attributes, 'lmnr.span.path').

Parent span ID

If the current span is the top span of the trace, the parent_span_id will be a 0 UUID, i.e. "00000000-0000-0000-0000-000000000000".

Span type

Here are the values of the span_type column and their meanings:

Status

Status is normalized to "success" or "error".

Input and output

The input and output columns are stored as either raw strings or stringified JSON. The best way to parse them is to try to parse them as JSON, and if it fails, use the raw string. You can also use isValidJSON function right in the query to test for this. input and output columns are also indexed on content, so you can use them in WHERE conditions. Use ILIKE instead of LIKE, because the index is case-insensitive.

Attributes

The attributes column is stored as a string in JSON format. That is, you can safely JSON.parse / json.loads them. In addition, you can use JSON* and simpleJSON* functions on them right in the queries. Attributes are guaranteed to be a valid JSON object.

Model

The model column is set to the response model if present, otherwise it is set to the request model.

Tool definitions

tool_definitions holds the tool/function definitions made available to an LLM span, stored as stringified JSON. It is empty for spans without tools. Parse it as JSON, same rules as attributes.

Total tokens and total cost

Usually, total_tokens = input_tokens + output_tokens and total_cost = input_cost + output_cost. However, you can manually report these values using the relevant attributes. In this case, totals may not be equal to the sum of the input and output tokens and costs.

Tags

The tags column contains an array of string tags attached to spans. You can filter by tags using array functions:

Events

The events column contains an array of event tuples. Each event has:
  • timestamp (Int64): Unix nanoseconds
  • name (String): Event name
  • attributes (String): JSON attributes
To work with events, you can extract timestamps, filter by event name, or unnest events using arrayJoin:

traces

id is the trace ID; join to spans with spans.trace_id = traces.id.

Tags and trace_tags

tags is the union of all tags attached to any span inside the trace (inherited from span-level tagging). trace_tags is a separate set of tags applied directly to the trace itself (for example, from the trace-view UI or via updateTraceTags). The two columns are independent: a trace can have trace_tags without any span-level tags, and vice versa.

Span names

span_names is the de-duplicated list of span names produced anywhere in the trace. Useful for filtering traces that contain (or don’t contain) a specific operation: has(span_names, 'tool.search').

Root span input and output

root_span_input and root_span_output mirror the input and output of the trace’s top span. Same parsing rules apply as span input/output: try to parse as JSON, fall back to raw string.

Trace type

Here are the values of the trace_type column and their meanings:

Duration

The duration is in seconds, and is calculated as end_time - start_time.

Status

Status is set to error if any span in the trace has status error, otherwise it is success.

Metadata

Metadata is stored as a string in JSON format. That is, you can safely JSON.parse / json.loads it. In addition, you can use JSON* and simpleJSON* functions on it right in the queries. Metadata is guaranteed to be a valid JSON object.

signal_events

Payload

The payload column is stored as a string in JSON format. That is, you can safely JSON.parse / json.loads it. In addition, you can use JSON* and simpleJSON* functions on it right in the queries. Payload is guaranteed to be a valid JSON object.

Severity

severity is a numeric level matching the alert thresholds: 0 (INFO), 1 (WARNING), 2 (CRITICAL).

Summary

summary is a short, human-readable description of the event produced by the Signal. It may be empty for older events.

Clusters

clusters is the list of cluster IDs this event belongs to (see Clusters). Only non-L0 clusters are included.

signal_events_all

Same schema as signal_events, but the clusters column includes L0-cluster membership as well. Use this when you need to resolve or list events that belong to an L0 cluster; use signal_events for everything else.

signal_runs

Status

status is one of "PENDING", "COMPLETED", "FAILED", or "UNKNOWN".

Mode

mode is one of "BATCH" (historical backfill job) or "REALTIME" (live trigger against a new trace).

clusters

Clusters group similar signal events into a hierarchy (see Clusters). Each row is one cluster. L0 (lowest-level) clusters are excluded.

Level

level is the cluster’s position in the hierarchy. Leaf-level (L0) clusters are excluded from this table; level is always greater than 0.

event_clusters_all

Maps individual signal events to the clusters they belong to, including L0 clusters. One row per (event, cluster) pair.

logs

Attributes

The attributes column is stored as a string in JSON format. That is, you can safely JSON.parse / json.loads it. In addition, you can use JSON* and simpleJSON* functions on it right in the queries. Attributes are guaranteed to be a valid JSON object.

evaluation_datapoints

data, target, metadata, executor_output, scores, and trace_metadata are JSON stored as strings. scores is a JSON object of string keys to numeric values. When the datapoint is not sourced from a dataset, dataset_id and dataset_datapoint_id are a nil UUID (all zeroes) and dataset_datapoint_created_at is the Unix epoch. The trace-related columns (duration, input_cost, output_cost, total_cost, start_time, end_time, input_tokens, output_tokens, total_tokens, trace_status, trace_metadata, trace_tags, trace_spans, top_span_id) are joined from the associated trace. If no trace exists for the datapoint, these columns will be nil/empty/zero.

dataset_datapoints

data, target, and metadata are JSON stored as strings.

dataset_datapoint_versions

Same schema as dataset_datapoints, but includes all versions and history for each datapoint.

Example Queries

Cost breakdown by model:
Slowest operations:
Error rate by span type:
Find spans with specific tags:
Count events by type:
Find cache hit rate from events:
Average cost per evaluation datapoint:
Find evaluation datapoints with specific span types:
Count span types across evaluation datapoints:

Exporting Results

Select results and click “Export to Dataset.” Map columns to dataset fields (data, target, metadata). Use this to build evaluation datasets from query results.

Full Reference

For complete ClickHouse SQL syntax, see the ClickHouse documentation.