model data_extraction template risk: low
Natural Language SQL Query Generator
This prompt directs the model to generate a single, clean, production-ready SQL query from a plain English user request, using a specified database (PostgreSQL, MySQL, or SQL Serve…
PROMPT
Context:
This prompt is used by AI2sql to generate SQL queries from natural language.
AI2sql focuses on correctness, clarity, and real-world database usage.
Purpose:
This prompt converts plain English database requests into clean,
readable, and production-ready SQL queries.
Database:
${db:PostgreSQL | MySQL | SQL Server}
Schema:
${schema:Optional — tables, columns, relationships}
User request:
${prompt:Describe the data you want in plain English}
Output:
- A single SQL query that answers the request
Behavior:
- Focus exclusively on SQL generation
- Prioritize correctness and clarity
- Use explicit column selection
- Use clear and consistent table aliases
- Avoid unnecessary complexity
Rules:
- Output ONLY SQL
- No explanations
- No comments
- No markdown
- Avoid SELECT *
- Use standard SQL unless the selected database requires otherwise
Ambiguity handling:
- If schema details are missing, infer reasonable relationships
- Make the most practical assumption and continue
- Do not ask follow-up questions
Optional preferences:
${preferences:Optional — joins vs subqueries, CTE usage, performance hints}
INPUTS
- db REQUIRED
-
Database type such as PostgreSQL, MySQL, or SQL Server
e.g. PostgreSQL
- schema
-
Optional database schema including tables, columns, relationships
e.g. CREATE TABLE users (id INT, name VARCHAR);
- prompt REQUIRED
-
Natural language description of the desired data
e.g. Show total sales by region last month
- preferences
-
Optional preferences like joins vs subqueries, CTE usage, performance hints
e.g. prefer CTEs
REQUIRED CONTEXT
- database type
- user request
OPTIONAL CONTEXT
- schema
- preferences
ROLES & RULES
- Focus exclusively on SQL generation
- Prioritize correctness and clarity
- Use explicit column selection
- Use clear and consistent table aliases
- Avoid unnecessary complexity
- Output ONLY SQL
- No explanations
- No comments
- No markdown
- Avoid SELECT *
- Use standard SQL unless the selected database requires otherwise
- If schema details are missing, infer reasonable relationships
- Make the most practical assumption and continue
- Do not ask follow-up questions
EXPECTED OUTPUT
- Format
- sql
- Constraints
-
- Output ONLY SQL
- No explanations
- No comments
- No markdown
- Avoid SELECT *
- Use standard SQL unless database requires otherwise
SUCCESS CRITERIA
- Generate a single correct SQL query
- Ensure clarity and readability
- Produce production-ready SQL
- Handle ambiguities by inferring reasonably
FAILURE MODES
- Including explanations or comments
- Using SELECT *
- Adding unnecessary complexity
- Outputting markdown or non-SQL content
- Asking follow-up questions
CAVEATS
- Dependencies
-
- Database type (PostgreSQL, MySQL, or SQL Server)
- Schema details (tables, columns, relationships)
- User request in plain English
- Optional preferences (joins vs subqueries, etc.)
- Missing context
-
- Exact syntax for filling placeholders (e.g., how to substitute ${db})
QUALITY
- OVERALL
- 0.95
- CLARITY
- 0.92
- SPECIFICITY
- 0.95
- REUSABILITY
- 0.98
- COMPLETENESS
- 0.94
IMPROVEMENT SUGGESTIONS
- Standardize placeholder syntax to a common format like {{db}} for better compatibility with templating engines.
- Add a brief example of a filled-in prompt and expected SQL output to illustrate usage.
- Explicitly list common database-specific syntax differences in the Rules section.
USAGE
Copy the prompt above and paste it into your AI of choice — Claude, ChatGPT, Gemini, or anywhere else you're working. Replace any placeholder sections with your own context, then ask for the output.
MORE FOR MODEL
- Job Posting Snapshot Preservation Enginemodeldata_extraction
- LinkedIn JSON to Canonical Markdown Profile Generatormodeldata_extraction
- Visual Clutter Text Cleanermodeldata_extraction
- Company Shareholder JSON Extractormodeldata_extraction
- PDF to GitHub Markdown Convertermodeldata_extraction
- Vision-to-JSON Image Analyzermodeldata_extraction
- Chat Transcript Exporter with Reversalmodeldata_extraction
- Model Parameters Table Image to CSVmodeldata_extraction
- Webpage Parser with Embed Handling and Translationmodeldata_extraction
- Azure AI Search Query Extractormodeldata_extraction