Request a demo
← All articles How it works

Inside the SQL engine: plan, generate, validate, execute, review

How InsightAsk turns a question about data into a read-only query it can stand behind: indexed and profiled tables, a planning step, validation checks, a repair loop, and verified examples that ground the next question.

Natural-language questions about data are where AI assistants are most impressive and most dangerous. A plausible query that joins the wrong table or drops a filter returns a confident, wrong number. InsightAsk's SQL engine is built to make that hard: the model writes the query, but it works from a profiled index of your tables, every query is checked before it runs, and the engine records whether it got it right first time.

In short

Building a Space indexes and profiles its tables. A question is planned (tables, measures, groups, filters), turned into SQL for that source, validated (parsed, read-only, known tables and columns, a row limit), run, and reviewed. A failed check goes back to the model with the reason, a bounded number of times. Verified examples from your team ground the next generation.

Before any question: the index

When a Space is built, each table from its sources is indexed and profiled. Columns are classified as identifiers, dates, measures and dimensions from their names and values; tables are classed as facts or dimensions; empty tables are marked so the engine is told not to use them. Glossary terms can be bound to columns so the team's words (case reserve, date of loss) map to the right fields. The Indexed tables tab shows all of this, with a box that shows which tables the engine would retrieve for a given question.

The checks before a query runs

CheckWhat it catches
ParsedSQL that is not valid for the source's dialect
Read-onlyAnything that would change data: queries are read-only
Tables in contextA table the model invented, or one outside the Space
Columns resolvedA column that does not exist, with a did-you-mean hint for the repair
Row limitA missing limit is added and an excessive one is capped

If a check fails, the failure is turned into a plain sentence and sent back to the model to repair the query, a bounded number of times. The engine counts how many questions were right first time, how many needed repair and how many failed, and the average time to rows. Those counters sit at the top of the SQL engine screen, per Space.

The stricter gates, for queries that run fine and are still wrong

The checks above catch queries that would fail. The harder defects are queries that run and return the wrong number: a join that doubles rows, a filter on the wrong date. The engine's default (full) verification adds gates for those:

  • A plan first when more than one table is in play: the grain, the joins and the filters, before any SQL.
  • A clarifying question instead of a guess, when two readings of the question would give different numbers. The run stops and asks.
  • Strict columns: unknown columns, unknown aliases and joins with no condition are caught before the database sees the query.
  • A review of risky queries (joins or aggregates) against the plan, looking for exactly the defects that run and mislead.
  • Data probes: when review rejects a query or it returns no rows, up to three small read-only checks of the data, fed into the retry.
  • A labelled fallback: when the attempts run out, the least-criticised query that did run is returned with its review findings, rather than nothing.

By default a question gets three trips round generate, validate, run and repair, and returns at most 500 rows. Both limits are deployment settings. An overview question ("claims trends for this broker") can be answered in several parts, each with its own plan, checks and review.

A repair, step by step

An illustration with a made-up claims table. Someone asks "average days from loss to report for open claims".

  1. The plan names one table, an average of the gap between two dates, and a filter on status.
  2. The first query uses a column called loss_date. Validation fails: no such column, did you mean date_of_loss?
  3. That sentence goes back to the model, which repairs the query. It parses, reads only, names known columns and has a limit.
  4. It runs, and the answer comes back with its SQL. The run is counted as repaired, not right first time.

A glossary term binding date of loss to date_of_loss, or a verified example using it, makes the next similar question more likely to be right first time.

Verified examples

The single most effective way to make answers right is to show the engine what right looks like. A Space's Examples are questions the team expects it to answer well, with the SQL that answers them; they appear as starters in Ask, and verified examples are retrieved as guidance when a similar question comes in. Golden examples are used to check the Space: run them after a change and see whether the answers still match.

The Examples tab of the Claims desk space with three verified examples: how many claims are open, total reserve on open claims by cause of loss, and which adjuster has the most open claims, each with its SQL.
Three verified examples for a made-up claims Space, each with the SQL that answers it.

You can always see, and run, the query

An answer from the facts plane comes with its SQL. In Explore you can open the same connection, browse to the table, and run that query (or your own) directly, to see exactly the rows behind a figure.

The Explore screen with a SQL query grouping open claims by cause of loss with claim count, reserve and paid, and the result table below it.
Running a query by hand in Explore against a made-up claims table: open claims by cause of loss, with reserve and paid.
A model is needed to write queries. Planning and generating SQL from a question uses the language model your deployment configures. Indexing, profiling, validation, execution and the query history do not.

Writing verified examples that help

  • Use the team's own wording, abbreviations included, not a tidied version.
  • Cover each table and each common join at least once, so retrieval has something close to most questions.
  • Include the filters people forget to say out loud: "open" claims, the current policy year, a business unit.
  • Keep the SQL simple and readable; it is guidance for the next query, and people will read it.
  • Re-check examples after a schema change. An example that names a dropped column teaches the wrong thing.

What to watch as a Space matures

  • Right first time rising as verified examples and glossary bindings are added.
  • Repairs clustering on one table or column: usually a naming problem a glossary term fixes.
  • Failures on questions the Space was never meant to answer: a sign to widen its sources, or to say so in its description.

Next: how access is enforced before anything is retrieved.

See it on your own sources

Bring one folder and one table

We'll set up a Space on your own sources and show how each answer is computed or quoted, with the access rules your sources already have, as a hosted trial or inside your own cloud.

Request a demo