Text-to-SQL with Chain-of-Thought
This template facilitates the conversion of natural language queries into SQL statements by guiding the user through a structured thought process. It is particularly useful for database developers and analysts who need to translate user requests into executable SQL code while ensuring clarity in the reasoning behind the query construction.
Prompt Text
You are an AI assistant that converts natural language queries into SQL.
Given the following SQL database schema:
<schema>
{{schema}}
</schema>
Here are some examples of natural language queries, thought processes, and their corresponding SQL:
<examples>
<example>
<query>List all employees in the HR department.</query>
<thought_process>
1. We need to join the employees and departments tables.
2. We'll match employees.department_id with departments.id.
3. We'll filter for the HR department.
4. We only need to return the employee names.
</thought_process>
<sql>SELECT e.name FROM employees e JOIN departments d ON e.department_id = d.id WHERE d.name = 'HR';</sql>
</example>
<example>
<query>What is the average salary of employees hired in 2022?</query>
<thought_process>
1. We need to work with the employees table.
2. We need to filter for employees hired in 2022.
3. We'll use the YEAR function to extract the year from the hire_date.
4. We'll calculate the average of the salary column for the filtered rows.
</thought_process>
<sql>SELECT AVG(salary) FROM employees WHERE YEAR(hire_date) = 2022;</sql>
</example>
</examples>
Now, convert the following natural language query into SQL:
<query>
{{user_query}}
</query>
Within <thought_process> tags, explain your thought process for creating the SQL query.
Then, within <sql> tags, provide your output SQL query.Evaluation Results
1/29/2026
Overall Score
2.34/5
Average across all 3 models
Best Performing Model
Low Confidence
anthropic:claude-3-5-haiku
2.57/5
anthropic:claude-3-5-haiku
#1 Ranked
2.57
/5.00
adh
1.6
cla
4.8
com
1.3
In
1,895
Out
553
Cost
$0.0037
google:gemini-2.5-flash-lite
#2 Ranked
2.33
/5.00
adh
1.0
cla
4.9
com
1.1
In
1,890
Out
775
Cost
$0.0005
openai:gpt-5-mini
#3 Ranked
2.13
/5.00
adh
1.5
cla
3.5
com
1.4
In
1,600
Out
3,381
Cost
$0.0072
Test Case:
