AIAgentIndex
← All use cases
Data

Plain-English questions to SQL

Lets teammates ask questions about your database in plain English; the agent writes read-only SQL, runs it, and shows both the query and the result.

Who it's for and the problem it solves

For startups and small data teams where everyone has questions for the database but only a few people write SQL. The analyst becomes a bottleneck for simple questions, and ad-hoc queries run with production credentials are risky. This agent writes and runs read-only SQL and always shows the query, so answers can be checked.

DataSQLAnalytics

Tools

How to set it up

  1. 1Create a dedicated Postgres role with SELECT-only access to an approved set of tables or views, ideally on a read replica. Set statement_timeout and a row limit for that role.
  2. 2Write a schema guide: what each approved table means, how key columns are defined (for example, what counts as an 'active customer'), and common joins. Accurate answers depend on this guide more than anything else.
  3. 3Exclude or mask sensitive columns (emails, payment details, free-text notes) by exposing views instead of raw tables.
  4. 4Connect Claude to the database through a tool that only accepts the read-only role, and have it list the schema and read the guide before writing queries.
  5. 5Require every answer to show the SQL, the result table and a one-sentence plain-English interpretation, plus any assumptions it made about definitions.
  6. 6For questions that will be asked again, save the query as a Metabase question or dashboard so the number has one owner and one definition.
  7. 7Have the data owner review a log of questions and queries each week, and fix the schema guide where the agent picked the wrong table or definition.

Example agent instructions

Copy, paste and adapt. Replace anything in {braces} with your own details.

You answer questions about our data using Postgres. You have a READ-ONLY role.
Before writing SQL, read the schema guide and use its metric definitions exactly.
For each question:
1. Restate the question and any assumption (time range, timezone, what "active" means).
2. Write a single SELECT query. Never use INSERT, UPDATE, DELETE, DDL or functions with side effects. Always include a LIMIT for row-level results.
3. Run it, then show: the SQL, the result (max 50 rows) and a 1-2 sentence interpretation.
4. If the question is ambiguous or the needed data isn't in the approved tables, say so and ask instead of guessing.
5. Never show columns marked sensitive in the guide.
6. If the query will be reused, suggest saving it in Metabase.

Guardrails and human checkpoints

Example input and output

Illustrative example only, not real customer data.

Example input

Example question from Slack: "How many new paying customers did we get each month this year?"

Example output

Example answer (illustrative): Assumption: 'paying customer' = first successful payment, months in UTC. SQL: SELECT date_trunc('month', first_paid_at) AS month, count(*) AS new_paying FROM analytics.customers_v WHERE first_paid_at >= date_trunc('year', now()) GROUP BY 1 ORDER BY 1; Result: {table of months and counts} Interpretation: {one sentence describing the trend in the returned numbers}

What to measure

FAQ

Is it safe to connect an AI to our production database?

Only through a read-only role with timeouts, limited to approved views and ideally on a replica. Let the database enforce permissions rather than the prompt.

Why does it keep asking clarifying questions?

Most data questions hide a definition (active, churned, revenue). A good schema guide answers those up front and cuts down the follow-ups.

Does it replace Metabase or our BI tool?

No. It's good for one-off questions, and the BI tool is where agreed metrics and dashboards live. Promote anything recurring into Metabase.

Related use cases

Get new agent playbooks by email

AgentIndex Pro

Weekly launch alerts for new agent use cases. Advanced search and early access are coming soon. What's included