Natural Language to SQL queries to Business Insights for Dummies with a demo

It’s a busy day at the office, and you immediately need certain insights, let’s say about top agents or top regions of the last quarter, or you want to generate a leads list based on a certain business logic. In the pre-AI civilization era, you had to send the request to the corresponding person via email or communicate your requirement in a meeting or a call. Evolution in foundational LLMs has given rise to numerous use cases. Still, one of the most important skills for business decision-makers is the ability to obtain data or results directly from the communication between the LLM and databases. With an apt description of what is needed, the employee can get fuel (data) to communicate and act on their decisions with their team. The industry-wide phrase for this kind of use case is known as Text to SQL.

Let’s jump into our demo:

Fig 1:The architecture involved in our demo

Architecture Explanation: Enabling Natural Language BI with LLMs

This system architecture showcases how organizations can leverage a Large Language Model (LLM) to simplify access to business insights by allowing users to ask questions in plain English. The LLM intelligently translates these natural language questions into SQL queries that run against the business database, making business intelligence more accessible, intuitive, and efficient.

1. Starting with the User

At the heart of this architecture is the user, who could be a business analyst, sales executive, operations manager, or anyone seeking data-driven insights. Traditionally, such users would require SQL expertise or depend on data teams to access information. However, in this system, users simply enter their questions in natural language, for example, “What were the total sales in Q1?” or “Which region had the highest customer churn?”

These questions are referred to as BI questions; they represent common inquiries stakeholders make to better understand performance, trends, or operational bottlenecks.

2. The Role of the LLM

Once a BI question is submitted, it flows into the Large Language Model (LLM). The LLM is the intelligent core of the system, trained to understand natural language and capable of converting questions into structured SQL queries.

But the LLM doesn't generate SQL blindly. It needs to understand the underlying database schema, that is, the structure, names, and relationships of the tables it’s working with. This is where table metadata comes into play.

3. Using Table Metadata for Context

The table metadata includes details such as:

  • Table names and their purposes (e.g., customers, orders, transactions)

  • Column names and their data types

  • Relationships between tables (e.g., foreign keys, primary keys)

This metadata is fed into the LLM so it can accurately generate SQL queries that conform to the specific structure of the business’s database.

For example, if the user asks, “How many new customers joined last month?”, the LLM uses the metadata to determine which table stores customer data, identify a relevant date column (like signup_date), and write a query that correctly filters and counts new entries from the last month.

4. Generating and Executing SQL

Once the LLM has both the question and the table structure, it constructs a SQL query tailored to extract the required data from the business database.

The system then executes this generated SQL query directly on the business database. The database returns the result of the query, which could be a number, a list of records, or even an aggregated summary.

5. Returning Results to the User

The final output, the result of the query, is sent back to the user in a readable format. This can be presented as plain text, a table, a chart, or integrated into a dashboard, depending on how the system is configured.

This result answers the user's original question, completing a full cycle from natural language input to actionable data insight, all without the user needing to write a single line of SQL.

Why This Matters

Users no longer need to rely on data engineers or BI teams for routine questions. It empowers non-technical users to interact with complex databases using a language they already know, while the LLM handles the complexity behind the scenes.

By combining natural language processing with database metadata and real-time SQL generation, organizations can:

  • Enable faster decision-making
  • Democratize data access
  • Reduce the backlog of ad-hoc data requests
  • Improve efficiency across teams

To work on similar and various other AI use cases, connect with us at

https://www.lotuslabs.ai/

To work on computer vision use cases, get to know our product Padme

https://www.padme.ai/

Blog Posts