The warehouse bill went up 40% and someone has to explain it by Friday.
Tier: Core · Workflow area: Orchestration, ops & cost
The evidence is all there — account usage views log every query, its bytes, its warehouse, its user — but turning a million rows of query history into "these five workloads drove the increase, here's the fix for each, and here's who pays for what" is analyst work that data engineers get handed anyway. This playbook uses SQL for the aggregation (facts) and an LLM for the parts humans are slow at: recognizing anti-patterns across thousands of query shapes and drafting the chargeback narrative stakeholders will actually read.
If the bill is small and flat, a quarterly glance at the console beats building this.
Aggregate with SQL — facts come from queries, not the model. Pull from account usage (Snowflake ACCOUNT_USAGE.QUERY_HISTORY, BigQuery INFORMATION_SCHEMA.JOBS, Databricks system tables) an aggregate by query fingerprint (normalized query text hash — every platform exposes one or lets you compute it):
-- ANSI-flavored shape; adapt view/column names per platform
SELECT query_fingerprint,
any_value(sample_query_text) AS sample_text,
count(*) AS runs,
sum(cost_estimate) AS total_cost,
sum(bytes_scanned) AS total_bytes,
avg(execution_seconds) AS avg_seconds,
any_value(user_name) AS typical_user,
any_value(warehouse_name) AS warehouse
FROM query_history_30d
GROUP BY query_fingerprint
ORDER BY total_cost DESC
LIMIT 200;
Also pull the same aggregate for the prior period — the delta view is what explains a spike. Export both as CSV/JSON.
Have the LLM rank drivers and detect anti-patterns.
Attached: top-200 query fingerprints by cost for this period and last period
(columns: fingerprint, sample_text, runs, total_cost, bytes, avg_seconds,
user, warehouse).
Produce:
1. Cost-driver ranking: which fingerprints/workloads explain the period-over-period
increase; show the arithmetic from the attached numbers.
2. Anti-pattern tags per offender, from this list only: SELECT-star-wide-table,
unpruned-scan (bytes >> plausible partition size), high-frequency-small-query
(scheduling problem), cartesian/exploding-join (output >> input), retry-storm
(same fingerprint, burst timing), oversized-warehouse (low avg utilization),
zombie-schedule (output table has no readers — flag for the lineage check).
3. For each: the fix category, effort guess (S/M/L), and estimated monthly savings
derived from the attached cost — show the derivation.
4. Chargeback draft: cost per team (user→team mapping attached), one paragraph
per team, neutral tone, stating drivers and recommended actions.
Do not invent numbers; every figure must be computable from the attachment.
Expected output: a ranked fix backlog and a narrative draft where every number traces to your export. Tagging accuracy is high because you constrained the taxonomy; free-form "insights" are where hallucination lives.
Verify the top findings against ground truth. For each of the top ~10: re-run the arithmetic in SQL, and check the anti-pattern claim against the actual query profile (an "unpruned scan" claim should show in bytes-scanned vs. table partition sizes). Kill any finding you can't reproduce; note it — a model that mis-tagged once will mis-tag again, and your prompt taxonomy may need sharpening.
Route fixes and attach owners. Zombie schedules → confirm with lineage/readers then disable; unpruned scans and exploding joins → per-query tuning (pb-24); high-frequency patterns → scheduling/caching change; oversized warehouses → right-size and measure a week. Every backlog item gets an owner and its estimated saving — this is what turns a report into a program.
Draft, humanize, ship the narrative. The LLM's chargeback draft is 80% done; the human pass adds context the data doesn't show (the marketing spike was the campaign launch, and was approved). Publish period-over-period per team with trend, top drivers, actions taken, savings realized from last period's actions — that last line is what builds credibility for the program.
Automate the cadence. Schedule the aggregation queries, re-run the analysis monthly, and track realized-vs-estimated savings per closed backlog item. A one-off triage decays in a quarter; the loop compounds.
SQL computes the numbers, the LLM explains and drafts — never the reverse. Every figure in the narrative must be reproducible from the query-history export, and the top-10 findings get re-verified in SQL before anyone sees the report.
Cost data is commercially sensitive twice over — it reveals the client's cloud spend and, via query text, their business logic. Run the aggregation entirely in the client's warehouse; export only fingerprint-level aggregates with literals stripped and, if required, table names pseudonymized before any external model sees them (or use an in-platform/self-hosted model and skip the concern). The chargeback narrative must go through a client-side review before circulation — cost allocation is organizationally political, and the consultant's draft should arrive as "proposed allocation with reproducible numbers", never as a fait accompli. The reproducibility pack (the SQL, the export, the arithmetic) is what makes the report defensible after you leave.