-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprompt_builder.py
More file actions
63 lines (48 loc) · 1.09 KB
/
prompt_builder.py
File metadata and controls
63 lines (48 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
def build_prompt(schema, user_question, explain=False):
if explain:
instruction = """
Generate valid MySQL SQL query using given schema.
After SQL, provide short explanation of what the query does.
Return format:
SQL:
<query>
Explanation:
<short explanation>
"""
else:
instruction = """
Generate valid MySQL SQL query using given schema.
Use minimum required tables.
Do not use JOIN unless necessary.
Return ONLY raw SQL.
No explanation.
No markdown.
"""
prompt = f"""
You are an expert MySQL query generator.
STRICT RULES:
1. Use only provided tables and columns.
2. Do not assume anything outside schema.
DATABASE SCHEMA:
{schema}
USER QUESTION:
{user_question}
{instruction}
"""
return prompt
def build_error_correction_prompt(schema, failed_query, error_message):
prompt = f"""
You are an expert MySQL query fixer.
The following SQL query failed.
DATABASE SCHEMA:
{schema}
FAILED QUERY:
{failed_query}
ERROR MESSAGE:
{error_message}
Fix the query using only the provided schema.
Return ONLY corrected SQL.
No explanation.
No markdown.
"""
return prompt