DistillQL

Quickstart

This page runs every part of DistillQL on a sample shop, a DuckDB file that needs no server. It takes about five minutes.

Install

pip install distillql

This is everything up to the last step. To let an AI app use DistillQL, the last step adds the MCP extra; a model on your own machine needs nothing more.

Write the sample shop

distillql demo

This writes ./distillql-demo with three files:

  • shop.duckdb: 200 customers and 3,000 orders. Some customers are test accounts, and some orders were refunded or cancelled.
  • history.jsonl: five queries the shop's analysts ran, with how often each ran.
  • distillql.yaml: the config, which names the database shop.

Crawl it

distillql crawl distillql-demo/distillql.yaml --out distillql-demo/context.yaml

The crawl reads each table's columns, comments and a sample of rows, and mines the query history. It writes what it found to context.yaml.

Read the glossary

distillql glossary distillql-demo/context.yaml

The glossary is one page of the shop's terms, drafted from the history. Part of it:

## Terms
- **revenue**: sum(orders.amount) where status = 'paid' @order_date (also joined to customers on customer_id and NOT customers.is_test) [shop.main: customers, orders] 52 runs; customers NOT is_test in 12/52 runs
- **orders**: count(*) of orders where status <> 'cancelled' @order_date [shop.main: orders] 25 runs; no customers row filter (0/25 runs)
- **customer** (also: customers): a row of customers where NOT is_test (inferred, 30 of 30 runs apply it; is_test: rows to exclude "internal test accounts; leave them out of customer counts" (history applies it in lookups 30/30 runs))

revenue counts paid orders only, because every query that computed it did so. Test accounts are left out of customer counts, because the column comment says to and every query does. An agent that guessed would count all orders.

Confirm what matters

distillql review distillql-demo/context.yaml

The review queue lists what a person should confirm, most useful first. Accept an item by its reference:

distillql review distillql-demo/context.yaml --accept measure:shop.main.orders.amount

An accepted definition outranks a drafted one. To approve, edit or strike the drafted terms with their evidence beside them, open the review page:

distillql review distillql-demo/context.yaml --browser

Glossary and review explains the queue and the page.

Run a query

distillql sql distillql-demo/distillql.yaml \
  "select c.region, sum(o.amount) as revenue from shop.main.orders o join shop.main.customers c using (customer_id) where o.status = 'paid' group by 1"

It prints the rows, then the explain record: the checks the query passed, what ran where and as whom, and where each column came from.

Ask a model on your machine

With Ollama running and a tool-capable model pulled (ollama pull gpt-oss:20b), DistillQL can run the conversation itself. Nothing else to install:

distillql ask distillql-demo/distillql.yaml "What is our total revenue?" --model gpt-oss:20b

The model reads the glossary, writes one query, and DistillQL prints its answer, the SQL and the rows. The model sees at most 20 rows of any result and no personal columns. Use any LLM covers LM Studio, cloud models and the limits.

Ask an AI app

Add the MCP extra, which lets an AI app start DistillQL and call its tools. Then, with Claude Code installed:

pip install 'distillql[mcp]'
claude mcp add distillql -- distillql mcp "$PWD/distillql-demo/distillql.yaml" --context "$PWD/distillql-demo/context.yaml"

Then ask Claude "What was revenue by region in September?" The glossary tells it that revenue counts paid orders only, and it runs its SQL through DistillQL as you. Connect an AI app covers other apps.

If your team uses dbt

Add dbt: to the engine that holds the dbt models, pointing at the project folder, and crawl again:

engines:
  shop: {kind: duckdb, path: shop.duckdb, dbt: ~/analytics}

DistillQL reads the files dbt parse writes into target/. Each dbt metric becomes a verified term, and model and column descriptions fill in missing comments. Definitions from dbt says what is read and what is left out.

To see what the history computes that dbt does not define, and where the two disagree, run gaps on a context crawled with dbt: set:

distillql gaps context.yaml

The sample shop has no dbt project, so on it gaps prints only:

No dbt project in this context. Add `dbt:` to an engine in the config and crawl again.

Next

Run distillql init to connect your own database.