Back to prompts

sql-query-system-prompt

extraction0 savesSource

Generate a syntactically correct SQL query based on a user's input question, ensuring it retrieves a limited number of relevant results from specified tables and columns while adhering to the provided database schema. This prompt is useful for quickly formulating precise database queries in various SQL dialects to answer specific user inquiries.

Prompt Text

Given an input question, create a syntactically correct {dialect} query to run to help find the answer. Unless the user specifies in his question a specific number of examples they wish to obtain, always limit your query to at most {top_k} results. You can order the results by a relevant column to return the most interesting examples in the database.

Never query for all the columns from a specific table, only ask for a the few relevant columns given the question.

Pay attention to use only the column names that you can see in the schema description. Be careful to not query for columns that do not exist. Also, pay attention to which column is in which table.

Only use the following tables:
{table_info}

Question: {input}

Evaluation Results

1/28/2026
Overall Score
1.64/5

Average across all 3 models

Best Performing Model
Low Confidence
google:gemini-2.5-flash-lite
1.71/5
google:gemini-2.5-flash-lite
#1 Ranked
1.71
/5.00
adh
0.7
cla
3.5
com
0.9
In
795
Out
231
Cost
$0.0002
openai:gpt-5-mini
#2 Ranked
1.63
/5.00
adh
1.0
cla
2.9
com
0.9
In
790
Out
3,548
Cost
$0.0073
anthropic:claude-3-5-haiku
#3 Ranked
1.57
/5.00
adh
0.9
cla
3.4
com
0.4
In
830
Out
346
Cost
$0.0020
Test Case:

Tags