What You Can Query
Only
SELECT queries are allowed.
Getting Started
Open the SQL Editor from the sidebar. Write a query:/v1/sql/query—authenticate with your project API key and pass { "query": "..." }.
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 bystart_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 withtoStartOfInterval:
INTERVAL 15 MINUTE, INTERVAL 1 HOUR, etc.
Shortcuts exist for common intervals: toStartOfDay(value), toStartOfHour(value), toStartOfWeek(value).
Working with JSON
Many columns (likeattributes) store JSON as strings. Use simpleJSONExtract* functions for fast extraction:
simpleJSONHas:
JSONExtract* functions—more flexible but slower.
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, theparent_span_id will be a 0 UUID, i.e. "00000000-0000-0000-0000-000000000000".
Span type
Here are the values of thespan_type column and their meanings:
Status
Status is normalized to"success" or "error".
Input and output
Theinput 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
Theattributes 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
Themodel column is set to the response model if present, otherwise it is set to the request model.
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.
traces
id is the trace ID; join to spans with spans.trace_id = traces.id.
Trace type
Here are the values of thetrace_type column and their meanings:
Duration
The duration is in seconds, and is calculated asend_time - start_time.
Status
Status is set toerror 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 safelyJSON.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.
events
Attributes
Theattributes 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.
Source
source is either "CODE" or "SEMANTIC".
tags
Source
source is "HUMAN" (set in the Laminar UI), "CODE" (attached from code), or "UNKNOWN".
evaluation_datapoints
data, target, metadata, executor_output, and scores 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.
dataset_datapoints
data, target, and metadata are JSON stored as strings.
dataset_datapoint_versions
Same schema asdataset_datapoints, but includes all versions and history for each datapoint.
Example Queries
Cost breakdown by model: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.
