estimate_query_cost
Estimate a SQL query's cost before execution to avoid expensive runs. Returns a dollar figure with an accuracy tier (PRECISE, UPPER_BOUND, or HEURISTIC).
Instructions
Estimate the cost of a SQL query before running it. ALWAYS call this before running an expensive-looking query. The response's accuracy_tier tells you how much to trust the number: PRECISE (exact), UPPER_BOUND (real cap, may overstate), HEURISTIC (rough). Accepts exactly one SQL statement per call (a single trailing ';' is fine) - text with more statements is refused before anything is estimated. This tool accepts only read statements (first keyword SELECT, WITH, VALUES, SHOW, DESCRIBE, DESC or EXPLAIN; a WITH must lead to a SELECT or VALUES) - others are refused before anything is estimated. Operator opt-out: COST_GUARD_ALLOW_WRITE_STATEMENTS=1.
warehouse_size (Snowflake/Databricks only, e.g. "SMALL", "X-Large") and edition
(Snowflake only, e.g. "enterprise") can only raise the estimate: the dollar figure is
priced at the warehouse the query is pinned to as the server observes it (its size, type
and generation) and at the operator-configured edition, whichever is higher. Warehouse
types without a modelled rate (Snowpark-optimized, Databricks Classic/Pro) get no dollar
figure.
Compute disclosure: on Snowflake and Databricks the EXPLAIN and the warehouse/history
metadata lookups run on the named (or default/configured) warehouse session, which could
resume a suspended or start a stopped warehouse and bill compute. By default the server
reads the warehouse's state first (Snowflake: the SHOW WAREHOUSES row, after USE WAREHOUSE,
EXPLAIN USING JSON and SELECT CURRENT_WAREHOUSE() when no warehouse argument names one;
Databricks: a control-plane GET through the Warehouses API, before any session): on a
Snowflake warehouse that is not STARTED the cloud-provider (SELECT CURRENT_REGION()) and
query-history lookups are skipped and the estimate says so in a caveat (Gen1 rates,
heuristic runtime; the query-history lookup is also skipped when no warehouse argument is
given); on a Databricks warehouse that is not RUNNING, or whose state cannot be read, no
session is opened and the estimate carries no byte or dollar figure. Operator opt-ins:
COST_GUARD_SNOWFLAKE_ALLOW_WAREHOUSE_RESUME=true,
COST_GUARD_DATABRICKS_ALLOW_WAREHOUSE_START=true. run_query_bounded is not gated.Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sql | Yes | ||
| engine | Yes | ||
| edition | No | ||
| warehouse | No | ||
| warehouse_size | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| engine | Yes | ||
| caveats | No | ||
| currency | No | USD | |
| accuracy_tier | Yes | ||
| estimated_bytes | No | ||
| estimated_cost_usd | No |