AI Prompt to Audit BigQuery Query Costs Using Google Cloud's MCP Server
This BigQuery MCP prompt is for data analysts and engineers who want to find out why their Google Cloud bill is climbing without manually digging through billing exports. Connected through an MCP server, Claude, ChatGPT, or Gemini can query BigQuery's INFORMATION_SCHEMA job and slot usage data directly, instead of relying on a static export someone pasted into a spreadsheet.
It's built around a common problem: a handful of queries or scheduled jobs quietly scanning far more data than they need to, often because of a missing partition filter or a SELECT * left in a production job. The prompt asks the model to rank the most expensive queries by bytes scanned, group them by the table or dataset involved, and flag the specific pattern driving the cost.
Because this kind of audit depends on getting the time window, project, and cost threshold right before the model starts querying, running the request through a Prompt Optimizer in Research mode first can help turn a vague "why is our bill so high" ask into something the model can act on precisely.
Prompt template
Want it sharper? Optimize this prompt with Prompt Optimizer, check it with the Prompt Debugger or shorten it with the Token Optimizer.
Example input
When to use it
- Your BigQuery or Google Cloud bill jumped and you need to find which jobs are driving it
- A scheduled query or dashboard refresh seems slower or more expensive than it used to be
- You want a ranked list of the most expensive queries from the last day, week, or month
- You're setting cost controls and need to know which teams or tables account for the most spend
Best practices
- Specify the exact time window and project ID rather than letting the model assume a default range
- Ask for both bytes scanned and dollar cost, since slot-based pricing and on-demand pricing calculate differently
- Have the model group results by table or dataset, not just by individual query, to spot recurring patterns
- Request the specific fix (partition filter, clustering, materialized view) rather than a generic "optimize your query" suggestion
Common mistakes
- Not specifying whether the project uses on-demand or flat-rate (slot-based) pricing, which changes how cost is calculated
- Asking for 'expensive queries' without a time window, which can return a misleading or incomplete picture
- Treating bytes scanned and bytes billed as the same number when cached or partitioned queries differ
- Skipping the step of checking which queries are scheduled vs. ad hoc, since scheduled jobs recur and compound cost
FAQs
Why is my BigQuery bill higher than expected?
The most common causes are queries without a partition filter that scan an entire table, SELECT * statements pulling unnecessary columns, and scheduled jobs that recur more often than needed. Auditing by bytes scanned over a set time window usually surfaces the pattern quickly.
What's the difference between bytes scanned and bytes billed in BigQuery?
Bytes scanned is the raw amount of data a query reads. Bytes billed can be lower if the query hits a cached result or reads from a partitioned/clustered table efficiently, which is why two queries that look similar can cost very different amounts.
Can an AI assistant actually query my BigQuery billing data directly?
Yes, if it's connected through an MCP server (or similar integration) that exposes BigQuery's INFORMATION_SCHEMA views and job metadata as callable tools. Without that connection, you'd need to export the data and paste it in manually.
How do I reduce BigQuery costs without changing my queries?
Switching to flat-rate (slot-based) pricing, enabling table partitioning and clustering, or using materialized views for frequently repeated queries can all reduce cost without rewriting the underlying SQL logic.
What tool pairs well with this prompt?
Prompt Optimizer — its Research mode helps turn a vague cost-audit request into a structured one with the right time window, project scope, and threshold before you run it against your data.