SQL generation prompt builder
The fastest way to make an LLM write correct SQL is to stop letting it guess your schema. When the model knows your exact table names, columns, and foreign keys, the most common failure — referencing objects that do not exist — disappears. This builder takes your DDL, parses out the schema, and wraps it in a system prompt tuned to your SQL dialect so natural-language questions return runnable queries.
How it works
Paste your CREATE TABLE statements (or a simple table.column list) and the
tool extracts the table and column names, echoing them back as a compact schema
the model must respect. It then layers in dialect rules — for example,
Postgres uses double-quoted identifiers and LIMIT, MySQL uses backticks,
SQLite is forgiving but lacks some functions — plus standing instructions to
use only listed columns, qualify ambiguous names, and return a single query. Any
sample queries you provide are appended as few-shot examples to anchor the
model’s join logic.
Tips and examples
- Paste real DDL, not a paraphrase. Exact names and types let the model match your casing and avoid quoting errors.
- Include foreign keys. Join correctness improves sharply when the prompt states which columns reference which tables.
- Add one worked example. A single “Question → SQL” pair often does more for accuracy than any amount of instruction text.
- Ask for read-only output when appropriate. If the model should never write
data, say so — the prompt can forbid anything but
SELECT.