The invention relates to the field of
text generation, and particularly discloses an LLM recursive
refractory recall and self-correct-based NL2
SQL method and
system, the method comprises the following steps: driving LLM to generate an initial recall table set according to user query and table element information of a
database, performing recursive extension on a table in SEEDSET, supplementing a missing table according to VFK in a
virtual database environment, constructing SQLGENPROMPT by using FINRECALLSET and SQLHINT, and performing recursive extension on the missing table in the
virtual database environment. If the execution fails, recording an error, performing correction according to a prompt, repeating the process until the maximum correction frequency is reached, if an
SQL query return result is null, judging whether the result is caused by a false filtering condition through NLI and vector retrieval, and if it is determined that the filtering condition has an error, correcting a filtering value in the
SQL, updating a
query statement and performing re-execution to ensure that the SQL result is accurate. And sorting all successfully executed SQL query statements according to quality, selecting an optimal
query statement as final output, and returning an SQL result required by a user.