An intent structured SQL statement generation method based on a large language model

By constructing an intermediate representation of query intent and introducing an improved PICARD algorithm, the problem of insufficient structuring of query intent in the SQL statement generation process in existing technologies is solved. This enables multi-dimensional constraints on SQL statements during the generation stage, improves the stability and consistency of the generated results, and ensures that the generated SQL statements conform to the database schema and business rules.

CN122152854APending Publication Date: 2026-06-05SHANGHAI DASHI INFORMATION TECHNOLOGY CO LTD +1

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
SHANGHAI DASHI INFORMATION TECHNOLOGY CO LTD
Filing Date
2026-03-04
Publication Date
2026-06-05

Smart Images

  • Figure CN122152854A_ABST
    Figure CN122152854A_ABST
Patent Text Reader

Abstract

The application discloses an intent structured SQL sentence generation method based on a large language model, and comprises the following steps: obtaining a natural language query sentence input by a user, database schema information corresponding to a target data source, and semantic layer resources; performing normalization processing on the natural language query data; inputting the normalized query sentence into the large language model; constructing a retrieval unit set based on a query intent intermediate representation, and performing retrieval in a semantic layer resource set; based on the query intent intermediate representation and the semantic retrieval result set; generating an SQL main skeleton based on a compilable query intent intermediate representation and a template; calling an improved PICARD algorithm to perform a parser-in-the-loop multi-dimensional constraint incremental decoding processing on a to-be-generated SQL structure; and filling the constrained SQL segment into the to-be-generated SQL structure to generate a target SQL sentence. The application adopts an intent structuring and constraint decoding mechanism to realize controllable generation from natural language to SQL.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of natural language processing technology, and in particular to a method for generating intent-based structured SQL statements based on a large language model. Background Technology

[0002] As enterprise information systems and data platforms continue to expand, the types and structures of data stored in databases are becoming increasingly complex, leading to a growing demand from users to directly obtain data analysis results via natural language. Current technologies for generating SQL statements from natural language primarily rely on rule templates, statistical models, or deep learning-based semantic mapping models to directly convert natural language queries into executable SQL statements for querying and analyzing relational databases. These methods, to some extent, lower the barrier to entry for users writing SQL statements and improve the convenience of data access.

[0003] However, existing technologies generally suffer from insufficient characterization of query intent structure. Most solutions directly establish an end-to-end mapping relationship between natural language and SQL statements, lacking explicit structured expression of metrics, dimensions, conditions, time windows, and sorting constraints in the query intent. This results in low stability of the generated SQL statements in complex analysis scenarios. Furthermore, existing methods often perform syntax or permission checks after SQL generation, making it difficult to effectively constrain field validity, table join relationships, and business consistency during the generation process. This can easily lead to query statements that do not conform to database schemas or business rules.

[0004] Furthermore, in scenarios involving multi-table joins, complex filtering conditions, and access control, existing technologies have limited support for constraint mechanisms during the generation process. They typically lack the ability to introduce semantic layer resources and multi-dimensional constraints during the generation stage, making it difficult to guarantee the consistency and controllability between the generated SQL statement and the original query intent, thereby affecting the accuracy of query results and the availability of the system.

[0005] Therefore, how to provide an intent-based structured SQL statement generation method based on a large language model is a problem that urgently needs to be solved by those skilled in the art. Summary of the Invention

[0006] One objective of this invention is to propose a method for generating structured SQL statements based on a large language model. This invention constructs an intermediate representation of query intent and combines it with semantic layer resources to achieve structured parsing and normalization of natural language queries. Based on this, it generates the main SQL skeleton and completes field mapping and join path determination. Simultaneously, an improved PICARD algorithm is introduced in the SQL generation stage. Through a parser-in-the-loop multi-dimensional constraint incremental decoding mechanism, syntactic constraints, database schema validity constraints, query intent coverage constraints, and permission and consistency constraints are applied to the SQL fragments to be generated, thereby generating constrained SQL fragments and forming the target SQL statement. This invention comprehensively utilizes large language models, semantic retrieval, and constraint decoding techniques to achieve controllable generation of SQL statements from natural language queries, possessing high stability of generation results and clear meaning. Figure 1 It has the advantages of strong consistency and good business compliance.

[0007] According to an embodiment of the present invention, a method for generating intent-based structured SQL statements based on a large language model includes the following steps: Obtain the user's input natural language query statement and the database schema information and semantic layer resources corresponding to the target data source, and generate a set of natural language query data and semantic layer resources; Perform normalization processing on natural language query data to generate normalized query statements and corresponding time window descriptions; Input the standardized query statement into the large language model to generate an intermediate representation of the query intent; A set of retrieval units is constructed based on the intermediate representation of query intent, and the retrieval unit set is used to perform retrieval in the semantic layer resource set to generate a set of semantic retrieval results; Generate a compilable intermediate representation of query intent based on the intermediate representation of query intent and the set of semantic retrieval results; The SQL main skeleton is generated based on the compileable query intent intermediate representation template, and the SQL structure to be generated is obtained by combining the semantic retrieval result set. The improved PICARD algorithm is invoked to perform parser-in-the-loop multidimensional constraint incremental decoding on the SQL structure to be generated, generating constrained SQL fragments; The constrained SQL fragment is filled into the SQL structure to be generated, the target SQL statement is generated, and the target SQL statement is validated.

[0008] Optionally, the natural language query data includes the text content data of the natural language query statement, database schema information, and semantic layer resource set.

[0009] Optionally, the normalization process includes character-level cleaning, word segmentation and part-of-speech tagging, synonym normalization, unit normalization, time expression recognition, time window normalization, and query statement rewriting and generation.

[0010] Optionally, the step of inputting the normalized query statement into the large language model to generate an intermediate representation of the query intent specifically includes: Obtain the normalized query statement and the corresponding time window description, and generate the model input feature set; Based on the set of input elements of the model, construct large language model prompt information, input the large language model prompt information into the large language model, and obtain the intermediate representation of the generated candidate query intent. Perform structural integrity checks on the intermediate representation of candidate query intents and generate structural check results; Perform validity checks on the field values ​​of the candidate query intent intermediate representation and generate validity check results; When the structure verification result and the legality verification result meet the preset conditions, the intermediate representation of the candidate query intent is determined as the intermediate representation of the query intent.

[0011] Optionally, the step of constructing a set of retrieval units based on the intermediate representation of query intent, and using the set of retrieval units to perform retrieval in the semantic layer resource set to generate a set of semantic retrieval results specifically includes: Read the intent field, indicator field, dimension or entity field, condition field, time window field, sorting field and limit field from the intermediate representation of the query intent, and generate a set of search elements; A set of search units is constructed based on the set of search elements. Based on the set of search units, index retrieval processing is performed in the set of index dictionary entries to generate the first set of index candidates. Perform indicator applicability filtering on the first indicator candidate set to generate a second indicator candidate set, and generate a subset of indicator retrieval results based on the second indicator candidate set; Based on the entity retrieval unit set, perform entity retrieval processing in the entity alias entry set to generate a first entity candidate set. Perform standardized name mapping processing on the first entity candidate set to generate a subset of entity retrieval results. Based on the set of conditional field retrieval units, conditional field retrieval processing is performed in the set of field mapping entries to generate a first field candidate set. Field type consistency verification processing is then performed on the first field candidate set to generate a subset of field mapping retrieval results. Based on the set of sorting field retrieval units, sorting field retrieval processing is performed in the set of field mapping entries to generate a candidate set of sorting fields. Based on the candidate set of sorting fields, a subset of sorting field retrieval results is generated. The candidate table set is determined based on the subset of search results obtained from field mapping and the subset of search results obtained from sorting fields, and the connection relationship information is generated based on the database schema information. Based on the set of permission rule entries, permission constraint processing is performed on the subset of index search results, the subset of field mapping search results, and the subset of sorting field search results to generate permission constraint information; Based on the indicator caliber identifier in the subset of indicator retrieval results, caliber description matching is performed in the set of caliber description entries to generate indicator caliber information. The table field mapping information is generated by combining the retrieval subsets of indicator caliber information, field mapping information, and sorting field retrieval results with the table field mapping information. The semantic retrieval result set is then generated by summarizing the join relationship information, indicator caliber information, and permission constraint information.

[0012] Optionally, generating a compilable intermediate representation of query intent based on the intermediate representation of query intent and the semantic retrieval result set specifically includes: Obtain the intermediate representation of the query intent and the set of semantic search results, and generate a set of validation inputs; Based on the validation input set, a slot status set is constructed to generate an intermediate representation of the query intent. Conflict detection is performed on the intermediate representation of the completed query intent to generate a conflict set, and conflict resolution is performed on the conflict set to generate a resolved intermediate representation of the query intent. Perform field type validation on the intermediate representation of the query intent and generate a field type validation pass flag; Perform permission consistency verification on the intermediate representation of the query intent and generate permission consistency verification results. Perform consistency verification on the intermediate representation of the query intent and generate consistency verification results; When the field type validation passes the first preset condition, the permission consistency validation result meets the second preset condition, and the caliber consistency validation result meets the third preset condition, the intermediate representation of the dissolved query intent is determined as the compileable intermediate representation of the query intent.

[0013] Optionally, the step of generating the SQL main skeleton based on the compilable query intent intermediate representation template and combining it with the semantic retrieval result set to obtain the SQL structure to be generated specifically includes: Obtain a compilable intermediate representation of the query intent and a set of semantic retrieval results, and generate a set of SQL generation elements; Based on the intent field, perform template matching processing in the preset template index table to determine the SQL generation template; The SQL main skeleton is generated based on the SQL generation template. Based on the table field mapping information in the semantic retrieval result set, the indicator field mapping processing is performed to generate the indicator selection item set. Based on the table field mapping information in the semantic retrieval result set, perform dimension or entity field mapping processing to generate a set of dimension selection options and a set of grouping fields. Perform condition expression generation processing on the condition fields in the compileable query intent intermediate representation to generate a set of condition expressions; Perform time window expression generation processing on the time window field to generate time window filter expressions; perform sorting and restriction expression generation processing on the sorting and restriction fields to generate restriction expressions. The connection path is determined and the connection clause is generated based on the connection relationship information and permission constraint information in the semantic retrieval result set; The SQL main skeleton, indicator selection set, dimension selection set, condition expression set, time window filter expression, sorting expression, restriction expression, and join clause are summarized and filled to generate the SQL structure to be generated.

[0014] Optionally, the invocation of the improved PICARD algorithm to perform parser-in-the-loop multidimensional constraint incremental decoding processing on the SQL structure to be generated, and to generate constrained SQL fragments, specifically includes: Read and detect the SQL structure to be generated, determine the set of segments to be decoded, construct the decoding input set based on the set of segments to be decoded, and generate a multi-dimensional constraint set; The parser of the improved PICARD algorithm obtains a set of candidate generated symbols from the candidate generated set in the ring decoding state, and performs incremental concatenation processing on each candidate generated symbol to generate candidate SQL prefixes; Perform SQL syntax constraint validation on candidate SQL prefixes and set syntax availability flags for candidate generated symbols; Perform database schema validity constraint verification on candidate generated symbols that have a syntax availability flag, and obtain the database schema validity constraint verification result; Perform query intent coverage constraint validation on the candidate generated symbols that have passed the database schema validity constraint validation, and obtain the query intent coverage constraint validation result; Perform permission constraint verification and caliber consistency constraint verification on the candidate generated symbols that pass the query intent coverage constraint verification, and generate permission verification results and caliber verification results; Based on the syntax availability identifier, database schema validity constraint verification results, query intent coverage constraint verification results, permission verification results, and caliber verification results, an extensible candidate set is generated. The current SQL prefix is ​​updated based on the expandable candidate set until a constrained SQL prefix that meets the termination condition is generated, and then it is determined as a constrained SQL fragment.

[0015] Optionally, the step of filling the constrained SQL fragment into the SQL structure to be generated, generating the target SQL statement, and performing validation on the target SQL statement specifically includes: Obtain the SQL structure to be generated and the constrained SQL fragment, and determine the placeholder structure to be filled in the SQL structure to be generated that corresponds to the constrained SQL fragment, and generate a set of fill positions; Perform fragment filling processing on the set of filling sites to generate the target SQL statement; Perform syntax validation on the target SQL statement, generate syntax parsing results, and generate a syntax validation pass flag when the syntax parsing results meet the syntax parsing conditions; Perform database schema validation on the target SQL statement and generate the database schema validation result; Perform query intent alignment and validation processing on the target SQL statement to determine the set of intent elements; Extract the SQL feature set from the target SQL statement, perform feature matching processing on the intent feature set and the SQL feature set, and generate alignment verification results; The target SQL statement is output when the syntax validation pass indicator meets the syntax validation pass condition, the database schema validation result meets the schema consistency condition, and the alignment validation result meets the intention alignment condition.

[0016] The beneficial effects of this invention are: This invention introduces an intermediate representation of query intent between natural language queries and SQL statement generation. It provides an explicit, structured description of metrics, dimensions or entities, conditions, time windows, and sorting and constraint elements in user queries, eliminating the reliance on implicit end-to-end mappings for query intent. This approach decomposes, validates, and completes query semantics before SQL generation, ensuring the generation process is based on a clear and interpretable intent structure. This effectively reduces SQL structure errors caused by natural language ambiguity, field confusion, or semantic omissions, improving the stability and consistency of intent parsing in complex query scenarios.

[0017] This invention systematically introduces semantic layer resources during query intent parsing and SQL construction, and incorporates database schema information, indicator definitions, field mapping relationships, and permission rules into a unified retrieval and constraint framework. By completing field validity verification, connection path determination, definition consistency verification, and permission consistency verification during the generation phase, it avoids the uncontrollable problems caused by post-processing verification only after SQL generation in traditional solutions. This ensures that the generated SQL statements are consistent with the target data source in terms of structure, business semantics, and access permissions, which helps guarantee the correctness and compliance of query results.

[0018] This invention introduces an improved PICARD algorithm during the SQL fragment generation stage, employing a parser-in-the-loop multi-dimensional constraint incremental decoding mechanism. This mechanism integrates SQL syntax constraints, database schema constraints, query intent coverage constraints, business scope constraints, and permission constraints into the generation process, allowing for continuous verification and filtering of SQL statements as they are generated. This approach reduces the probability of expanding invalid candidate paths and improves the alignment between the generated results and the original query intent. Particularly in scenarios involving multi-table joins, complex condition combinations, and analytical queries, it effectively enhances the executability and reliability of the generated SQL statements. Attached Figure Description

[0019] The accompanying drawings are provided to further illustrate the invention and form part of the specification. They are used in conjunction with embodiments of the invention to explain the invention and do not constitute a limitation thereof. In the drawings: Figure 1 This is a flowchart of an intent-based structured SQL statement generation method based on a large language model proposed in this invention; Figure 2 This is a schematic diagram of the semantic retrieval process in the intent-based structured SQL statement generation method proposed in this invention; Figure 3 This is a schematic diagram of the constraint decoding process of the improved PICARD algorithm in the intent-based structured SQL statement generation method proposed in this invention. Detailed Implementation

[0020] The present invention will now be described in further detail with reference to the accompanying drawings. These drawings are simplified schematic diagrams, illustrating only the basic structure of the invention, and therefore only show the components relevant to the invention.

[0021] refer to Figures 1-3 A method for generating intent-based structured SQL statements based on a large language model includes the following steps: Obtain the user's input natural language query statement and the database schema information and semantic layer resources corresponding to the target data source, and generate a set of natural language query data and semantic layer resources; Perform normalization processing on natural language query data to generate normalized query statements and corresponding time window descriptions; Input the standardized query statement into the large language model to generate an intermediate representation of the query intent; A set of retrieval units is constructed based on the intermediate representation of query intent, and the retrieval unit set is used to perform retrieval in the semantic layer resource set to generate a set of semantic retrieval results; Generate a compilable intermediate representation of query intent based on the intermediate representation of query intent and the set of semantic retrieval results; The SQL main skeleton is generated based on the compileable query intent intermediate representation template, and the SQL structure to be generated is obtained by combining the semantic retrieval result set. The improved PICARD algorithm is invoked to perform parser-in-the-loop multidimensional constraint incremental decoding on the SQL structure to be generated, generating constrained SQL fragments; The constrained SQL fragment is filled into the SQL structure to be generated, the target SQL statement is generated, and the target SQL statement is validated.

[0022] In this embodiment, obtaining the user-input natural language query statement, the database schema information corresponding to the target data source, and semantic layer resources, and generating a set of natural language query data and semantic layer resources specifically includes: Receive natural language query statements input by users and generate text content data and session identifier data of the natural language query statements; The target data source identifier is determined based on the session identifier data, and the database connection information corresponding to the target data source is obtained according to the target data source identifier to generate the target data source connection configuration; Based on the target data source connection configuration, read the database metadata, extract the database object information and generate database schema information. The database object information includes at least table identifier, column identifier, column data type, primary key constraint, foreign key constraint and inter-table join relationship. Obtain the semantic layer resources corresponding to the target data source, and generate a semantic layer resource set according to the resource category. The semantic layer resource set shall include at least the indicator dictionary, entity aliases, field mapping relationships, definition descriptions and permission rules. Perform resource consolidation on the indicator dictionary to generate a set of indicator dictionary entries. The set of indicator dictionary entries includes at least the indicator identifier, indicator name, indicator scope identifier, set of field identifiers that the indicator depends on, and the aggregation method identifier that the indicator applies to. Perform resource balancing on entity aliases to generate a set of entity alias entries. The set of entity alias entries includes at least the entity identifier, the entity specification name, and a set of aliases associated with the entity specification name. Perform resource consolidation on the field mapping relationship to generate a set of field mapping entries. The set of field mapping entries includes at least semantic field identifiers, target table identifiers, target column identifiers, and field data type identifiers. Perform resource consolidation on the definition description to generate a set of definition description items. The set of definition description items should include at least the definition label, the definition scope label, the definition calculation constraint label, and the set of indicator labels corresponding to the definition label. Perform resource consolidation on the permission rules to generate a set of permission rule entries. The set of permission rule entries includes at least the permission subject identifier, the set of accessible field identifiers, the set of inaccessible field identifiers, and the de-identification processing identifier. Natural language query data is generated based on the text content data of natural language query statements, database schema information, and semantic layer resource sets.

[0023] In this embodiment, the natural language query data is normalized to generate a normalized query statement, and a corresponding time window description is generated, specifically including: Perform character-level cleaning processing on the natural language query statements in the natural language query data to generate cleaned query statements. The character-level cleaning processing includes at least the normalization of whitespace characters, the normalization of full-width and half-width characters, the normalization of punctuation marks, and the removal of abnormal characters. The cleaned query statement is processed by word segmentation and part-of-speech tagging to generate query word sequence and part-of-speech sequence, and candidate entity phrase set and candidate indicator phrase set are extracted based on the query word sequence; Based on the entity alias entry set and indicator dictionary entry set in the semantic layer resource set, the candidate entity phrase set and candidate indicator phrase set are subjected to synonym normalization processing to generate a normalized phrase set. The synonym normalization processing includes at least mapping alias phrases to entity normalized names and mapping indicator aliases to indicator names. Perform unit normalization on the cleaned query statement to generate a unit normalized query statement. The unit normalization process includes at least identifying numerical expressions and unit expressions, generating a set of numerical items and a set of value domain items, and mapping the unit expression to the standard unit identifier in the preset unit system. Perform time expression recognition processing on unit regularization query statements to generate a time expression set, which includes at least absolute time expression and relative time expression; Time warping is performed on the relative time expressions in the time expression set to generate a relative time window description. Based on the base time corresponding to the session identifier data, the relative time window description is time-converted to obtain the corresponding absolute time window description. The absolute time window description is used to represent the specific start and end time range of the relative time expression in the current query context. Perform interval extraction processing on the absolute time expressions in the time expression set to generate absolute time window descriptions, and then merge and deduplicate the absolute time window descriptions and relative time window descriptions to generate a time window description set; Based on the set of normalized phrases, the unit normalized query statement, and the set of time window descriptions, the cleaned query statement is rewritten and generated to produce a normalized query statement, and the set of time window descriptions is determined as the time window descriptions corresponding to the normalized query statement.

[0024] In this embodiment, inputting the standardized query statement into the large language model to generate an intermediate representation of the query intent specifically includes: Obtain the normalized query statement and the time window description corresponding to the normalized query statement, and obtain the indicator dictionary entry set, entity alias entry set and field mapping entry set from the semantic layer resource set to generate the model input element set; The large language model prompt information is constructed based on the model input element set. The construction process includes: writing the normalized query statement into the query statement area, writing the time window description into the time constraint area, writing the indicator names in the indicator dictionary entry set into the indicator candidate area, writing the entity normalized names in the entity alias entry set into the dimension or entity candidate area, and writing the semantic field identifiers in the field mapping entry set into the condition field candidate area and the sorting field candidate area; and then sequentially concatenating the above areas based on the preset prompt template to generate the large language model prompt information. Input the prompt information of the large language model into the large language model and obtain the output text of the model; perform structured parsing processing on the output text of the model, extract the data items corresponding to the preset field identifiers from the output text of the model, and generate intermediate representations of candidate query intents; wherein, the intermediate representations of candidate query intents include at least intent fields, indicator fields, dimension or entity fields, condition fields, time window fields, sorting fields, and restriction fields; Perform structural integrity verification on the intermediate representation of the candidate query intent and generate structural verification results. The structural integrity verification includes at least verifying whether the intermediate representation of the candidate query intent contains all or a preset subset of the intent field, indicator field, dimension or entity field, condition field, time window field, sorting field, and restriction field. The intermediate representation of the candidate query intent performs field value validity checks and generates validity check results. Field value validity checks include at least checking indicator fields based on the indicator dictionary entry set, checking dimension or entity fields based on the entity alias entry set, and checking condition fields and sorting fields based on the field mapping entry set. When the structure verification result and the legality verification result meet the preset conditions, the intermediate representation of the candidate query intent will be determined as the intermediate representation of the query intent. The preset conditions include structural integrity conditions, field value validity conditions, and time window consistency conditions; The structural integrity condition includes that the intermediate representation of the candidate query intent contains all or a preset subset of the intent field, indicator field, dimension or entity field, condition field, time window field, sorting field, and limit field; The validity conditions for field values ​​include that the value of the indicator field belongs to the indicator dictionary entry set, the value of the dimension or entity field belongs to the entity alias entry set, and the field identifiers referenced in the condition field and sorting field belong to the field mapping entry set. The time window consistency condition includes that the time window field in the intermediate representation of the candidate query intent is consistent with the time window description, and that the time range represented by the time window field does not conflict with the time constraints contained in the condition field.

[0025] In this embodiment, a set of retrieval units is constructed based on the intermediate representation of the query intent, and the retrieval unit set is used to perform a retrieval in the semantic layer resource set to generate a set of semantic retrieval results. Specifically, this includes: Read the intent field, indicator field, dimension or entity field, condition field, time window field, sorting field and restriction field from the intermediate representation of the query intent, and generate a set of search elements based on the above fields; A set of search units is constructed based on a set of search elements. The set of search units includes at least a set of index search units, a set of entity search units, a set of condition field search units, and a set of sorting field search units. Each search unit includes a corresponding field identifier and a field type identifier. Based on the set of indicator retrieval units, indicator retrieval processing is performed in the set of indicator dictionary entries. The indicator retrieval processing includes: performing name matching processing based on the indicator name or indicator identifier contained in the indicator retrieval unit to generate a first set of indicator candidates. Perform indicator suitability filtering on the first indicator candidate set, removing indicator entries that do not support the intent field or time window field in the query intent intermediate representation QIR, and generate the second indicator candidate set. Extract the indicator identifier, indicator definition identifier, and set of field identifiers that the indicator depends on from the second indicator candidate set to generate a subset of indicator retrieval results; Entity retrieval processing is performed in the entity alias entry set based on the entity retrieval unit set. The entity retrieval processing includes: performing alias matching processing in the entity alias entry set based on the entity name or entity identifier contained in the entity retrieval unit, and generating a first entity candidate set. Perform canonical name mapping processing on the first entity candidate set to generate a subset of entity retrieval results. The subset of entity retrieval results includes at least the entity identifier and the entity canonical name. Based on the set of conditional field retrieval units, conditional field retrieval processing is performed in the set of field mapping entries. The conditional field retrieval processing includes: based on the field identifiers contained in the conditional field retrieval units, performing field matching processing in the set of field mapping entries to generate a first set of candidate fields. Perform field type consistency verification on the first field candidate set, retain field entries whose field data type matches the operator type of the condition field, and generate a subset of field mapping retrieval results; Based on the set of sorting field retrieval units, sorting field retrieval processing is performed in the set of field mapping entries. The sorting field retrieval processing includes: based on the field identifiers contained in the sorting field retrieval units, performing field matching processing in the set of field mapping entries to generate a candidate set of sorting fields; Extract the target table identifier, target column identifier, and field data type identifier from the candidate set of sorting fields, and generate a subset of sorting field retrieval results; Based on the subset of search results from field mapping and the subset of search results from sorting fields, a set of candidate tables is determined. Then, according to the foreign key constraints and inter-table join relationships in the database schema information, a join path search is performed on the set of candidate tables to generate join relationship information. The join relationship information includes at least the identifier of the join start table, the identifier of the join end table, and the identifier of the join key field. Based on the set of permission rule entries, permission constraint processing is performed on the subset of index retrieval results, the subset of field mapping retrieval results, and the subset of sorting field retrieval results. The permission constraint processing includes: filtering the set of accessible field identifiers based on the permission subject identifier; removing entries corresponding to inaccessible field identifiers from the subset of index retrieval results, the subset of field mapping retrieval results, and the subset of sorting field retrieval results; and attaching desensitization processing identifiers to the field entries marked as requiring desensitization processing to generate permission constraint information. Based on the indicator caliber identifier contained in the subset of indicator retrieval results, caliber description matching processing is performed in the set of caliber description entries to extract the caliber description entries corresponding to the indicator caliber identifier and generate indicator caliber information. The table field mapping information is generated by combining the retrieval subsets of indicator caliber information, field mapping information, and sorting field retrieval results with the table field mapping information. The semantic retrieval result set is then generated by summarizing the join relationship information, indicator caliber information, and permission constraint information.

[0026] In this embodiment, generating a compilable intermediate representation of query intent based on the intermediate representation of query intent and the semantic retrieval result set specifically includes: Obtain the intermediate representation of the query intent and the semantic retrieval result set, and read the indicator caliber information, table field mapping information, connection relationship information and permission constraint information from the semantic retrieval result set to generate a validation input set; A slot status set is constructed based on the validation input set. The slot status set includes at least the intent field status, metric field status, dimension or entity field status, condition field status, time window field status, sorting field status, and restriction field status. Slot completion processing is performed on the slot status set. Slot completion processing includes: based on the table field mapping information in the semantic retrieval result set, completing the missing field type identifiers in the intermediate representation of the query intent to generate the first completion result. Based on the indicator definition information, the missing indicator definition identifiers in the intermediate representation of the query intent are completed to generate a second completion result. Based on the connection relationship information, the missing connection path identifiers in the intermediate representation of the query intent are completed to generate a third completion result; Based on the time window description, the missing values ​​of the time window field in the intermediate representation of the query intent are filled in to generate a fourth completion result; The query intent intermediate representation is updated based on the first, second, third, and fourth completion results to generate a complete query intent intermediate representation. Conflict detection processing is performed on the intermediate representation of the completion query intent to generate a conflict set. The conflict set includes at least field mapping conflicts, join relationship conflicts, indicator caliber conflicts, and permission conflicts. Perform conflict resolution processing on the conflict set. The conflict resolution processing includes: for field mapping conflicts, determine the target field mapping entry based on the field matching priority identifier in the table field mapping information, and replace the conflicting field mapping with the target field mapping entry to generate the first resolution result; For connection conflicts, the target connection path is determined based on the connection path length identifier in the connection relationship information, and the conflicting connection path is replaced with the target connection path to generate a second resolution result; For conflicts in indicator definitions, the target definition description item is determined based on the definition priority identifier in the indicator definition information, and the conflicting definition identifier is replaced with the target definition description item to generate a third resolution result. For permission conflicts, the set of accessible field identifiers is determined based on the permission constraint information, and the field items corresponding to the inaccessible field identifiers are removed from the intermediate representation of the complete query intent or replaced with field items with additional desensitization processing identifiers to generate the fourth resolution result; Based on the first resolution result, the second resolution result, the third resolution result, and the fourth resolution result, the intermediate representation of the query intent is updated and completed to generate the intermediate representation of the resolved query intent; The intermediate representation of the query intent is processed by performing field type validation. The field type validation process includes: determining the field data type identifier corresponding to each field item based on the table field mapping information. For each condition item in the condition field, verify whether the operator type identifier of the condition item matches the field data type identifier of the field referenced by the condition item, and generate a condition type verification result; For each sorting item in the sorting field, verify whether the data type identifier and sorting direction identifier of the field referenced by the sorting item meet the preset sorting type constraints, and generate a sorting type verification result. When the condition type validation result and the sort type validation result meet the preset conditions, a field type validation pass flag is generated; The intermediate representation of the query intent is processed to perform a permission consistency check. The permission consistency check includes: Based on the set of accessible field identifiers in the permission constraint information, the field identifiers referenced in the indicator field, dimension or entity field, condition field and sorting field all belong to the set of accessible field identifiers, and a permission consistency verification result is generated. The intermediate representation of the query intent is processed for consistency verification. The consistency verification process includes: determining the target caliber description entry corresponding to the indicator field based on the indicator caliber information; verifying that the indicator caliber identifier of the indicator field is consistent with the target caliber description entry, and verifying that the verification condition field and the time window field satisfy the caliber calculation constraint identifier in the target caliber description entry, and generating the consistency verification result. When the field type validation passes the first preset condition, the permission consistency validation result meets the second preset condition, and the caliber consistency validation result meets the third preset condition, the intermediate representation of the dissolved query intent is determined as the compileable intermediate representation of the query intent. The first preset condition is that the field type validation passes, the second preset condition is that the permission consistency validation passes, and the third preset condition is that the caliber consistency validation passes.

[0027] In this embodiment, the SQL main skeleton is generated based on the compilable query intent intermediate representation template, and combined with the semantic retrieval result set, the SQL structure to be generated specifically includes: Obtain the compileable query intent intermediate representation and semantic retrieval result set, and read the intent field, indicator field, dimension or entity field, condition field, time window field, sorting field and restriction field from the compileable query intent intermediate representation to generate the SQL generation feature set; Based on the intent field, template matching is performed in the preset template index table to determine the SQL generation template, wherein the template index table establishes a correspondence between the intent field and the SQL generation template identifier; The SQL main skeleton is generated based on the SQL generation template. The generation of the SQL main skeleton includes: generating placeholder structures for SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, and LIMIT clauses in sequence according to the clause order identifiers of the SQL generation template, thus obtaining the SQL main skeleton. Based on the table field mapping information in the semantic retrieval result set, indicator field mapping processing is performed on the indicator fields in the compileable query intent intermediate representation. The indicator field mapping processing includes: performing field matching processing on the table field mapping information based on the indicator fields to generate a candidate indicator field mapping set; determining the target indicator field mapping entries in the candidate indicator field mapping set according to the indicator caliber information; and writing the target indicator field mapping entries into the SELECT clause placeholder structure to generate an indicator selection item set. Based on the table field mapping information in the semantic retrieval result set, dimension or entity field mapping processing is performed on the dimension or entity fields in the compileable query intent intermediate representation. The dimension or entity field mapping processing includes: performing field matching processing on the table field mapping information based on the dimension or entity fields to generate a set of candidate dimension field mappings; determining the target dimension field mapping entries in the set of candidate dimension field mappings; writing the target dimension field mapping entries into the SELECT clause placeholder structure and the GROUPBY clause placeholder structure to generate a set of dimension selection items and a set of grouping fields. Perform condition expression generation processing on the condition fields in the compileable query intent intermediate representation. The condition expression generation processing includes: mapping the condition fields to target column identifiers based on table field mapping information, and determining the condition operator type based on the field data type identifier; writing the mapped target column identifier, condition operator type, and condition value into the WHERE clause placeholder structure or HAVING clause placeholder structure to generate a set of condition expressions. Perform time window expression generation processing on the time window field. The time window expression generation processing includes: determining the time field identifier based on the time window field, writing the time range corresponding to the time window field into the placeholder structure of the WHERE clause, and generating the time window filter expression. The sorting and constraint expression generation process is performed on the sorting field and the constraint field. The sorting and constraint expression generation process includes: mapping the sorting field to the target column identifier based on the table field mapping information, and writing the target column identifier and sorting direction identifier into the ORDERBY clause placeholder structure to generate the sorting expression; determining the constraint value based on the constraint field, and writing the constraint value into the LIMIT clause placeholder structure to generate the constraint expression. The process of determining and generating join clauses based on the join relationship information and permission constraint information in the semantic retrieval result set includes: identifying a set of candidate join paths that cover the target indicator field mapping entries and the target dimension field mapping entries from the join relationship information; filtering out join paths involving inaccessible field identifiers from the candidate join path set to generate a set of compliant join paths; determining the target join path from the set of compliant join paths, and generating a set of JOIN clauses based on the target join path and writing them into the FROM clause placeholder structure. The SQL main skeleton, indicator selection set, dimension selection set, condition expression set, time window filter expression, sorting expression, restriction expression, and JOIN clause set are summarized and filled to generate the SQL structure to be generated.

[0028] In this embodiment, the improved PICARD algorithm is invoked to perform parser-in-the-loop multidimensional constraint incremental decoding on the SQL structure to be generated, specifically generating constrained SQL fragments including: Read the SQL structure to be generated and detect whether there are multiple candidate field mappings, multiple candidate connection paths or complex condition expressions in the SQL structure to be generated. When a situation is detected, determine the set of segments to be decoded. The set of segments to be decoded includes at least one of the following: field mapping segments to be decoded, connection path segments to be decoded, or condition expression segments to be decoded. A decoding input set is constructed based on the set of fragments to be decoded. The decoding input set includes at least database schema information, a set of semantic retrieval results, a compilable intermediate representation of query intent, and a main SQL skeleton, and a multi-dimensional constraint set is generated. The parser of the improved PICARD algorithm is constructed in the ring decoding state. The parser in the ring decoding state includes at least the current SQL prefix, the candidate generation set, the parser state, and the constraint evaluation state, where the current SQL prefix is ​​the generated part of each segment to be decoded in the set of segments to be decoded. Obtain the candidate generation symbol set from the candidate generation set, and perform incremental concatenation processing on each candidate generation symbol, concatenating the candidate generation symbol to the end of the current SQL prefix to generate a candidate SQL prefix; Perform SQL syntax constraint verification on candidate SQL prefixes. The SQL syntax constraint verification includes inputting candidate SQL prefixes into the SQL syntax parser to generate parsing results, and setting a syntax-available flag for candidate generated symbols when the parsing results meet the grammatically parsable conditions. Perform database schema validity constraint verification on candidate generated symbols that have a syntax availability flag. The database schema validity constraint verification includes verifying whether the table identifier and column identifier referenced in the candidate SQL prefix exist in the database schema information based on the database schema information, and verifying whether the join key field identifier referenced in the candidate SQL prefix satisfies the foreign key constraint. Perform query intent coverage constraint verification on the candidate generated symbols that have passed the database schema legality constraint verification. The query intent coverage constraint verification includes determining the set of necessary intent elements based on the compilable intermediate representation of query intent, and verifying whether the candidate SQL prefix contains at least one item or its placeholder structure from the set of necessary intent elements. The set of necessary intent elements includes at least the selection options corresponding to the indicator field mapping, the grouping fields corresponding to the dimension or entity field mapping, the filtering expressions corresponding to the condition fields, the time window filtering expressions corresponding to the time window fields, and the sorting and restriction expressions corresponding to the sorting and restriction fields. For candidate generated symbols that pass the query intent coverage constraint validation, perform permission constraint validation and caliber consistency constraint validation. The permission constraint validation and caliber consistency constraint validation include: Based on the permission constraint information in the semantic retrieval result set, determine the set of accessible field identifiers, and verify that the field identifiers referenced in the candidate SQL prefix all belong to the set of accessible field identifiers, and generate permission verification results; Based on the indicator caliber information in the semantic retrieval result set, the target caliber description entries are determined, and it is verified whether the indicator field mapping referenced in the candidate SQL prefix is ​​consistent with the target caliber description entries. It is also verified whether the condition expression and time window filtering expression in the candidate SQL prefix meet the caliber calculation constraint identifier in the target caliber description entries, and caliber verification results are generated. Based on the syntax availability identifier, database schema legality constraint verification results, query intent coverage constraint verification results, permission verification results, and caliber verification results, the candidate generated symbols are filtered and sorted to generate an expandable candidate set. The current SQL prefix is ​​then updated based on the expandable candidate set until a constrained SQL prefix that meets the termination conditions is generated. The constrained SQL prefixes that meet the termination conditions are identified as constrained SQL fragments, and the constrained SQL fragments are output to fill the SQL structure to be generated.

[0029] In this embodiment, filling the constrained SQL fragment into the SQL structure to be generated, generating the target SQL statement, and performing validation on the target SQL statement specifically includes: Obtain the SQL structure to be generated and the constrained SQL fragment, and determine the placeholder structure to be filled in the SQL structure to be generated that corresponds to the constrained SQL fragment, and generate a set of fill positions; Fragment filling processing is performed on the set of filling sites. Fragment filling processing includes writing the constrained SQL fragment into the corresponding placeholder structure in the set of filling sites, and performing structure closure processing on the SQL structure to be generated to generate the target SQL statement. Perform syntax verification processing on the target SQL statement. The syntax verification processing includes inputting the target SQL statement into the SQL syntax parser to generate a syntax parsing result, and generating a syntax verification pass flag when the syntax parsing result meets the syntax parsing condition. Perform database schema validation on the target SQL statement. The database schema validation process includes verifying that the table identifiers and column identifiers referenced in the target SQL statement exist in the database schema information based on the database schema information, and verifying that the join key field identifiers referenced in the target SQL statement satisfy foreign key constraints, and generating database schema validation results. The query intent is processed to perform QIR alignment validation on the target SQL statement. This includes: Based on the intermediate representation of query intent (QIR), the intent element set is determined. The intent element set includes at least the query type identifier corresponding to the intent field, the set of indicator selection items corresponding to the indicator field, the set of grouping fields corresponding to the dimension or entity field, the set of condition expressions corresponding to the condition field, the time window filter expression corresponding to the time window field, and the sorting and restriction expressions corresponding to the sorting and restriction fields. Extract a set of SQL elements from the target SQL statement. The set of SQL elements includes at least the SELECT clause elements, FROM clause elements, WHERE clause elements, GROUP BY clause elements, HAVING clause elements, ORDER BY clause elements, and LIMIT clause elements. Perform feature matching processing on the intent feature set and the SQL feature set to generate alignment verification results. Feature matching processing includes verifying that the set of indicator selection items is consistent with the features in the SELECT clause, verifying that the set of grouping fields is consistent with the features in the GROUP BY clause, verifying that the set of condition expressions is consistent with the features in the WHERE clause or HAVING clause, verifying that the expression of time window filtering is consistent with the features in the WHERE clause, and verifying that the expression of sorting and restriction is consistent with the features in the ORDER BY clause and LIMIT clause. When the syntax validation pass indicator meets the syntax validation pass condition, the database schema validation result meets the schema consistency condition, and the alignment validation result meets the intent alignment condition, the target SQL statement is output for query execution.

[0030] Example 1: To verify the feasibility of this invention in practice, it was applied to a self-service analysis scenario in an enterprise-level data platform. In this scenario, business users do not directly write SQL, but instead submit query requests using natural language. For example, they might want to view a summary of a certain indicator within a specified time window by a certain dimension, then sort the results and retrieve the top few. Because the data platform has accumulated a large number of subject libraries and wide tables, there are complex relationships between tables, inconsistent field naming, multiple definitions for the same indicator, and overlapping field-level permissions and desensitization rules. Existing natural language to SQL conversion solutions typically use end-to-end generation, performing post-processing syntax or permission checks after the SQL output. When user expressions include multi-table joins, aggregation grouping, complex filtering, and time window constraints, issues such as SQL compilation failures, incorrect connection paths, mismatched field types, conflicts between indicator definitions and filter conditions, or referencing inaccessible fields can easily occur, leading to query failures or requiring multiple retries and manual corrections, affecting the stability and usability of self-service analysis.

[0031] In this scenario, the present invention uses the user's natural language query as the entry point, simultaneously reads the database schema information of the target data source, and loads a semantic layer resource set. The semantic layer resources include an indicator dictionary, entity aliases, field mappings, definition descriptions, and permission rules, used to map business expressions to database fields and provide definition and permission constraints. The system first standardizes the natural language query, completing cleaning, synonym normalization, unit normalization, and time expression recognition, converting relative time into an executable time window description, and forming a standardized query statement. Subsequently, the standardized query statement, along with candidate indicators, candidate entities, and candidate fields, is organized into prompt information and input into the large language model to generate an intermediate representation of the query intent, making indicators, dimensions or entities, conditions, time windows, sorting, and restrictions explicitly and structurally expressed. Based on this intermediate representation, a set of retrieval units is constructed, retrieving table field mappings, join relationships, indicator definitions, and permission constraint information from the semantic layer resources, completing the intent slots and resolving conflicts to obtain a compilable intermediate representation of the query intent. Then, the SQL main skeleton is generated by matching the SQL template according to the intent, and the SQL structure to be generated is formed by combining the semantic retrieval results. For fragments with multiple candidate field mappings, multiple candidate connection paths or complex condition expressions, the improved PICARD algorithm is called to perform parser-in-the-loop multidimensional constraint incremental decoding, so that the candidate generation simultaneously satisfies the requirements of syntactic parsing, pattern legality, intent coverage, permission consistency and caliber consistency during the generation process. Thus, the constrained SQL fragment is output and filled into the final SQL. Finally, after performing syntax verification, pattern verification and intent alignment verification, the output is executed.

[0032] To objectively demonstrate its beneficial effects, anonymized natural language query samples from this scenario were selected for comparative testing. The comparison object was the existing solution of "end-to-end generation + unified verification and interception after generation". Statistical criteria included the proportion of queries that could be executed on the first generation, the proportion where the generated result matched the intent elements, and the proportion requiring a second retry or manual correction. Average generation time was also recorded. Test results showed that the existing solution was more prone to compilation failures and connection / field errors in complex queries, leading to increased retry and manual correction rates. This invention, by completing the structured expression of intent and semantic retrieval constraints before generation and employing multi-dimensional constraint decoding during the generation stage, makes it easier for the generated SQL to pass compilation on the first attempt and align with the query intent. It also reduces failures caused by unauthorized references and conflicting criteria, thereby improving the stability and compliance of complex query scenarios and reducing overall interaction costs.

[0033] Table 1 Summary of Natural Language to SQL Conversion Performance Comparison

[0034] As can be seen from the table above, this invention significantly improves upon existing "end-to-end generation + post-verification" solutions in several key metrics of natural language to SQL generation. Firstly, in terms of first-time executability, this invention achieves 94.6%, an improvement of 18.2 percentage points compared to the existing solution's 76.4%. This indicates that by introducing an intermediate representation of query intent, semantic layer resource retrieval, and compilable intent construction before generation, this invention ensures that the SQL meets syntactic and pattern constraints during the generation stage, reducing the likelihood of "uncompilation failures discovered after generation." Correspondingly, the intent alignment rate of this invention reaches 95.1%, higher than the existing solution's 80.2%, an improvement of 14.9 percentage points. This demonstrates that by explicitly structuring indicators, dimensions or entities, conditions, time windows, sorting, and constraints, the generated SQL matches the elements of the original query intent more closely, reducing omissions or deviations.

[0035] Secondly, regarding the distribution of error types, this invention demonstrates more significant suppression of structural errors. The connection path error rate decreased from 9.8% in existing solutions to 1.9%, and the field / type error rate decreased from 10.7% to 2.3%, representing reductions of 7.9 and 8.4 percentage points, respectively. This aligns with the present invention's introduction of connection relationship information and field mapping information, along with type consistency verification, during the semantic retrieval stage. Simultaneously, during the constraint decoding stage, database schema validity constraints and intent coverage constraints are applied to candidate SQL prefixes, ensuring that candidates that do not meet the requirements for inter-table connection relationships or field types are eliminated in advance during the generation process. This reduces common sources of failure in multi-table joins and complex condition scenarios.

[0036] Furthermore, this invention demonstrates compliance advantages in business rule-related metrics. The failure rate due to conflicting definitions decreased from 6.5% to 1.2%, and the rate of unauthorized access decreased from 7.9% to 1.4%, representing reductions of 5.3 and 6.5 percentage points respectively. This indicates that the invention incorporates consistency between "metric definitions, filtering conditions, and time windows" and field accessibility into the generation process control through definition descriptions and the retrieval and constraint of permission rules, reducing failures due to inconsistent definitions or triggered permission interceptions after generation. Overall, the average number of retries decreased from 1.12 per record to 0.46 per record, and the manual correction rate decreased from 20.6% to 5.7%, indicating a significant reduction in the interaction and correction costs incurred by users to obtain usable SQL. Although the average generation time of this invention is 1580ms / item, slightly higher than the existing solution's 1420ms / item, this increase is mainly due to the overhead of semantic retrieval, completion resolution, and multi-dimensional constraint decoding during the generation process, combined with the decrease in first-time executability, retry count, and manual correction rate. Overall, it achieves higher executability and better performance. Figure 1 Consistency and business compliance.

[0037] The above are merely preferred embodiments of the present invention, but the scope of protection of the present invention is not limited thereto. Any equivalent substitutions or modifications made by those skilled in the art within the scope of the technology disclosed in the present invention, based on the technical solution and inventive concept of the present invention, should be covered within the scope of protection of the present invention.

Claims

1. A method for generating intent-based structured SQL statements based on a large language model, characterized in that, Includes the following steps: Obtain the user's input natural language query statement and the database schema information and semantic layer resources corresponding to the target data source, and generate a set of natural language query data and semantic layer resources; Perform normalization processing on natural language query data to generate normalized query statements and corresponding time window descriptions; Input the standardized query statement into the large language model to generate an intermediate representation of the query intent; A set of retrieval units is constructed based on the intermediate representation of query intent, and the retrieval unit set is used to perform retrieval in the semantic layer resource set to generate a set of semantic retrieval results; Generate a compilable intermediate representation of query intent based on the intermediate representation of query intent and the set of semantic retrieval results; The SQL main skeleton is generated based on the compileable query intent intermediate representation template, and the SQL structure to be generated is obtained by combining the semantic retrieval result set. The improved PICARD algorithm is invoked to perform parser-in-the-loop multidimensional constraint incremental decoding on the SQL structure to be generated, generating constrained SQL fragments; The constrained SQL fragment is filled into the SQL structure to be generated, the target SQL statement is generated, and the target SQL statement is validated.

2. The method for generating intent-based structured SQL statements based on a large language model according to claim 1, characterized in that, The natural language query data includes the text content data of the natural language query statement, database schema information, and semantic layer resource set.

3. The method for generating intent-based structured SQL statements based on a large language model according to claim 1, characterized in that, The standardization process includes character-level cleaning, word segmentation and part-of-speech tagging, synonym normalization, unit normalization, time expression recognition, time window normalization, and query statement rewriting and generation.

4. The method for generating intent-based structured SQL statements based on a large language model according to claim 1, characterized in that, The step of inputting the standardized query statement into the large language model to generate an intermediate representation of the query intent specifically includes: Obtain the normalized query statement and the corresponding time window description, and generate the model input feature set; Based on the set of input elements of the model, construct large language model prompt information, input the large language model prompt information into the large language model, and obtain the intermediate representation of the generated candidate query intent. Perform structural integrity checks on the intermediate representation of candidate query intents and generate structural check results; Perform validity checks on the field values ​​of the candidate query intent intermediate representation and generate validity check results; When the structure verification result and the legality verification result meet the preset conditions, the intermediate representation of the candidate query intent is determined as the intermediate representation of the query intent.

5. The method for generating intent-based structured SQL statements based on a large language model according to claim 1, characterized in that, The process of constructing a set of retrieval units based on the intermediate representation of query intent, and using this set of retrieval units to perform retrieval in the semantic layer resource set to generate a set of semantic retrieval results specifically includes: Read the intent field, indicator field, dimension or entity field, condition field, time window field, sorting field and limit field from the intermediate representation of the query intent, and generate a set of search elements; A set of search units is constructed based on the set of search elements. Based on the set of search units, index retrieval processing is performed in the set of index dictionary entries to generate the first set of index candidates. Perform indicator applicability filtering on the first indicator candidate set to generate a second indicator candidate set, and generate a subset of indicator retrieval results based on the second indicator candidate set; Based on the entity retrieval unit set, perform entity retrieval processing in the entity alias entry set to generate a first entity candidate set. Perform standardized name mapping processing on the first entity candidate set to generate a subset of entity retrieval results. Based on the set of conditional field retrieval units, conditional field retrieval processing is performed in the set of field mapping entries to generate a first field candidate set. Field type consistency verification processing is then performed on the first field candidate set to generate a subset of field mapping retrieval results. Based on the set of sorting field retrieval units, sorting field retrieval processing is performed in the set of field mapping entries to generate a candidate set of sorting fields. Based on the candidate set of sorting fields, a subset of sorting field retrieval results is generated. The candidate table set is determined based on the subset of search results obtained from field mapping and the subset of search results obtained from sorting fields, and the connection relationship information is generated based on the database schema information. Based on the set of permission rule entries, permission constraint processing is performed on the subset of index search results, the subset of field mapping search results, and the subset of sorting field search results to generate permission constraint information; Based on the indicator caliber identifier in the subset of indicator retrieval results, caliber description matching is performed in the set of caliber description entries to generate indicator caliber information. The table field mapping information is generated by combining the retrieval subsets of indicator caliber information, field mapping information, and sorting field retrieval results with the table field mapping information. The semantic retrieval result set is then generated by summarizing the join relationship information, indicator caliber information, and permission constraint information.

6. The method for generating intent-based structured SQL statements based on a large language model according to claim 1, characterized in that, The process of generating a compilable intermediate representation of query intent based on the intermediate representation of query intent and the set of semantic retrieval results specifically includes: Obtain the intermediate representation of the query intent and the set of semantic search results, and generate a set of validation inputs; Based on the validation input set, a slot status set is constructed to generate an intermediate representation of the query intent. Conflict detection is performed on the intermediate representation of the completed query intent to generate a conflict set, and conflict resolution is performed on the conflict set to generate a resolved intermediate representation of the query intent. Perform field type validation on the intermediate representation of the query intent and generate a field type validation pass flag; Perform permission consistency verification on the intermediate representation of the query intent and generate permission consistency verification results. Perform consistency verification on the intermediate representation of the query intent and generate consistency verification results; When the field type validation passes the first preset condition, the permission consistency validation result meets the second preset condition, and the caliber consistency validation result meets the third preset condition, the intermediate representation of the dissolved query intent is determined as the compileable intermediate representation of the query intent.

7. The method for generating intent-based structured SQL statements based on a large language model according to claim 1, characterized in that, The process of generating the SQL main skeleton based on the compilable query intent intermediate representation template, combined with the semantic retrieval result set, to obtain the SQL structure to be generated specifically includes: Obtain a compilable intermediate representation of the query intent and a set of semantic retrieval results, and generate a set of SQL generation elements; Based on the intent field, perform template matching processing in the preset template index table to determine the SQL generation template; The SQL main skeleton is generated based on the SQL generation template. Based on the table field mapping information in the semantic retrieval result set, the indicator field mapping processing is performed to generate the indicator selection item set. Based on the table field mapping information in the semantic retrieval result set, perform dimension or entity field mapping processing to generate a set of dimension selection options and a set of grouping fields. Perform condition expression generation processing on the condition fields in the compileable query intent intermediate representation to generate a set of condition expressions; Perform time window expression generation processing on the time window field to generate time window filter expressions; perform sorting and restriction expression generation processing on the sorting and restriction fields to generate restriction expressions. The connection path is determined and the connection clause is generated based on the connection relationship information and permission constraint information in the semantic retrieval result set; The SQL main skeleton, indicator selection set, dimension selection set, condition expression set, time window filter expression, sorting expression, restriction expression, and join clause are summarized and filled to generate the SQL structure to be generated.

8. The method for generating intent-based structured SQL statements based on a large language model according to claim 1, characterized in that, The invocation of the improved PICARD algorithm to perform parser-in-the-loop multidimensional constraint incremental decoding on the SQL structure to be generated, specifically to generate constrained SQL fragments, includes: Read and detect the SQL structure to be generated, determine the set of segments to be decoded, construct the decoding input set based on the set of segments to be decoded, and generate a multi-dimensional constraint set; The parser of the improved PICARD algorithm obtains a set of candidate generated symbols from the candidate generated set in the ring decoding state, and performs incremental concatenation processing on each candidate generated symbol to generate candidate SQL prefixes; Perform SQL syntax constraint validation on candidate SQL prefixes and set syntax availability flags for candidate generated symbols; Perform database schema validity constraint verification on candidate generated symbols that are set with syntax availability flags, and obtain the database schema validity constraint verification result; Perform query intent coverage constraint validation on the candidate generated symbols that have passed the database schema validity constraint validation, and obtain the query intent coverage constraint validation result; Perform permission constraint verification and caliber consistency constraint verification on the candidate generated symbols that pass the query intent coverage constraint verification, and generate permission verification results and caliber verification results; Based on the syntax availability identifier, database schema validity constraint verification results, query intent coverage constraint verification results, permission verification results, and caliber verification results, an extensible candidate set is generated. The current SQL prefix is ​​updated based on the expandable candidate set until a constrained SQL prefix that meets the termination condition is generated, and then it is determined as a constrained SQL fragment.

9. The method for generating intent-based structured SQL statements based on a large language model according to claim 1, characterized in that, The step of filling the constrained SQL fragment into the SQL structure to be generated, generating the target SQL statement, and performing validation on the target SQL statement specifically includes: Obtain the SQL structure to be generated and the constrained SQL fragment, and determine the placeholder structure to be filled in the SQL structure to be generated that corresponds to the constrained SQL fragment, and generate a set of fill positions; Perform fragment filling processing on the set of filling sites to generate the target SQL statement; Perform syntax validation on the target SQL statement, generate syntax parsing results, and generate a syntax validation pass flag when the syntax parsing results meet the syntax parsing conditions; Perform database schema validation on the target SQL statement and generate the database schema validation result; Perform query intent alignment and validation processing on the target SQL statement to determine the set of intent elements; Extract the SQL feature set from the target SQL statement, perform feature matching processing on the intent feature set and the SQL feature set, and generate alignment verification results; The target SQL statement is output when the syntax validation pass indicator meets the syntax validation pass condition, the database schema validation result meets the schema consistency condition, and the alignment validation result meets the intention alignment condition.