Query Cost Estimation: By Hand vs With an AI Agent
The manual pre-flight workflow, what an agent takes over, and what still needs a human approval
Estimating a query's cost by hand means compiling it without running it (a BigQuery dry run or a Snowflake EXPLAIN), reading the bytes it would touch, converting that to money, and comparing the result to a budget. An agent can do the same steps before every run and stop the expensive ones. This guide lays out both paths so you can decide which parts to hand over.
Key Takeaways
- •Both major warehouses expose a free pre-flight: BigQuery states that dry runs are not charged, and Snowflake EXPLAIN compiles a statement without needing a running warehouse.
- •Pre-flight numbers are estimates, not quotes. Snowflake documents its EXPLAIN byte figures as upper-bound estimates, and BigQuery dry runs on row-level-secured tables return 0 bytes.
- •The manual workflow breaks at the handoffs: nobody runs the estimate consistently, and nobody compares it to a budget in the same moment.
- •An agent running the dw-query-cost-estimation skill estimates cost before execution and gates expensive runs against budget context. Raising the budget stays a human decision.
- •Evaluate any agent for this job on three things: estimate accuracy against actual bills, what it does when it cannot estimate, and who can override a block.
The job, and who does it today
The job is simple to state: before a query runs, know roughly what it will cost, and refuse to run it if it breaks a budget. In practice the work is spread across people. An analyst writes the query, an analytics engineer reviews the model, and a platform or FinOps owner watches the monthly bill. Each holds a piece of the picture, and none holds all of it at the moment the query is submitted.
Most teams handle this informally. A few engineers know which tables are huge and warn colleagues in chat. Scheduled jobs get a review when they are first written and never again, even when the underlying table grows. The cost shows up weeks later in a billing report, long after the person who wrote the query has moved on to something else.
The gap is timing. Billing data is accurate but late. Estimates are early but only useful if somebody actually produces and reads them. That is the job an agent can take over: producing the early number every time, with the budget context already attached.
The manual workflow, step by step
The manual path has five steps. First, compile the query without executing it. On BigQuery, a dry run does this; the docs say that dry runs do not use query slots and that you are not charged for performing one, and they report the approximate bytes processed in capacity mode. On Snowflake, the docs say EXPLAIN compiles the statement but does not execute it, so it does not require a running warehouse.
Second, read the plan. Snowflake's EXPLAIN output includes partitionsAssigned and bytesAssigned, which are the partitions and bytes left after compile-time pruning. Third, translate that into money. BigQuery's on-demand pricing is driven by bytes processed, so the conversion is arithmetic. Snowflake bills compute by warehouse time, so bytes only suggest cost indirectly and you have to reason about warehouse size and runtime.
Fourth, compare the number to a budget, which usually lives in a spreadsheet, a wiki page or someone's head. Fifth, decide: run it, rewrite it, or ask for approval. Each step is easy alone. The trouble is that five steps across several tools and people rarely happen for every query.
Where the manual workflow breaks
It breaks first on consistency. A dry run is free, but it is optional, so it gets skipped under deadline pressure and for queries that look harmless. The queries that hurt are often the ones that looked harmless: a missing partition filter, a join that fans out, a scheduled job pointed at a table that grew.
It breaks second on accuracy. The Snowflake docs describe the assigned partition and byte values as upper-bound estimates, because runtime optimizations such as join pruning can reduce what is actually scanned. The BigQuery docs warn that dry runs on tables masked by row-level security always return 0 bytes. A person reading a 0 may conclude the query is free. The estimate is only as trustworthy as the reader's knowledge of its limits.
It breaks third on warehouse mechanics that bytes do not capture. Snowflake bills warehouse credits per second with a 60-second minimum each time a warehouse starts or resumes. A cheap query that wakes an idle warehouse repeatedly can cost more than its scan size implies, and no EXPLAIN plan will say so.
It breaks last on the budget handoff. Even a correct estimate does nothing if the budget is in a different system from the query editor. The number gets produced, shrugged at, and the query runs.
What an agent does instead
The dw-query-cost-estimation skill, run by our Cost Agent, is described in one line: estimate a query's cost before execution and gate expensive runs against budget context. We keep the description that narrow on purpose. The agent does not rewrite your warehouse or change its settings as part of this skill.
Concretely, that means the pre-flight step is no longer optional. The estimate is produced before the query executes, the result is compared with the budget context the agent holds, and a query that exceeds it is held instead of run. The engineer sees a reason and a number, not a bill three weeks later.
Because the agent is an MCP server, it is reachable from the tools engineers already use, such as Claude Code or Cursor, through the Model Context Protocol. A question like How much are we spending on Snowflake this month? and a pre-run check on a specific query go through the same interface. Our own pilot data on this skill is limited, so we do not quote a savings figure here.
Manual versus agent, side by side
| Step | By hand | With the agent |
|---|---|---|
| Produce the estimate | Run a dry run or EXPLAIN when someone remembers | Runs before execution as part of the flow |
| Interpret the result | Reader must know the limits, such as upper bounds and 0-byte masked tables | Limits are handled in the skill, and unknowns are flagged instead of read as zero |
| Compare to budget | Spreadsheet, wiki or memory | Budget context is held alongside the estimate |
| Decide | Individual judgment under deadline | Expensive runs are gated; the reason is shown |
| Override | Informal, often unrecorded | Human approval, with a record |
| Effort | Small per query, large in aggregate and easy to skip | Effort moves from running checks to reviewing exceptions |
What still needs a human approval
An agent that can block a query needs a clear rule about who can unblock one. We recommend that the agent may estimate and hold on its own, but that overriding a hold, raising a budget, or approving a one-off expensive run belongs to a named person. A legitimate quarterly backfill will look expensive, and the agent should not decide for you that it is worth it.
Humans also own the budget itself. Budgets reflect business priorities that no estimate can infer: a launch week, a migration, a finance-mandated cap. The agent enforces the number it is given. Choosing the number is a management call, and changing it should leave a trail.
Finally, humans own the unknowns. When the agent cannot produce a reliable estimate, for example on a masked table where a dry run returns 0, the safe behavior is to say so and ask, not to proceed on a false zero. Make sure that behavior is what you get.
How to evaluate an agent for this job
- •Accuracy: ask it to estimate a sample of past queries, then compare to what they actually cost. Look at the misses, not the average.
- •Failure mode: test a table where estimates are known to be unreliable, such as row-level-secured data, and check that it flags the gap rather than reporting zero.
- •Gate behavior: confirm that a blocked query shows the estimate, the budget and the reason, and that the override path requires a named approver.
- •Scope: check that the skill only estimates and gates. An agent that also changes warehouse settings needs a separate permission review.
- •Audit: confirm every estimate, block and override is logged so finance can reconstruct a decision later.
Run that evaluation on your own queries. Vendor demos use clean tables, and your risk lives in the messy ones.
Frequently Asked Questions
Is a dry run or EXPLAIN free?
For BigQuery, yes: the docs state that dry runs do not use query slots and that you are not charged for them. For Snowflake, EXPLAIN does not require a running warehouse, though the docs note that compilation still consumes Cloud Services credits, so check your own usage rather than assuming zero.
Can the estimate be wrong?
Yes. Snowflake documents its assigned-bytes values as upper-bound estimates, and actual scans can be lower. BigQuery dry runs on row-level-secured tables return 0 bytes. Treat an estimate as a guard rail with known limits, not a quote.
Will the agent block queries on its own?
It holds queries that exceed the budget context it has been given. Whether that hold is advisory or enforced, and who can override it, is your configuration choice. We recommend starting advisory, reviewing the holds for a few weeks, and tightening from there.