Skip to content

Demo Data (CLI-first)

The demo is three SQLite databases, registered as three datasources. Chinook, a small digital music store, leads; it is vendored in the wheel (MIT, v1.4.5, 1.02 MB). Beside it are support, a help-desk ticketing system (about 232 KiB), and webanalytics, website traffic (about 284 KiB). Both hold synthetic data generated by this repository from a fixed seed (scripts/generate_demo_datasets.py), so a regeneration reproduces exactly what is committed and no third-party data is involved in either. All three are shipped in the wheel and copied into your project by the CLI, so no data is downloaded or built when you set the demo up. The tables, columns and row counts are in Demo datasets.

To see it before installing anything, the same web app runs at https://nl2sql.codewithnk.com, where you bring your own model key.

What to expect

nl2sql demo is a launcher

nl2sql demo starts nl2sql-api serve --demo in a child process, waits until the server answers and opens http://127.0.0.1:8765/ in your browser (Ctrl+C stops both). Its flags are --dir, --host, --port and --no-browser. The command takes no key, recording or hosting options: put a key in the environment or the project's .env, or enter it in Settings, and run the public variant with nl2sql-api serve --demo --hosted. The web app guide is Web app.

After pip install "nl2sql-cli[web]" and nl2sql demo:

  1. No questions at the terminal. The command does not prompt. The demo project uses the first model key it finds (OPENAI_API_KEY, OPENROUTER_API_KEY or ANTHROPIC_API_KEY, in the environment or in the .env next to the demo's nl2sql.yaml), then an Ollama daemon on localhost:11434 with a model pulled, and otherwise answers its guided questions from recorded runs.
  2. A project folder and an index. The first time, it writes ./nl2sql-demo (--dir changes it) with nl2sql init --demo, which copies in the three databases above; every start then builds the engine, calls engine.check(), and indexes the schemas on your machine when the index is missing, empty or out of date. The first run downloads a ~79 MB embedding model; indexing needs no key.
  3. A local page. The server starts without sign-in: you are the local operator, with the admin roles. The page opens in your browser once the server answers (--no-browser skips that, --port changes the port). Ctrl+C stops it.
  4. No key yet? Open Settings and enter an OpenAI, Anthropic or OpenRouter key. It stays in that browser tab and is sent with each question; nothing is written on the server.
  5. Ask. Home shows the guided questions the demo carries and Chat answers them or your own. An answer shows the text and the rows first, then the warnings, Why this answer, the SQL and Plan, and Trace and cost; Did this answer it? keeps a good answer in My answers. The Pipeline page lists every step and which a model decides.

The web app also has pages to build dashboards, decide approvals, add a database (Connect), review what the engine knows (Knowledge), run evals and search the index (Retrieval). Connect, Knowledge and Evals are for administrators, which is what you are on a local demo.

The nl2sql command is the nl2sql-cli package and its web extra brings the web app. From a clone, install pip install -e packages/sdk -e packages/nl2sql -e packages/api -e "nl2sql-cli[web]".

1. Install the CLI

# Install from PyPI. The `web` extra brings the browser app that
# `nl2sql demo` serves.
pip install "nl2sql-cli[web]"

# Or install from source (dev)
pip install -e packages/sdk -e "packages/nl2sql[all]" -e packages/api -e "nl2sql-cli[web]"

2. Write the demo project

nl2sql init --demo nl2sql-demo
nl2sql --config nl2sql-demo/nl2sql.yaml index

init --demo writes a complete config, relative to the folder you name:

nl2sql.yaml            # the table of contents
datasources/
  chinook.yaml         # each with its description, read-only connection,
  support.yaml         # 10,000-row limit and sample questions
  webanalytics.yaml
llm.yaml               # the provider and model; no key
embeddings.yaml        # provider: local
policies.yaml          # the admin, analyst and viewer roles below
storage.yaml           # path: .nl2sql (index, state.db, traces, results)
knowledge.yaml         # one yaml knowledge source: glossary.yaml
glossary.yaml          # the Chinook glossary: descriptions, roles, terms, a rule
curated.yaml           # six verified queries on Chinook
settings.yaml          # a 300 s timeout and a trace for every run
data/                  # chinook.sqlite, support.sqlite, webanalytics.sqlite
.gitignore             # .nl2sql/ and .env

It is the same config nl2sql.config.demo_config() (and NL2SQL.demo()) builds in code.

The glossary describes Chinook's invoices, its money and enum columns, the terms "revenue" and "invoiced total", and a rule. "Sales" is a synonym of both terms on purpose: the demo carries one real ambiguity. After nl2sql index, see what the engine makes of it, as a role:

nl2sql --config nl2sql-demo/nl2sql.yaml knowledge show --as analyst
nl2sql --config nl2sql-demo/nl2sql.yaml knowledge show --as viewer   # the catalog only: no invoice terms

Each item is labelled with its origin (knowledge, database or derived); see Knowledge. nl2sql index then builds the index, and exits 1 if any datasource fails. See Start a config with nl2sql init.

For the browser web app instead of the CLI, nl2sql demo does both steps in ./nl2sql-demo the first time (and adds a nl2sql-demo.json stamp recording which engine version wrote the folder; see Old demo folders), then serves a page over it. See the CLI reference for its flags, and the Settings page for entering a key and choosing models from the page.

The schemas

Chinook is eleven tables with real declared foreign keys: Artist, Album, Track, Genre, MediaType, Playlist, PlaylistTrack, Customer, Employee, Invoice and InvoiceLine. support adds four - agents, customers, tickets and ticket_messages - and webanalytics five - devices, referrers, sessions, page_views and conversions. All three declare their foreign keys, which matters: LogicalValidatorNode checks every join in a plan against a declared relationship, so a dataset without them cannot answer a join question at all.

The three share their people. Both generated databases carry a customer_email column and a customer_id matching Chinook's Customer.CustomerId, so the same 59 customers appear in all three, and every timestamp in them falls inside Chinook's invoice window, 2009-01-01 to 2013-12-22. That does not make a question spanning two databases answerable: the engine plans each sub-query against a single datasource, so it cannot join across them. The shared columns are groundwork for when it can.

Three registered datasources also change how a question is routed. With one, the resolver took the only datasource and skipped the vector search; with three, the datasource search and the LLM answerability judge run on every question, so the demo exercises the part of the pipeline a single-dataset demo never reached. Indexing all three writes 186 entries - 111 for chinook (24 of them the verified queries' phrasings and descriptions), 36 for support and 39 for webanalytics - and nl2sql index takes about seven or eight seconds once the embedding model is cached; the first run on a machine still downloads the model.

Verified answers

curated.yaml holds six verified queries on Chinook: SQL written and reviewed in advance, with typed params, and the questions each answers (top customers by revenue in a year, revenue by year, monthly revenue in a year, sales by country, best-selling genres, top artists by tracks sold). nl2sql.yaml includes it as the curated section, so curated answers are on, and indexing embeds their questions beside the schema. A question one of them answers runs its SQL with the values bound instead of a generated plan, and Why this answer names the verified query used. "What is the total revenue per year?" and "Which genre sells the most tracks?" among the guided questions are two of them. See Curated answers.

The keyless replay includes the matcher's recorded choices, so a verified query answers without a key too, on the guided questions it covers.

The roles

policies.yaml is written with three roles, spanning all three datasources, so the policy check is visible without editing anything:

Role Patterns May read
admin allow: ["*"] every table in every demo database
analyst allow: [chinook, support, webanalytics], deny: [chinook.main.Employee, support.main.agents] everything except employee and support-agent records
viewer allow: the seven Chinook catalog tables and webanalytics.main.devices, webanalytics.main.page_views, webanalytics.main.referrers no customer, invoice or ticket-message data, and no access to support at all

Ask the viewer role about customers and no model ever sees the Customer or Invoice tables: they are hidden from the planner, so the answer is that the connected data cannot answer the question. A plan that names a hidden table anyway is refused by the logical validator with a SECURITY_VIOLATION before any SQL is generated. policies.yaml sets refusal_names_tables: true, so the demo's refusal names the role and table; outside the demo the message is the generic "You do not have permission to see the data this question requires." See Security Model. The web app runs the demo as the local operator with the admin roles, so to try the other roles use nl2sql run --role viewer or the REST API; engine.datasources.schema(..., user_context=) lists only the tables a role may read.

Recorded answers, no key

With no key anywhere and no local Ollama model, the project nl2sql.prepare_demo(folder) writes uses provider: replay: the demo's guided questions are answered by the real pipeline from the model output recorded with the engine (the replay provider). Any other question fails with REPLAY_MISS until you add a key. A key in the environment is used first, then an Ollama daemon with a model pulled. The facade's engine.add_demo() does not touch the provider: it keeps the one the engine has, so a project answers the guided questions with no key only when its llm is provider: replay. From Python:

from nl2sql import NL2SQL, load_config, prepare_demo

config_path = prepare_demo("my-demo")   # written once, indexed when the index is missing
engine = NL2SQL(load_config(config_path))

engine.add_demo() adds the three sample databases, their verified queries and the demo glossary (copied to demo-glossary.yaml in the project folder, so accepting a proposal writes into your project) to an engine you already have, then indexes them. When the engine was loaded from a nl2sql.yaml all of it is saved there and is still there after a restart: each database under datasources/, the verified queries in curated.yaml (with a curated: line in nl2sql.yaml if the project had none), and the glossary as a second source in knowledge.yaml. A section written inline in nl2sql.yaml is left alone. The files are appended to, never rewritten, so your comments stay, and a file you edited since the engine loaded it is refused (changed on disk) with nothing added. An engine built in code has no file, so for it the verified queries and the glossary are added to that engine only and add_demo has to run again after a restart. An id such as chinook that is already a database of yours (another file, even one named chinook.db) is refused with a DatasourceExists error and nothing is added; a second call changes nothing. A caller who is not an admin gets NotAuthorized. engine.datasources.list() shows each one's sample_questions.

API keys in the demo

embeddings.yaml says provider: local, so schema chunks are embedded with the key-free ONNX all-MiniLM-L6-v2 model bundled with chromadb instead of the OpenAI embeddings API. The first indexing run downloads roughly 79 MB of model files into a local cache, which can take a few minutes.

This covers the embedding step only. The demo is not key-free end to end:

  • nl2sql run "..." calls a chat model, so it needs a working LLM key (OPENAI_API_KEY, or an OpenRouter key with llm.yaml pointed at provider: openrouter). Keep it in the environment, or in a .env file next to nl2sql.yaml, which the CLI loads without overriding a variable already set.
  • The demo's model is gpt-5.4 with temperature: 0.0, which it accepts. To use a model that rejects it (gpt-5.5, gpt-5-mini), set temperature: null in llm.yaml - see LLM configuration → Temperature. With an OpenRouter key or Ollama, change model to one that provider serves: live mode switches the provider, not the model name.
  • Indexing calls no model: the demo's own indexing (the first run and the startup repair) reads the schema and the glossary and embeds them, with the local embedding model by default. Descriptions a model drafts are proposals for review, not part of the index.
  • A key entered in Settings stays in that browser tab and is sent with each question; nothing is written on the server. To keep a key for the server, put it in the environment or in the .env next to nl2sql.yaml, which is covered by .gitignore. A key passed on the command line is visible in shell history and to ps, so the environment variable remains the more private route.
  • So nl2sql init --demo and nl2sql index complete with no chat key at all, and nl2sql index exits 0. It exits 1 if any datasource actually fails to index, which is safe to rely on in a script. A missing key surfaces when a chat model is first called (nl2sql doctor names it before that).
  • Pointing llm.yaml at provider: ollama removes the chat key requirement, but a local model's ability to satisfy the pipeline's structured output is model-dependent - see LLM configuration → Ollama.

Sharing the demo with other people is the one case where none of this applies: nl2sql-api serve --demo --hosted serves the web app with no key on the server at all, and each visitor pastes their own into the page; a visitor without one can replay the guided questions from recorded runs. It refuses to start when OPENAI_API_KEY, OPENROUTER_API_KEY or ANTHROPIC_API_KEY is set. See Hosted demo.

Each project keeps its index under its own storage.path (the demo's is nl2sql-demo/.nl2sql/index), with one namespace per embedding model. If you change the embeddings section of an existing project, run nl2sql index: the new model's namespace starts empty, and the old one stays until nl2sql index prune.

Column statistics are read when a datasource is indexed, so a change to what indexing records reaches an existing demo folder only when it is indexed again. A text column with at most 50 distinct values keeps all of them. nl2sql demo does not re-index a folder whose index is healthy, so run nl2sql index in the folder, or start a fresh one with nl2sql demo --dir <new folder>. The hosted image builds its index with nl2sql init --demo and nl2sql index, so a new image picks the change up.

Index health and repair

The resolver, which picks the database for every question when more than one is registered, reads the vector index, and with three registered it searches on every question. The schema snapshot and the index can disagree: a folder once had its snapshot intact and 0 entries in its index, so the schema looked fine while every question failed with SCHEMA_RETRIEVAL_FAILED. Three things guard against that:

  • Startup repair. Every nl2sql demo start calls engine.check(), which reports what the index contains: the demo rebuilds it when it is missing or empty, or a datasource has no live build. A failed rebuild is reported and the server still starts.
  • Rebuilds never leave an empty index. A datasource's new entries are written beside its current ones and switched in only when all are written; a failure keeps the previous entries answering questions. See Indexing.
  • Actionable errors. With an empty index the resolver says "The vector index is empty ... Re-index with nl2sql index", and nl2sql doctor prints the engine's check, the index status included.

GET /index reports the index's health, the Retrieval page searches it, and nl2sql index rebuilds it for all three databases. A question in flight finishes on the entries it started with. The first run downloads the 79 MB embedding model, so it can take a few minutes. Descriptions a model drafts are proposals for review, not part of the index. On the hosted demo the index was built before the server started and nothing rebuilds it: the sample data never changes.

Old demo folders

Demo folders are not upgraded in place: a folder keeps the defaults of the engine that wrote it (for example its default model). A new folder gets a nl2sql-demo.json stamp; when nl2sql demo starts in a folder stamped by an older engine, or in one with no stamp at all, it warns and suggests a fresh --dir.

The web app

Asking, the pipeline view, Settings, the retrieval inspector and answer ratings are pages of the web app, described in Web app. Did this answer it? files the rating through POST /feedback; it is stored in the demo's state store (.nl2sql/state.db) with the question, role, SQL, the model per step and the engine version, never the rows; see Feedback and Signals.

3. Use the demo from the CLI

Every command reads one config: --config PATH, else NL2SQL_CONFIG, else ./nl2sql.yaml. Paths inside it are relative to nl2sql.yaml, so from the demo folder (cd nl2sql-demo) no flag is needed; from anywhere else, add --config nl2sql-demo/nl2sql.yaml before the command.

# Run a query against the demo
nl2sql run "How many customers do we have, by country?"

# Ask as a role that is not allowed the answer
nl2sql run --role viewer "Who are the top 5 customers by total spend?"

# Plan and validate without touching the database
nl2sql run --no-exec "Which artist has the most albums?"

# Pin one datasource instead of letting the resolver pick
nl2sql run --ds-id support "How many support tickets are still open, by priority?"

# Re-index after editing the demo's config
nl2sql index

# Re-index one datasource only; the others' entries are left untouched
nl2sql index --datasource chinook

# After changing the embedding model: drop the old model's index
nl2sql index prune

# Check the install, the keys, and the engine: each datasource, each key, the index
nl2sql doctor

The two flags that name a datasource are not the same flag: run takes --ds-id, which pins the datasource and makes the resolver skip its search; index takes --datasource (-d), which chooses what to re-index.

The demo's settings.yaml sets traces: { mode: always }, so every run also writes a trace to .nl2sql/traces/ and prints its path. Inspect one with nl2sql trace show <file or trace id>, or re-run it on the recorded model answers with nl2sql trace replay <file>. See Debugging a Run.

Asking a question a second time on the same day reuses the first run's validated plan from the plan cache (in .nl2sql/state.db), so the SQL and rows are the same and the planner is not called. The plan is still validated for the role you ask as. To start fresh:

nl2sql cache clear

The ratings, and the guardrail rates over every rated run and kept trace:

nl2sql feedback list               # the ratings, newest first
nl2sql feedback stats              # thumbs up/down, refusals, retries, errors, plan cache
nl2sql feedback export --good      # thumbs-up runs as draft eval cases, for review
nl2sql feedback clear              # delete every rating

export --good writes feedback_gold_drafts.yaml, a suite of draft cases. A person must review each draft, approve it and run engine.evals.regenerate before it runs; see Feedback and Signals.

Recording (scripts/record_demo_answers.py) turns the cache off (settings.pipeline.plan_cache is off in the engine it builds; the files are not changed), so every planner answer is captured. It also stops with exit 1, recording nothing, when the demo's indexing fails: a plain nl2sql demo keeps going, but answers recorded against no index would be the wrong ones. Only a question whose run succeeded (rows, an answer, no error) keeps its recordings; a failed run's are dropped, the question is listed as not recorded, and the command exits 1 after writing recordings.json with the rest. The file names the provider and the model that answered, and a replay reports that model -- in the usage ledger and on the Pipeline page, tagged recorded -- rather than the one the replaying config names. See Determinism → The plan cache.

The .env next to nl2sql.yaml is loaded by the CLI, nl2sql-api and nl2sql demo at startup, so doctor and run find a key kept only there; a variable already exported in your shell wins over the file. There is no --env flag and no .env.<name> lookup: one config folder, one .env.

run and index call engine.check() first. A datasource marked required: true that cannot connect stops them with the report (exit 1); any other one that fails is printed and left out of routing.

Sample questions

The demo's datasource files carry twenty questions (sample_questions), the same ones the web app offers as guided questions, from GET /meta. Chinook's twelve come first, so the demo opens on familiar ground:

  • How many customers do we have, by country?
  • Who are the top 5 customers by total spend?
  • Which artist has the most albums?
  • What is the total revenue per year?
  • Which genre sells the most tracks?
  • What is the average invoice total by billing country?
  • Which employees support the most customers?
  • What is the longest track in each genre?
  • Which 5 customers bought the most jazz tracks?
  • What was the monthly revenue in 2013 for customers in the USA?
  • Which playlists contain tracks from more than three genres?
  • Who are the top customers by total spend?

Then four on support:

  • How many support tickets are still open, by priority?
  • Which support agents resolved the most tickets?
  • What is the average time to close a ticket, by category?
  • Which customers raised the most support tickets?

And four on webanalytics:

  • Which pages were viewed the most last year?
  • How many sessions came from each marketing channel?
  • What is the bounce rate by device type?
  • How many purchases were there per month in 2013?

None of them spans two databases, deliberately: the engine plans each sub-query against one datasource, so a question that has to read two of them at once is not answerable.

They are also indexed, per datasource, each question as an entry of its own (schema.datasource_example, from sample_questions in its datasource file), beside the schema.datasource entry with the configured description. Routing votes with both, and with each datasource's tables and columns, which is how the resolver tells the three apart (see Routing). Re-index (nl2sql index) after editing them.

Whether a given question is answered correctly depends on the model; see Known limitations.

Regenerating the demo

nl2sql init --demo DIR --force overwrites the config files and all three databases under data/ with fresh copies; without --force it names the files that exist and writes nothing. It never touches .env, so a saved key survives, and it leaves the index under .nl2sql/ alone: run nl2sql index afterwards. nl2sql demo never rewrites an existing project's config; start a new --dir for a fresh one.

The datasets that are not here

--lite and --docker chose between a generated manufacturing dataset in SQLite and the same data in a Postgres/MySQL/MSSQL Compose stack. Both are gone: the manufacturing DDL declared no foreign keys, so it could not answer a join question, and it was the only dataset the test suite ran on. The Postgres, MySQL and MSSQL adapters are unaffected - they are product features, configured like any other datasource. The demo's three SQLite databases took their place. A question that has to read two of them at once is still not answerable: the engine plans each sub-query against a single datasource.