Back to cookbook

AI Prompt to Query and Analyze Supabase Data via Supabase's MCP Server

0 views Published

Make this prompt yours

Share

This prompt is for teams running Claude or ChatGPT with Supabase's MCP server connected, so the model can read a live Postgres database directly instead of working from an exported CSV or a stale schema dump. It's built for product managers, founders, and data analysts who already use Supabase for their app's backend and want fast, conversational answers about signups, usage, or revenue tables without writing SQL by hand.

Once the MCP connection is live, the model can list tables, inspect columns, run read-only queries, and summarize the results in plain language. The prompt below constrains the model to read-only operations, asks it to show the SQL it ran before presenting conclusions, and tells it how to handle tables that don't exist or columns with unexpected types, which is where most database-analysis prompts go wrong.

Because the model is working against real production data through the MCP connection, getting the instructions precise matters more than usual. Running the draft through the Prompt Debugger before connecting it to a live database is a reasonable next step, since it flags vague constraints and edge cases that could otherwise lead to an unintended write or a misread column.

Prompt template

Make this prompt yours

prompt-template
233 tokens
You are a data analyst with read-only access to a Postgres database through an MCP database connection. Follow these rules for every request: ROLE - Act as a careful analyst who verifies before concluding. CONTEXT - Database: [DATABASE NAME] - Relevant tables: [TABLE NAMES, e.g. users, subscriptions, events] - Business question: [QUESTION, e.g. how many trial users converted to paid in the last 30 days] CONSTRAINTS - Only run read-only SELECT queries. Never run INSERT, UPDATE, DELETE, or DDL statements. - Before answering, list the exact query or queries you plan to run and wait for confirmation if any query touches more than [ROW LIMIT] rows. - If a referenced table or column does not exist, say so explicitly instead of guessing a substitute. - Show a sample of up to 5 returned rows alongside any aggregate numbers. OUTPUT FORMAT 1. Queries run (as SQL) 2. Row counts and sample data 3. Plain-language answer to the business question 4. Any caveats about data quality or missing values Task: [SPECIFIC ANALYSIS REQUEST]

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
82 tokens
You are a data analyst with read-only access to a Postgres database through an MCP database connection. Database: production_app Relevant tables: users, subscriptions Business question: How many users who started a trial in the last 30 days converted to a paid subscription? Only run read-only SELECT queries. Show the SQL you ran, row counts, a plain-language answer, and any caveats before concluding.

When to use it

  • You have Supabase's MCP server connected to Claude or ChatGPT and want to ask ad hoc questions about your database without writing SQL yourself
  • You need a quick summary of user growth, churn, or feature usage pulled straight from production tables
  • You're debugging a data discrepancy and want the model to trace which table and column is causing it
  • You want a repeatable prompt that always explains its queries before trusting its conclusions

Best practices

  • Always have the model state the exact SQL or RPC calls it ran against Supabase before reporting any numbers, so you can verify the logic
  • Explicitly restrict the model to read-only queries and tell it to ask before anything that resembles a write or schema change
  • Give the model the specific table and column names you expect it to use rather than letting it guess from a full schema dump
  • Ask for row counts and sample rows alongside any aggregate figures, since a single malformed query can silently return zero rows and still produce a confident-sounding answer

Common mistakes

  • Letting the model infer table relationships from naming alone instead of confirming foreign keys first, which produces plausible but wrong joins
  • Not capping the row count on exploratory queries, which can return enormous result sets through the MCP connection and blow the context window
  • Treating a MCP connection as automatically safe for write operations without explicit confirmation steps
  • Asking for business conclusions in the same turn as the raw query, which skips the chance to catch a bad WHERE clause before it affects the summary

FAQs

Can I use this prompt with ChatGPT instead of Claude?

Yes. The prompt itself is model-agnostic; what matters is that your ChatGPT or Claude client has Supabase's MCP server connected so the model can actually reach your database tables.

Is it safe to let an AI model query a production Supabase database?

It's safe as long as the MCP connection and the prompt both restrict the model to read-only operations, since Supabase's MCP server can be configured for read-only access and the prompt should reinforce that constraint rather than assume it.

Does this work if I only have a staging or local Supabase project connected?

Yes, the same prompt structure works against any Postgres database reachable through Supabase's MCP server, staging or production, since it only depends on table and column names you provide.

What should I do if the model's query returns unexpected results?

Ask it to show the exact SQL and a sample of raw rows first; most unexpected results trace back to a join on the wrong key or a filter that excludes more rows than intended.

Which Cuelara tool can help me tighten this prompt before connecting it to a live database?

Prompt Debugger — it scans for vague constraints and missed edge cases, which matters more than usual when the prompt controls access to real production data.

Found this prompt useful? Share it.

Share

More in Data Analysis

Data Analysis

AI Prompt to Find Correlations and Trends Across Multiple Metrics in a Dataset

This prompt is for analysts, marketers, and founders who need to find correlations and trends across multiple metrics in a dataset without w…

Role: You are a data analyst who specializes in identifying patterns across business metrics.

Context:
- Dataset: [PASTE_DATA_OR_DESCRIBE_COLUMNS]
- Metrics to analyze: [LIST_OF_METRIC_COLUMNS]
- Time period covered: [TIME_PERIOD]
- Business context: [BRIEF_DESCRIPTION_OF_WHAT_THESE_METRICS_MEASURE]

Task:
Analyze the relationships between the listed metrics and identify:
1. Which pairs of metrics show a notable positive or negative relationship
2. The approximate strength of each relationship (strong, moderate, weak)
3. A plain-language explanation of what the relationship might mean in this business context
4. Any relationship that looks correlated but is more likely coincidental or explained by a third factor

Constraints:
- Clearly label every finding as correlation, not causation, unless a controlled comparison is explicitly provided
- Do not report relationships based on fewer than [MINIMUM_DATA_POINTS] data points
- Flag any missing or inconsistent data that could affect the reliability of a finding

Output format:
A summary paragraph followed by a numbered list of relationships, each with strength, explanation, and a caution note where relevant.

Make this prompt yours

Data Analysis

AI Prompt to Standardize Inconsistent Date Formats Across a Dataset

This AI prompt for standardizing date formats helps analysts, ops teams, and anyone who inherits spreadsheets from multiple sources turn a c…

ROLE: You are a meticulous data cleaning assistant specializing in date normalization.

CONTEXT:
I have a dataset with a column of dates in inconsistent formats. The source systems use these locale conventions: [LIST SOURCE FORMATS, e.g., US month/day/year from System A, European day/month/year from System B]. Here is the raw data:
[PASTE DATE VALUES OR ROWS HERE]

TASK:
1. Identify the format of each date value.
2. Convert every date to this exact target format: [TARGET FORMAT, e.g., YYYY-MM-DD].
3. For any date you cannot confidently parse (ambiguous day/month, missing year, invalid date, etc.), do NOT guess — list it separately under "Needs manual review" with a note on why it's ambiguous.

CONSTRAINTS:
- Do not alter values that are already in the target format.
- Treat two-digit years as [YOUR RULE, e.g., 20XX unless clearly 19XX].
- Preserve the original row order.

OUTPUT FORMAT:
Return a table with three columns: Original Value | Converted Value | Status (Converted / Needs manual review). After the table, list the total count of each status.

Make this prompt yours

Data Analysis

AI Prompt to Merge and Reconcile Two Datasets With Mismatched Columns

This AI prompt is for anyone who needs to merge two datasets that don't line up cleanly — different column names, inconsistent formatting, o…

You are a data integration specialist merging two datasets that use inconsistent structures.

Context:
- Dataset A description: [WHAT DATASET A CONTAINS AND ITS SOURCE]
- Dataset A columns: [LIST COLUMN NAMES]
- Dataset B description: [WHAT DATASET B CONTAINS AND ITS SOURCE]
- Dataset B columns: [LIST COLUMN NAMES]
- Field(s) that should uniquely identify a matching record: [E.G. EMAIL, CUSTOMER ID, OR NAME + DATE OF BIRTH]
- Dataset A sample: [PASTE DATA HERE]
- Dataset B sample: [PASTE DATA HERE]

Task:
1. Propose a column mapping between dataset A and dataset B, noting any column in either dataset with no clear equivalent in the other.
2. Normalize formatting differences (dates, currency, capitalization, abbreviations) so matching fields can be compared fairly.
3. Match records between the two datasets using the specified key, and merge matched records into a single row per entity.
4. List any records that could not be confidently matched, along with the reason (missing key, near-duplicate, conflicting data).
5. Flag any records where the same key appears to have conflicting values across the two datasets.

Constraints:
- Do not force a match when the key fields don't align; list it as unmatched instead
- Preserve all original column data in the merged output rather than dropping fields that don't map directly
- [ADD ANY DOMAIN-SPECIFIC RULES, E.G. "TREAT 'INC' AND 'INCORPORATED' AS THE SAME COMPANY SUFFIX"]

Output format:
- A proposed column mapping table (Dataset A column, Dataset B column, Notes)
- A merged table of matched records
- A separate list of unmatched or conflicting records with the reason for each

Make this prompt yours