compile_metric
Compile a metric into correct SQL with joins, filters, and time bucketing; use legal alternatives when a request is refused.
Instructions
Compile a metric to correct SQL (joins, filters, time bucketing).
group_by: comma-separated columns. On refusal the response lists
legal alternatives — retry with those or ask the user; do NOT
hand-assemble SQL for a refused request.
scd: "current" or "asof", required when the join path crosses a
history table. These are different questions — a customer's segment
now, or their segment when they ordered — so ask the user which they
meant rather than guessing.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"name": "<name>"
},
"name": "compile_metric"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| scd | No | `current` or `asof`. Required when the join path crosses a history table. | |
| name | Yes | A metric `name` exactly as `get_metrics` returned it. | |
| filter | No | An extra SQL predicate added to the WHERE clause, on top of the metric's own filters. | |
| dialect | No | The SQL dialect to compile to, by its sqlglot name: `duckdb`, `snowflake`, `bigquery`, `postgres`. | duckdb |
| calendar | No | `fiscal` or `calendar`. Required for quarter and year grains when the date dimension carries a verified fiscal calendar. | |
| group_by | No | Columns to group by, comma-separated. A refusal lists the legal alternatives. | |
| time_end | No | Exclusive upper bound on the metric's date column, as a date such as `2026-04-01`. | |
| time_grain | No | `day`, `week`, `month`, `quarter` or `year`. Omit for no time bucketing. | |
| time_start | No | Inclusive lower bound on the metric's date column, as a date such as `2026-01-01`. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |