a project by DkR.srl

Querying a Database in Natural Language: What Makes Answers Reliable

Contents

“How much did we sell in Central Italy last quarter?” It sounds like a simple question. Yet before providing an answer, a system needs to interpret at least three things: what “sold” means, which areas count as Central Italy, and which period “last quarter” refers to. If these definitions are not shared, an SQL query can run without errors and return a number that does not answer the question.

Querying a database in natural language means turning a request expressed in everyday words into a data query. In relational systems, this often involves text-to-SQL techniques, which generate a query from the question. But converting a sentence into SQL is only part of the process: a reliable answer also requires context, checks, and the ability to verify where it came from.

From question to query: the stages that really matter

A conversational interface hides the complexity of what happens behind the scenes. To assess its quality, it helps to follow the question all the way to the result, rather than simply checking whether a table or chart appears.

1. Understand the intent and identify ambiguous terms

The first step is to identify metrics, filters, dimensions, and the time range. “Active customers,” for example, may mean customers with a current contract, accounts that have placed at least one order, or those that have used the service within a given period. There is no universally correct definition: what matters is the one the business uses.

If the question does not include the necessary information, a reliable system should be able to ask for clarification or make its assumptions explicit, rather than silently choosing a definition.

2. Select the tables and map the relationships

A business management system may contain operational tables, historical archives, views, cancelled records, and relationships that are not immediately apparent from column names. Finding a table with a “revenue” field is not enough: you need to understand whether it represents the right value, whether the data is up to date, and how it connects to other entities. Even a formally valid JOIN can duplicate records or attribute values to the wrong entity.

Microsoft Fabric documentation recommends pairing questions with consistent query examples and spelling out complex join and calculation logic. When the same intent is associated with incompatible tables or aggregations, the system may produce different results even for equivalent questions.

3. Apply the business context

The database describes the structure and holds the information. Business rules explain how to interpret it: which definition of revenue to use, which order statuses to exclude, how to handle returns and credit notes, and which organisational units to include in scope. Without this semantic layer, the system has to guess.

We explored the distinction between technical structure and business meaning in “AI Can Read Your Database. But Does It Understand What Your Data Means?”. The point is not to add more text to the prompt, but to make sufficiently precise, up-to-date definitions and relationships accessible.

4. Generate and review the query

Only once the previous steps have been addressed does it make sense to translate the request into SQL. The query must use the dialect supported by the database, stay within the permitted data scope, and correctly apply filters, groupings, and aggregations. A syntax check can prevent invalid SQL from running, but it does not prove that the question has been interpreted correctly.

5. Execute, compare, and present the result

The final number needs to be read alongside the metric, time period, filters, and source of the information. For critical questions, it is useful to be able to inspect the generated query, compare it with a verified reference, or have the data team review it. Only then can the answer become a reasonable basis for analysis.

Example: a correct query that answers the wrong question

For illustration, imagine a sales management system with three tables: orders, invoices, and customers. A manager asks, “What was our revenue in September?” The system might add up the value of confirmed orders or the value of issued invoices. Both queries can be valid, but they measure different things.

Suppose the business defines revenue as the total value of issued invoices, net of credit notes. If this definition is not provided, the system might choose orders because that table is easier to identify. The error would not appear as a database message: it would show up as a plausible metric that does not follow the business rule.

This example does not describe a test performed on DataTalk or a customer result. It illustrates why the reliability of natural language querying needs to be assessed on the meaning of the answer, not just on whether the SQL runs successfully.

What to check before connecting AI to an existing business management system

For a software company, the practical question is not just “Can we add a chat interface?” but “What conditions are needed to make data querying manageable in our customers’ software?” The business management system can continue performing its operational functions while a specialised component handles the conversation with the data. However, the effectiveness of the integration depends on the architecture and the quality of the available context.

When evaluating a solution, you need to clarify who maintains metric definitions, how legacy tables and complex relationships are handled, which roles can query which data, whether queries are observable, and how unexpected answers are identified. It is equally important to establish how the context will be updated when the schema, rules, or versions of the business management system change.

A demo test with three clearly named tables says little about the complexity of a real database. A credible assessment should include ambiguous questions, non-trivial joins, shared metrics, and cases that require clarification. Google Cloud describes approaches such as selective metadata retrieval, semantic context, and query validation; none of these mechanisms should be assumed to be present in a platform without checking the product.

Where DataTalk fits into the process

DataTalk lets users query SQL databases through natural language requests. The official DataTalk Public API documentation describes endpoints for sending conversational requests, generating SQL queries, and exploring databases and table metadata. This makes it possible to assess integration with existing applications and business management systems without assuming that every project requires rewriting the software.

The availability of these endpoints alone does not establish how the platform handles every situation discussed in this article: ambiguity resolution, permission management in the specific context, traceability, and behaviour on complex schemas need to be verified in the real use case. For software developers, the most useful starting point is a concrete business question, together with the database and explicit criteria for assessing whether the answer is correct.

You can explore the documented capabilities in the DataTalk API and request a demo based on a question that your business management system cannot currently answer easily.

a project by DkR.srl