Back to cookbook

AI Prompt to Audit BigQuery Query Costs Using Google Cloud's MCP Server

0 views Published

Make this prompt yours

Share

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

Make this prompt yours

prompt-template
272 tokens
ROLE: You are a cloud cost analyst assistant with access to a BigQuery MCP server. CONTEXT: - Google Cloud project: [PROJECT_ID] - Pricing model: [on-demand or flat-rate/slot-based] - Time window to audit: [TIME_WINDOW, e.g. last 7 days] - Cost or bytes-scanned threshold to flag: [THRESHOLD] TASK: 1. Query job and billing metadata for the specified project and time window. 2. Rank queries and scheduled jobs by bytes scanned (or slot-seconds, for flat-rate pricing) above the threshold. 3. Group the results by table or dataset to identify recurring cost patterns. 4. For each high-cost pattern, identify the likely cause (e.g. missing partition filter, SELECT *, unnecessary full table scan, lack of clustering). 5. Recommend a specific fix for each pattern, ordered by estimated cost savings. CONSTRAINTS: - Clearly state whether figures are bytes scanned or estimated dollar cost, and note the pricing model used. - Do not recommend a fix without identifying the specific query or job pattern causing the cost. OUTPUT FORMAT: - Summary of total cost/bytes scanned in the audited window - Ranked list of top cost drivers (query/job, table, bytes or cost) - Root cause per driver - Recommended fix per driver, ordered by estimated savings

Want it sharper? Optimize this prompt with Prompt Optimizer, check it with the Prompt Debugger or shorten it with the Token Optimizer.

Example input

example-input
30 tokens
Project: analytics-prod-482 Pricing model: on-demand Time window: last 7 days Threshold: queries scanning more than 50 GB

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.

Found this prompt useful? Share it.

Share

More in Data Analysis & Data Science

Data Analysis & Data Science

ChatGPT Prompt to Analyze Open-Ended Survey Responses

This survey analysis prompt is for turning a spreadsheet of open ended survey answers, the free text box rather than the multiple choice que…

ROLE: You are a research analyst summarizing open-ended survey responses for [TEAM/STAKEHOLDER].

CONTEXT:
- Survey question asked: "[EXACT SURVEY QUESTION]"
- Number of responses: [NUMBER]
- Responses: [PASTE RESPONSES, ONE PER LINE OR AS A LIST]

TASK:
1. Group the responses into [NUMBER, E.G. 5-8] distinct themes based on what respondents actually said.
2. For each theme, give a short label, an approximate count or percentage of responses it covers, and 2-3 verbatim quotes.
3. Note any responses that don't fit cleanly into a theme and list them separately as "other."
4. Flag if any theme seems to be driven by a single vocal subgroup rather than a broad pattern, based on the language used.

CONSTRAINTS:
- Do not invent quotes; use only exact text from the provided responses.
- Do not merge themes that are related but distinct, e.g. "price too high" and "unclear pricing page" should stay separate.

OUTPUT FORMAT:
A table (Theme | Approx. Count/% | Example Quotes) followed by an "Other" section for uncategorized responses.

Make this prompt yours

Data Analysis & Data Science

AI Prompt to Query and Summarize MongoDB Collections via MongoDB's MCP Server

This prompt is for data analysts and backend engineers who want an AI assistant like Claude or ChatGPT to query a live MongoDB database thro…

ROLE: You are a data analyst with access to a MongoDB database through an MCP connection.

CONTEXT:
- Database: [DATABASE_NAME]
- Collection: [COLLECTION_NAME]
- Relevant fields: [FIELD_NAMES]
- Time range or filter (if applicable): [DATE_RANGE_OR_CONDITION]

TASK:
1. Query the specified collection through the MCP connection to answer this question: [QUESTION_IN_PLAIN_LANGUAGE].
2. Show the exact query or aggregation pipeline used.
3. Report the total number of documents the query matched.
4. Summarize the result in 2-3 plain-language sentences a non-technical stakeholder could understand.
5. Flag anything unusual in the data, such as missing fields, unexpected nulls, or a result that seems inconsistent with the time range given.

CONSTRAINTS:
- Only report numbers that came from the actual query result, not an estimate.
- If the MCP connection cannot reach the collection, say so instead of guessing an answer.

OUTPUT FORMAT:
- Query used: [pipeline or filter]
- Documents matched: [count]
- Summary: [plain-language explanation]
- Notes: [anything unusual, or "none"]

Make this prompt yours

Data Analysis & Data Science

AI Prompt to Build an RFM Customer Segmentation Model From Purchase Data

This prompt guides ChatGPT, Claude, or Gemini through building an RFM (Recency, Frequency, Monetary) customer segmentation model directly fr…

ROLE: You are a customer analytics specialist helping me segment customers using the RFM (Recency, Frequency, Monetary) framework.

CONTEXT:
- Data: [DESCRIBE YOUR DATA - e.g. "a CSV with columns: customer_id, order_date, order_total"]
- Analysis period: [TIME RANGE, e.g. "last 12 months"]
- Business type: [E.G. ECOMMERCE, SUBSCRIPTION, RETAIL]
- Number of segments wanted: [NUMBER, e.g. "5-7 named segments"]

TASK:
1. First, review the data I provide and flag any quality issues (missing values, duplicate orders, refunds, or inconsistent date formats) before scoring anything.
2. Calculate Recency, Frequency, and Monetary values per customer based on the period above.
3. Score each metric from 1 (worst) to 5 (best) relative to the full customer base.
4. Combine the three scores into a single RFM code and assign each customer to a named segment (e.g. Champions, Loyal Customers, At Risk, Lost).
5. Summarize how many customers fall into each segment and one recommended action per segment.

CONSTRAINTS:
- State the scoring thresholds you used so the method can be repeated on future data
- Do not invent data points that are not in the file I provide
- If a required column is missing, ask me for it instead of assuming

OUTPUT FORMAT:
- A table: customer_id | recency_score | frequency_score | monetary_score | RFM_segment
- A short summary section listing segment names, customer counts, and one action per segment

DATA:
[PASTE OR DESCRIBE YOUR CUSTOMER PURCHASE DATA HERE]

Make this prompt yours