What is turning a question into a query?
Company data lives in tables, and is asked for in a query language that most people do not write. A model can translate a plain question into a query, if it is shown the map of the data: which tables exist, what each column means, and how the business defines its terms.
The model only writes the query. Code decides whether it may run: read-only access, an allowed list of tables, a time limit, and rules about who may see which rows. The model never does the arithmetic. The database does, and code formats the result.
The dangerous failure is a query that runs and is wrong, such as one that counts every order twice. So answers are shown with their working: what was counted, over which dates, with which filters.
These systems are tested with questions whose correct result is known, comparing the returned numbers and not the wording of the query.
Why does turning a question into a query matter?
Most of a company's facts live in databases, and most people cannot write the queries that get them out. Letting someone ask in plain words and receive a real number removes a long queue. The difficulty is not getting an answer. It is getting one that is right, since a query can run perfectly and still be wrong.
How does turning a question into a query work?
- The app shows the model a map of the data: the relevant tables, what each column means, a few real rows.
- It adds the business's own definitions of its terms, and a few worked examples.
- The model writes a query. It does not answer the question.
- Code checks the query is read-only and allowed, then runs it on a copy of the database.
- Code checks the result is plausible, and shows the number with its working in plain words.
When should you use turning a question into a query?
Use it when
- People need facts from structured data
- Questions vary too much for fixed reports
- The business can say precisely what its terms mean
Think twice when
- Definitions are unsettled. Different people will get different numbers
- The question is why something happened. The data reports. It does not explain
Where does turning a question into a query sit in a real system?
The model sits between the person and the database, and never touches the data. Safety belongs to the database: a read-only user, a separate copy, and hidden tables and columns for each role.
What goes wrong with turning a question into a query?
- Letting the model write the number into the sentence, where it can be copied wrongly.
- Treating "the query ran" as "the answer is right".
- Putting all 140 tables into the prompt.
What does turning a question into a query look like in practice?
"What was our revenue last month?" First the model invented $84,000. With the schema, the definition of revenue and three examples, it wrote a query. The database returned $71,610, shown with its working: paid orders, less $2,940 of refunds, 14 test orders left out.