MCPcopy Create free account
hub / github.com/FlyingFeather/DEA-SQL / correct_sql_self

Function correct_sql_self

correct_sql.py:11–40  ·  view source on GitHub ↗
(query, table_info, sql)

Source from the content-addressed store, hash-verified

9
10
11def correct_sql_self(query, table_info, sql):
12 sql_prompt = "For the given question, use the Database scheme to fix the given SQLite QUERY for any issuses.\n" \
13 "If there are any problems, please fix them.\n" \
14 "If there are no issues, return SQLite QUERY as is.\n" \
15 "### There are some instructions for fixing the SQL query:\n" \
16 "1) In sql, just select columns that are explicitly requested in the query.\n" \
17 "2) Pay attention to the columns that are used for the SELECT clause. " \
18 "Fix possible ambiguous columns if there are the same columns in different table in the SELECT clause.\n" \
19 "3) Pay attention to the correspondence between tables and fields. " \
20 "Cannot use fields that are not in the table.\n" \
21 "4) Pay attention to the columns that are used for the JOIN." \
22 "The join table condition must be in the Foreign_keys.\n" \
23 "5) Pay attention to the use of the JOIN." \
24 "Don't use LEFT JOIN unless necessary.\n" \
25 "6) Only change the SELECT, GROUP BY and ORDER BY clause when necessary.\n" \
26 "7) " \
27 f"Database scheme: {table_info}\n" \
28 f"### Question: {query}\n" \
29 f"### SQLite SQL QUERY:\n" \
30 f"{sql}\n" \
31 f"### Fixed SQL QUERY:" \
32 f"SELECT\n"
33 prompt_dict = {
34 "query": query,
35 "table_info": table_info,
36 "sql": sql
37 }
38 sql_prompt = get_prompt_content(sql_prompt, prompt_dict)
39 sql = ask_llm(sql_prompt)
40 return sql
41
42
43def correct_sql_by_case(query, table_info, sql):

Callers 1

step_get_sqlMethod · 0.90

Calls 2

get_prompt_contentFunction · 0.90
ask_llmFunction · 0.90

Tested by

no test coverage detected