Skip to content
← All guides

Guide · Intermediate · 5 min

Prompt for a SQL query

A model cannot see your schema. Paste it, or it will invent column names that look right.

The schema is the context

Every wrong SQL answer traces back to the same gap: the model guessed your columns. Paste the tables and their columns inline — 'users(id, email, created_at, plan)' is enough. This one line prevents more errors than any amount of instruction about writing good SQL.

Name the dialect and the version

Postgres 15, MySQL 8 and SQLite disagree about window functions, date arithmetic and upserts. A query that is correct in one is a syntax error in another. One clause — 'You are writing PostgreSQL 15' — removes a whole class of failure.

Say what a row means

Ask for the exact columns and their units: 'email, order count, and total in rupees to two decimals'. Money in particular goes wrong quietly — if the column stores paise and you wanted rupees, an unlabelled number is a bug you will find in production.

Try it

Give it a schema, a dialect, and a definition of the output row. Aim for a score of 85+.

74structure

Target: 85. Keep working the prompt — the score moves as you type.

  • Role / persona: Open with a persona, e.g. "You are a senior backend engineer."
  • Constraints: State limits and do/don't rules, e.g. "Keep it under 200 words. Do not invent APIs."
  • Examples (few-shot): Add one input→output example to anchor tone, format, and edge handling.