Prompt library
Write SQL from a plain-language request
Most wrong SQL is a correct answer to a misread question, so the grain-and-edges restatement catches errors before they cost a table scan. The never-invent-columns rule plus the assumptions list makes silent schema hallucination visible.
Last reviewed July 17, 2026
The prompt
Write a SQL query for the request below.
Schema: {{schema}}
Request: {{request}}
Dialect: {{dialect}}
Rules:
1. Before the query, restate the request in one sentence including grain (one row per what?) and edge decisions (ties, nulls, timezone, inclusive or exclusive date bounds). If the request is ambiguous, state the interpretation you chose.
2. Write the query with CTEs named after business concepts, not t1/t2.
3. Comment any line where a subtle choice hides (join type, null handling, dedup).
4. Then list what would silently break it: schema assumptions you made that the schema text did not confirm.
5. End with a 3-row mock of the expected output shape.
Never invent columns; if a needed column is missing from the schema, say which and stop.Run in idaptOpens a new chat with the prompt prefilled. Nothing sends until you press send.
Fill in the variables
| Variable | What it is | Example |
|---|---|---|
| {{schema}} | The relevant tables and columns | orders(id, customer_id, total_cents, status, created_at), customers(id, country, created_at) |
| {{request}} | What you want, in plain words | monthly revenue from completed orders for the last 12 months, split by customer country, including months with zero revenue |
| {{dialect}} | The SQL dialect | PostgreSQL |