Database Dictionary for LLM Query Code Generation
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Conventional large language models (LLMs) struggle to generate query code that is specific to a target database, often producing syntactically correct but unusable SQL queries due to lack of alignment with the database schema, leading to errors and the need for substantial rework by database administrators.
Innovation Solution
A database dictionary system that maps natural language phrases to query code, leveraging prompt engineering and fine-tuning of LLMs, includes a database dictionary definition that provides summary information, table groups, attributes, lookups, phrases, aliases, joins, unions, and comments, enabling the generation of context-aware and executable query code tailored to a specific database.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Reliability
If a conventional LLM is used to generate query code from natural language input, then the model can produce syntactically correct code outputs, but the code is not aligned with the specific database schema and cannot be executed on the target database
Solution Approach 1:
The system performs preliminary action by constructing a database dictionary that contains schema information, table definitions, column names, data types, and relationships before the LLM generates query code. This pre-prepared contextual information is then provided to the LLM during code generation, ensuring the output is aligned with the specific database schema without requiring complex post-processing or validation steps.
Solution Approach 2:
The database dictionary serves as an intermediary between the natural language input and the LLM. It translates and structures the database schema information into a format that the LLM can effectively use to generate accurate query code. The dictionary acts as a bridge that connects the generic LLM capabilities with the specific database context, enabling reliable code generation without modifying the LLM itself.
2Adaptability or versatility
If the LLM output is constrained to be specific to a target database, then the query code becomes executable and context-specific, but the system requires additional components like database dictionary construction and schema integration
Solution Approach 1:
The database dictionary is designed as a universal component that can work with any target database schema. It provides a standardized interface and structure that accommodates different database types, table configurations, and relationships. This multi-functional approach allows the same system architecture to adapt to various databases without requiring database-specific customization, thereby reducing overall system complexity while maintaining high adaptability.
Solution Approach 2:
The system performs preliminary action by automatically constructing the database dictionary from the target database schema before query generation. This pre-processing step extracts and structures all necessary schema information, making it readily available for the LLM. By doing this preparation work in advance, the system avoids the need for complex real-time schema analysis during query generation, simplifying the overall architecture.
3Productivity
If natural language input is mapped directly to query code without database context, then the process is simple and fast, but the generated code is generic and unusable for specific databases
Solution Approach 1:
The system performs preliminary action by pre-construction of the database dictionary containing all schema information. This preparation is done once and cached, so during query generation, the LLM can quickly access the necessary context without time-consuming schema analysis. This approach maintains fast query generation speeds while ensuring the output is database-specific and usable.
Solution Approach 2:
The database dictionary serves as an intermediary that is efficiently integrated into the query generation process. It provides contextual information in a structured format that the LLM can quickly process, maintaining fast generation speeds. The dictionary acts as a ready-reference guide that enables the LLM to produce usable, database-specific code without adding significant overhead to the generation process.
Data Source
AI summary
According to some aspects, systems and methods for optimizing the mapping and translating of natural language phrases into query code (e.g., SQL) via Generative AI are provided. Various embodiments employ optimizations to resolve at least some of the known issues with conventional LLM usage. Various embodiments are configured to leverage prompt engineering and/or fine tuning of a generative AI model to optimize the translation of natural language into code. For example, a database dictionary system manages creation of a database dictionary that describes an existing database target to a model. The database dictionary can be used as part of a query prompt input to an LLM. Employing the database dictionary, the output of the LLM is optimized for the specific database/context responsive to any request provided by a user. In various embodiments, the database dictionary is constructed and supplied to the LLM as part of a query prompt.


