A governed metric layer for reliable natural-language questions about data

An "ask your data" box that answers only through defined metrics, shows the definition behind every number and asks back when a question is ambiguous, benchmarked against an LLM writing SQL on the raw tables of a real marketplace.

Background

Ask a language model for last quarter's revenue against a raw database and it will write SQL that runs and returns a number. Whether the number is right depends on things the tables don't say: whether cancelled orders were removed, whether joining payments to items counted each order twice, which date puts an order in the quarter. The answer looks the same either way.

This question box only answers through defined metrics. Each metric is written down once, with its SQL, the filters that always apply and the ways it can be broken down. The model chooses metrics rather than writing SQL, shows which definition it used, and asks back when a question could mean more than one thing.

Data

Olist's Brazilian e-commerce data: about 100,000 marketplace orders from 2016 to 2018 in nine linked tables (CC BY-NC-SA 4.0). Orders have several item and payment rows, every order gets a new customer key, and there are five order dates and two kinds of location, so plausible SQL is easy to get wrong.

How it works

  • Metric definitions. Thirty-one metrics, each written once: description and synonyms, measure, grain and join path, mandatory filters, allowed dimensions and dates, and the terms that need a choice before answering.
  • Compiler. Turns a request for a metric, dimensions, filters and period into SQL and runs it in DuckDB in the browser. Anything undefined is refused rather than improvised.
  • Model. Works only through tools: list metrics, describe one, query one, or ask the user a clarifying question.

Evaluation

About 120 questions written in advance: straightforward ones, trap questions that are only right if the joins and filters are handled, ambiguous ones that should get a clarifying question, and out-of-scope ones that should be declined. Three setups answer them on a large and a small model: SQL on the raw tables, SQL with a written data dictionary, and the metric layer. Each is scored on correct answers, confidently wrong answers, clarifications and refusals where they were due, agreement across repeated runs, and cost.

Demo

The question box: ask about the marketplace's orders, customers and deliveries and get the number with the definition behind it, the filters applied and the SQL, or a clarifying question to answer first. Beside it, the metric catalogue and the benchmark results, with examples of each setup's confident mistakes.

The benchmark uses one marketplace's data and questions written for it, so it shows how the setups compare here rather than on every dataset.