adamboom111 commited on
Commit
9b2d1b9
·
verified ·
1 Parent(s): 3902d48

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -11
app.py CHANGED
@@ -8,23 +8,25 @@ api = os.getenv("GROQ_API_KEY")
8
 
9
  def create_prompt(user_query, table_metadata):
10
  system_prompt = """
11
- You are a SQL query generator specialized in generating SQL queries for a single table at a time.
12
- Your task is to accurately convert natural language queries into SQL statements based on the user's intent and the provided table metadata.
13
 
14
- Rules:
15
- - Single Table Only: Use only the table in the metadata.
16
- - Metadata-Based Validation: Use only columns in the metadata.
17
- - User Intent: Support filters, grouping, sorting, etc.
18
- - SQL Syntax: Use standard SQL (DuckDB compatible).
19
- - Output only valid SQL. No extra commentary.
20
 
21
  Input:
22
  User Query: {user_query}
23
- Table Metadata: {table_metadata}
 
24
 
25
  Output:
26
- SQL Query (on a single line, nothing else).
27
- """
 
28
  return system_prompt.strip(), f"User Query: {user_query}\nTable Metadata: {table_metadata}"
29
 
30
  def generate_output(system_prompt, user_prompt):
 
8
 
9
  def create_prompt(user_query, table_metadata):
10
  system_prompt = """
11
+ You are a SQL query generator for a single relational table.
12
+ You must strictly follow the metadata and never guess or invent column names.
13
 
14
+ Instructions:
15
+ - Use only the table and columns listed in the metadata.
16
+ - Never generate queries with columns not present in the metadata.
17
+ - If a column like 'gender' is not present, do not mention it.
18
+ - Do not hallucinate values. Use provided structure only.
19
+ - Output valid SQL (DuckDB-compatible), single line, no comments or explanations.
20
 
21
  Input:
22
  User Query: {user_query}
23
+ Table Metadata:
24
+ {table_metadata}
25
 
26
  Output:
27
+ A single valid SQL SELECT statement using only metadata-provided columns.
28
+ """
29
+
30
  return system_prompt.strip(), f"User Query: {user_query}\nTable Metadata: {table_metadata}"
31
 
32
  def generate_output(system_prompt, user_prompt):