LLM SQL Generation With Reinforcement-Learned Error Correction

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Existing large language models (LLMs) face challenges in generating accurate structured query language (SQL) responses, particularly due to errors, hallucinations, and the need for extensive training data, which complicates the conversion of natural language queries into SQL.

Innovation Solution

A two-tiered approach using a powerful LLM for inference and a smaller, trainable LLM to correct errors through reinforcement learning, leveraging a reward metric and a solver to improve the accuracy of SQL generation.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Adaptability or versatility

If a single large language model is used for SQL generation, then the model can provide human-like responses and handle complex queries, but the model produces errors and hallucinations that reduce accuracy

Engineering Contradiction:
Improvequery handling capabilityVSAvoidresponse accuracy
Core Design Contradiction:
Adaptability or versatilityVSReliability

Solution Approach 1:

The system divides the SQL generation task into two separate models: a large language model for generating candidate SQL queries and a smaller verifier model for checking and correcting them. This segmentation allows each model to specialize in its strength while compensating for the other's weaknesses.

Inventive Principle:
Principle #1Segmentation

Solution Approach 2:

The verifier model acts as an intermediary between the language model's output and the final SQL query. It receives candidate queries, validates them against the database schema, and corrects errors before the queries are executed, thereby improving reliability.

Inventive Principle:
Principle #24Intermediary (Mediator)

2Reliability

If extensive training data is used to improve SQL generation accuracy, then the model's performance improves, but the complexity and resource requirements increase substantially

Engineering Contradiction:
ImproveSQL generation accuracyVSAvoidtraining data requirements
Core Design Contradiction:
ReliabilityVSDevice complexity

Solution Approach 1:

Instead of training a large model on extensive SQL-specific data, the system uses a smaller verifier model that copies and validates the structural patterns from the database schema. This approach achieves accuracy without requiring massive training datasets.

Inventive Principle:
Principle #26Copying

Solution Approach 2:

The system replaces the mechanical approach of training large models with extensive data with a validation-based approach. The verifier model uses rule-based checking and schema validation to ensure accuracy without relying on large-scale training.

Inventive Principle:
Principle #28Mechanics substitution (Replace mechanical system)

3Ease of operation

If a powerful large language model is used for inference, then the model can handle complex natural language queries, but the model generates more hallucinations and errors

Engineering Contradiction:
Improvenatural language processing capabilityVSAvoidquery generation accuracy
Core Design Contradiction:
Ease of operationVSManufacturing precision

Solution Approach 1:

The system segments the query processing into generation (handled by the large language model) and validation (handled by the smaller verifier model). This allows the large model to focus on understanding natural language while the verifier ensures precision.

Inventive Principle:
Principle #1Segmentation

Solution Approach 2:

The verifier model provides feedback to the language model by identifying and correcting errors in generated queries. This feedback loop improves the overall accuracy by allowing the system to learn from and correct its mistakes.

Inventive Principle:
Principle #23Feedback

Data Source

PatentUS12596707B2Structured query language generation using large language models
Publication Date: 2026.04.07 CISCO TECHNOLOGY INC
  • US12596707B2 patent drawing
  • US12596707B2 patent drawing
  • US12596707B2 patent drawing

AI summary

In one embodiment, a method herein comprises: inputting, by a device, an input prompt to a first large language model to generate an output; computing, by the device, a reward metric in part by using a solver to process the output; tuning, by the device and based on the reward metric, a second large language model configured to correct errors of the first large language model using reinforcement learning; and using, by the device, the second large language model to correct an error of the first large language model.