☰ Categories

AI2sql SQL Model — Query Generator

Context: This prompt is used by AI2sql to generate SQL queries from natural language.

CategoryDevelopment › Data & databases
TagsDraftingDeveloperCodeTemplate
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}

What this prompt does

This developer prompt converts natural language into SQL for AI2sql. If schema details are missing, it infers practical relationships and avoids follow-up questions.

Model comparison

Gemini is the most concise and faithful; Claude adds an extra column, while ChatGPT repeats a join.

GeminiTop overall
49/ 50

+ It computes all requested metrics concisely in one CTE.

- Ordering is nondeterministic when quantities are tied.

ChatGPT
46/ 50

+ It clearly aggregates and returns quantity and revenue.

- Joining the products table twice is somewhat redundant.

Claude
46/ 50

+ It adds a tie-breaker for more stable result ordering.

- It unnecessarily includes the unrequested category column.

CriterionChatGPTClaudeGeminiLeader
Instruction following9910Gemini +11%
Accuracy999Tie
Specificity10910Tie
Structure91010Tie
Right length9910Gemini +11%

Scored 1–10 by gpt-5.6-sol with model names hidden (2026-09-24). This is an AI review, not a measurement.

Read full answers

We gave three models the same input and copied their answers unedited. Each ran in its CLI (an agent harness), and answers in the ChatGPT or Claude apps or on the web may differ. Outputs are in Korean.

Input used
[Pasted material]
db: PostgreSQL
schema: users(id, name, email, created_at), orders(id, user_id, product_id, quantity, order_date), products(id, name, price, category)
prompt: 지난 30일 동안 가장 많이 팔린 상품 상위 5개와 각 상품의 총 매출을 보여줘
preferences: 서브쿼리보다 JOIN과 CTE를 선호
gpt-5.6-luna (codex CLI · 에이전트 하네스) · Run on 2026-09-24

WITH product_sales AS ( SELECT o.product_id, SUM(o.quantity) AS total_quantity_sold, SUM(o.quantity * p.price) AS total_revenue FROM orders AS o JOIN products AS p ON p.id = o.product_id WHERE o.order_date >= CURRENT_DATE - INTERVAL '30 days' GROUP BY o.product_id ) SELECT p.id AS product_id, p.name AS product_name, ps.total_quantity_sold, ps.total_revenue FROM product_sales AS ps JOIN products AS p ON p.id = ps.product_id ORDER BY ps.total_quantity_sold DESC, ps.total_revenue DESC LIMIT 5;

More in this category

Advanced Text Converter for Large Datasets
AI-powered data extraction and organization tool
Backend Architect
base-R
Building a Scalable Search Service with FastAPI and PostgreSQL