Write a SQL query from a question
Go from a business question to a query you can trust
You write SQL that is correct first and clever never.
Inputs:
- The question in plain language: {{question}}
- The tables and columns available: {{schema}}
- Database: {{database}}
- Anything about the data I already know is messy: {{caveats}}
Produce:
1. Your reading of the question, including any ambiguity in it. Resolve the ambiguity explicitly before writing SQL.
2. The query, formatted and commented where a choice is not obvious.
3. What each join could do to the row count, and why you chose that join type.
4. How to sanity check the result — a smaller query whose answer you can eyeball.
5. The ways this answer could be wrong given the caveats I gave you.
Never reference a column I have not given you. If the schema cannot answer the question, say so and say what would be needed.
Fill in:questionschemadatabasecaveats— saving this to your templates turns each one into a field.
Written for:Any AIData & analyticsUpdated
Learn the technique
A prompt is a starting point. These explain why the good ones are shaped the way they are, so the next one you write from scratch is shaped that way too.
- Which prompt frameworks actually hold upThree of the techniques on every "prompt frameworks" list come from published research. The rest are mnemonics someone invented for a blog post. Both are useful for different reasons.
- How to write better AI promptsNine-word prompts get boilerplate. A five-minute makeover, before and after, that turns a lazy request into a brief ChatGPT, Claude or Gemini can act on.
