The Problem: Hallucinations in NL2SQL

Natural Language to SQL (NL2SQL) systems often struggle with accuracy when mapping user intent to complex database schemas. The primary failure modes include referencing non-existent tables or columns (hallucination) and misinterpreting schema relationships. Standard prompt engineering often fails to enforce strict adherence to the underlying database structure, leading to broken queries that fail at execution time.

The SAL Approach: Live Schema Grounding

Schema-Aware Localisation (SAL) introduces a framework for real-time validation of SQL generation. Instead of relying solely on the LLM's internal knowledge of the schema, SAL forces the model to perform a 'grounding' step. This process involves:

  • Live Schema Mapping: The system dynamically injects relevant schema metadata into the context window, ensuring the model only references valid entities.
  • Hallucination Validation: SAL implements a secondary validation layer that checks the generated SQL against the actual database schema before execution. If the model attempts to query a column that does not exist or uses an incorrect join path, the system flags the error.
  • Iterative Correction: By identifying these schema-level mismatches, the system can provide targeted feedback to the LLM, allowing it to refine the query based on the specific constraints of the target database.

Impact on System Reliability

By moving schema awareness from a static prompt instruction to an active validation loop, SAL significantly reduces the rate of execution errors. This approach is particularly effective for 'Oracle' NL2SQL scenarios, where the system must be highly precise. The framework demonstrates that grounding the model in the actual database environment—rather than relying on semantic similarity alone—is the most effective way to ensure that generated code is both syntactically correct and logically sound according to the database's specific architecture.