Use the SQL editor’s current schema when authoring a query. The examples below assume the tables and columns are present in your workspace’s schema.
Create and inspect the schema
- Open Metrics > New Metric and choose Custom SQL from the available types.
- Give the metric a descriptive name.
- Click View schema in the SQL editor. Inspect the current tables, column types, enum values, and sample data before writing the query.
- Choose the aggregation and output unit, test the draft, and save the metric.
Return timestamped values
Return only these columns, using exact aliases:
Extra columns, duplicate column names, missing required columns, and nonnumeric values or offsets are rejected. Use aliases for computed expressions and avoid
SELECT *. Offsets determine where subvalues appear on the timeline; they do not set the unit of value.
For example, measure each transcript message’s duration in seconds:
Choose an aggregation
Rows with
value = NULL contribute neither a timeline subvalue nor an aggregate value. If the query returns no rows, Count reports 0; the other methods are skipped as not applicable. If it returns rows but every value is null, the other methods report a query error. Use COALESCE only when substituting a number reflects the intended measurement.
Choose a supported output unit such as seconds, milliseconds, count, ratio, percent, tokens, or unitless. Keep the query’s arithmetic consistent with that unit. For example, a percentage query should calculate a percentage, rather than return a 0–1 ratio labeled as percent.
Test before saving
Click Test Metric in the SQL editor to evaluate the draft query, aggregation, and unit on up to 10 recent eligible simulations in the current workspace. Inspect each result’s row count, aggregate value, timeline subvalues, and errors. This draft test does not require saving the metric first. Each tested conversation can return at most 1,000 rows. A larger result is rejected rather than silently aggregated as a partial sample. Filter, aggregate, or carefully limit the query, and check that any limit still answers your measurement question. A bounded interactive request can time out; simplify the query or retry when the data is ready. Test a conversation with matching data, one without matches, and one with a known expected value. Where available, Ask Sofia can help draft a query from the schema and your measurement goal. Review the generated SQL and its test results before saving it. After saving, select the metric for an evaluation with the necessary structured data. Test Metric on a saved metric is separate from the SQL editor’s bounded draft test.Query restrictions and missing data
- Use read-only SQL beginning with
SELECTorWITH; data-changing statements are unsupported. - Query the tables and columns shown in the schema panel. This is a conversation-data measurement surface, not general database access.
- Keep the result to the timestamp/value contract above. Compute supporting columns inside a subquery when needed, then return only the supported aliases.
- A query error, unavailable data, and a valid empty result have different meanings. Inspect the test message before changing the query or treating the score as zero.