The invention provides an automatic error detection and
repair method and
system for translation from
natural language to
SQL (Structured
Query Language), which is characterized in that a plurality of candidate
SQL queries are generated for
natural language queries for given
natural language and original
SQL queries on the basis of a
correctness condition, namely execution consistency, matched with the natural language queries and the SQL queries; the method comprises the following steps of: firstly, translating a natural language to an SQL (Structured
Query Language), trying to generate a counter example between non-equivalent SQL queries by using an SQL equivalence
verification technology, respectively executing the natural language and the SQL queries on the counter example by using a large
language model and a
database execution engine, and if the execution result of the natural language is inconsistent with the execution result of the original SQL query, judging that an error exists in the translation of converting the natural language to the SQL; and if the execution result of the candidate SQL query on the counter example is more matched with the natural language, taking the candidate SQL as a repair result. By means of the method, wrong translation in an existing Text-to-SQL
data set can be automatically detected and repaired, higher-quality training and testing data sets are provided, meanwhile, the method can be used for Text-to-SQL
model translation tasks, and translation accuracy is improved.