Training · learner work

The Question Was in Plain English. The Query Still Had to Be Safe.

A Colaberry learner built a plain-English question tool for SQL Server around one rule: the model proposes a query, and code with no model in it decides whether it may run. This record follows the choices that rule forced and what the repository can and cannot prove.

verified

All student projects
A plain-English question, a checked query, and what the record cannot prove. Narrated by a synthetic voice; the figures it states are the verified metrics recorded below.
Industry
Technology
Capability
Operational AI plain english to safe SQL
Built by
Harpreet Kaur
Published
2026-11-19

The situation

Important business answers often sit in a database that only someone who writes SQL can reach, so a leader's question waits for an analyst. A text-to-SQL tool shortens that wait, but it adds a new risk: the model can choose the wrong table, invent a join or produce an unsafe statement, and nothing in a fluent answer tells a non-technical reader that it happened.

The people this is for are business and operations leaders who need answers and do not write SQL, analysts who want a reviewable starting point for recurring questions, and data teams who want plain-English access bounded by checks they can inspect.

ToolSmithAI connects to Microsoft SQL Server, profiles the schema, and answers plain-English questions with a table, KPIs, a chart and an insight grounded in the returned values. It also accepts uploaded CSV and Excel files through a simpler path that never generates SQL.

The build is a working application on a local setup. It has not been measured for answer accuracy, response latency or business impact, and nothing in the repository shows it deployed or used by anyone.

What it had to do

  • Give a non-technical user a current answer from a live database without asking them to trust unchecked model output.
  • Ask the user when a question is genuinely ambiguous rather than answer a guess.
  • Keep answers current even when a plan is reused from the cache.
  • State plainly what the release has not measured.

What constrained it

  • The model never executes anything. Its output is a candidate that must pass checks with no model involved before any SQL reaches a database.
  • Read-only access only, enforced in the application and, by her security guide's recommendation, again by a read-only database login.
  • Question answering is off by default and runs only for sources an operator lists in a local allow-list.
  • Credentials, result rows, prompts and vectors are never written to the plan cache; connection details are stored encrypted.
  • Live question answering supports Microsoft SQL Server only, and needs an OpenAI key.

Decisions that made the difference

Four choices shaped the system. Each one lives at a specific point in the drawing above.

  1. At Deterministic validation

    The model writes a candidate, not a query that runs

    A text-to-SQL model can pick the wrong table, invent a join or write an unsafe statement, and a fluent answer hides the mistake from someone who cannot read SQL.

    Every candidate is parsed into a T-SQL syntax tree with sqlglot and checked with no model involved: length, no comments, exactly one statement, a read-only root statement, no write construct anywhere in the tree, and every table, column, alias and join present in the retrieved schema. Credential-like columns are rejected.

    Evidence The validator module and its rejection tests at the pinned commit.

    17Seventeen write and control statement forms, from INSERT and DROP to EXEC and USE, each have a test that expects a rejection. A candidate that fails is refused or turned into a clarification; it never falls back to another planner.

  2. At Read-only capped execution

    Even a valid query gets a ceiling

    A query that passes every check can still ask for a million rows or run for minutes against a live database.

    Validated SQL runs unmodified through one bounded executor: a real query timeout, separate from the connect timeout, a hard row cap read in batches, and failure messages sanitized so driver text cannot leak a connection string. The executor never rewrites, repairs or retries a query. Her security guide also asks for a read-only database login, so the database refuses writes on its own as well.

    Evidence The executor module and the defaults in the configuration module at the pinned commit.

    1,000 rowsBy default no answer is built from more than 1,000 rows, no query runs longer than 30 seconds, and a truncated result says it is truncated. Both limits are settings, so a deployment can change them.

  3. At Ask instead of guess

    An ambiguous question gets a question back

    Some questions have two reasonable readings, such as which date a report means, and picking one silently gives a confident answer to a question nobody asked.

    After schema retrieval and before validation, a local check with no model call reasons over what the pipeline already loaded. When a real ambiguity remains it returns one concise clarification question; when the question already names the deciding term, it goes ahead. Follow-up turns keep their context in signed state the server rejects if altered.

    Evidence The ambiguity guard module and the signed conversation-state module at the pinned commit.

    A user who asks something unclear is asked to choose rather than shown a guess. How often that happens, and whether it happens at the right times, has not been measured.

  4. At Refused, no other planner

    One route, and the old one kept only as history

    Earlier versions had a keyword intent router and a multi-path planner. A second route is somewhere a failed answer can quietly retry with weaker checks.

    Database questions go through one route. A failure returns that route's own typed status, and a source missing from the operator's allow-list gets a clear not-enabled answer. The retired planner's contract tests were kept and marked skipped with a stated reason, rather than deleted or left failing.

    Evidence The single route module, the enablement gate in configuration, and the skip marker in the planning tests at the pinned commit.

    8 testsThere is no path in the code from a refused candidate to another planner. Eight of the nine skipped backend tests her README reports are those retired-planner tests.

The build

  1. The application released in one commit
  2. Documentation tightened
  3. A product preview added
  4. The commit this record is pinned to
Notes on 4 of the 4 steps
  • The application released in one commit. A sanitized portfolio release adds the whole application at once: 658 files, with the backend, frontend, tests, migrations and her architecture, security and testing guides. The development history before it is not public.
  • Documentation tightened. A separate case-study file is removed and the README, architecture and security guides are reworded. The statement that accuracy, latency and business impact were not measured stays.
  • A product preview added. A screenshot of the sign-in page is added to the README as the product preview.
  • The commit this record is pinned to. The README header is simplified. Every file and figure on this record was read at this commit.

What was built

A Python and FastAPI backend with a React and Vite frontend, run locally. A Docker image packages the backend only. Metadata, retrieval documents, validated plans and history live in a local SQLite store with additive migrations; the data being questioned stays in the connected SQL Server database.

Stack

  • Python 3.12
  • Fastapi
  • Sqlglot
  • Sqlite
  • Microsoft SQL server
  • OpenAI SDK
  • React 19
  • Vite
  • Pytest
  • Vitest
  • Docker
More on what was built

The parts, in the order a question meets them. Connecting a source starts a lifecycle that profiles the schema and builds embedded retrieval documents. A question for an enabled source either matches a validated plan in the cache or goes through schema retrieval and one combined OpenAI call that classifies the request, selects the schema objects and proposes SQL. Relationship completion and a local ambiguity check follow, then a validator built on sqlglot parses the candidate into a T-SQL syntax tree and checks it against the retrieved schema, and a bounded executor runs only what passes.

The model step is named here because it is the one step a model runs. By default the proposing call uses the model set in her configuration, gpt-4o-mini, and retrieval uses the text-embedding-3-small embedding model; both are settings. Answer text for complex results is also model-written. Validation, execution, caching decisions, KPI and chart selection involve no model.

Safety is layered rather than trusted to one place: the validator refuses anything but one read-only statement over known objects, the executor caps rows and time, her security guide asks for a read-only database login, conversation state returned to the browser is signed, connection details are encrypted, and the backend refuses to start with a missing or weak JWT secret. Database questions have one route; a retired keyword router and multi-path planner are not part of the product.

Capabilities

  • Deterministic validation of generated SQL before execution
  • Read only execution with row and time caps
  • Clarification instead of a guessed query
  • Schema retrieval by embedding search
  • A validated plan cache that still runs live
  • One question route with no silent fallback

Integrations

  • OpenAI chat model one call per fresh question proposes a plan default gpt 4o mini configurable
  • OpenAI embeddings for schema retrieval default text embedding 3 small configurable
  • Microsoft SQL server over odbc read only
  • Optional email delivery of reports off by default

Data stores

  • Sqlite profiled metadata retrieval documents and embeddings validated plans history
  • Microsoft SQL server the connected source read live and read only

The measurement

Six figures, all counted in her repository at the pinned commit and all describing how the system is built. None is an outcome, and there is no headline figure because nothing available compares a before with an after.

The test figures count tests defined, not tests passing. Her own reported results are kept off the page because they were not reproduced.

Her architecture document says answer accuracy, response latency and business impact are not measured and that no numbers are claimed. This record claims none either.

  • 6,136 backend tests defined across 258 files

    Backend tests defined in the repository

    verified

    Baseline
    None. This sizes the test suite rather than comparing it with an earlier state.
    Sample
    Every file named test_*.py under the tests folder of her repository at commit 4c777f3: 258 files, each of which defines at least one test.
    Methodology
    Counted directly from the repository at a pinned commit, two independent ways. A line-pattern count of every test definition gives 6,136, of which 5,967 are distinct names; the difference is names repeated across files, which is expected. A structure-aware count of top-level test functions (4,901) plus test methods inside test classes (1,235) gives the same 6,136. Fifty-two parametrize markers mean the test runner collects more cases than there are definitions, which is consistent with the larger totals in her README. Anyone can re-run either count against the same commit and get the same number.

    Limitations

    • This counts tests DEFINED, not tests passing. The suite was not executed; running it needs Python 3.12, the Microsoft ODBC driver and an OpenAI key.
    • A test count says work was covered, not that the coverage is good. There is no coverage percentage behind it.
    • Eight of these tests belong to a retired planner and are marked skipped on purpose.
    • The project's own documentation states that answer accuracy, response latency and business impact are not measured in this release. No figure on this record claims otherwise.
  • 175 frontend test cases defined in 14 files

    Frontend test cases defined in the repository

    verified

    Baseline
    None. This sizes the frontend test suite.
    Sample
    The 14 files named *.test.js or *.test.jsx under the frontend source folder at commit 4c777f3.
    Methodology
    Every call that defines a single test was counted, giving 166. The two table-driven tests were read by hand: one has 3 rows and one has 6, adding 9 cases. 166 plus 9 is 175.

    Limitations

    • Defined, not run. The agreement with her reported 175 passing is a consistency check, not a reproduction.
    • Seven of the 14 files test the answer workspace; a test count says nothing about which screens are untested.
  • 17 statement forms, each tested for rejection

    Write and control statement forms the validator is tested to reject

    verified

    Baseline
    None. This sizes one rejection test.
    Sample
    The parametrized list in the prohibited-statement test of the main validator test file at commit 4c777f3.
    Methodology
    The entries of the parametrize list were counted line by line: 17. Further tests in the same file reject writes into temporary tables, temporary-table and table-variable references, comments and multiple statements; those are not in this figure.

    Limitations

    • Seventeen forms is the scope of one test, not the scope of everything the validator refuses.
    • The validator's real defense is that only a read-only root statement type passes; the list shows that rule being exercised, not its limits.
  • 1,000 rows and 30 seconds per query by default

    Default limits on every validated query

    verified

    Baseline
    None. These are configured limits, not measured behavior.
    Sample
    The execution settings in the configuration module at commit 4c777f3.
    Methodology
    Read from the configuration module: the maximum rows default is 1,000 and the query timeout default is 30 seconds. A separate connect timeout defaults to 10 seconds. The executor module documents that the query timeout is applied to the connection itself after login, so it bounds the statement and not only the connection attempt.

    Limitations

    • Defaults, not guarantees: both values are environment settings.
    • A row cap bounds what is returned, not what the database scans to produce it.
    • No timing of a real query is on this record.
  • 8 retired-planner tests kept and marked skipped

    Tests of the retired planner, kept and marked skipped

    verified

    Baseline
    None. This counts a deliberate choice about old tests.
    Sample
    The query-planning test file at commit 4c777f3.
    Methodology
    Each use of the skip marker was counted: 8. Her README reports 9 skipped backend tests and attributes 8 of them to the retired planner and 1 to a test that needs Windows symlink permission; that ninth test is a conditional skip in a separate file.

    Limitations

    • Skipped tests run nothing. They document a contract the product no longer uses.
  • 4 commits, all on 9 Nov 2026

    Commits in the public repository history

    verified

    Baseline
    None. The public history has one starting point and no earlier state.
    Sample
    All 4 commits on the main branch up to and including commit 4c777f3.
    Methodology
    The commit log was listed at the pinned commit. The first commit, 14407fc, adds 658 files and 304,660 lines in one change; the other three edit documentation and add one screenshot. All four carry an author date of 9 Nov 2026 in the author's time zone, five hours behind UTC, so three of them fall on 10 Nov 2026 in UTC.

    Limitations

    • A single release commit cannot show iteration, so this record makes no claim about the build's timeline beyond the release date.
    • Commit metadata names the author; it does not show who or what typed each line. Her README discloses AI-assisted development tools.

What happened next

Shipped

  • Deterministic validation before any query runs
  • Read-only execution with a row cap and a query timeout
  • A clarification question instead of a guessed query
  • One question route with no fallback
  • A validated-plan cache that still runs live
  • Uploaded CSV and Excel datasets, reports and exports

Unknown

  • Measure answer accuracy and response latency
  • A controlled pilot
  • Managed secrets, SSO and a tenant-isolation review
  • Database engines beyond SQL Server
  • Deployment automation and a full container image
  • Split the largest source files
Notes on 12 of the 12 items
  • Deterministic validation before any query runs. A T-SQL syntax-tree check with no model involved: one statement, read-only constructs only, known tables, columns, aliases and joins, and credential-like columns rejected.
  • Read-only execution with a row cap and a query timeout. Validated SQL runs unmodified with a default cap of 1,000 rows and a default query timeout of 30 seconds, both configurable. Truncated results are labeled.
  • A clarification question instead of a guessed query. A local check with no model call stops a genuinely ambiguous question before validation and asks one concise question back.
  • One question route with no fallback. Database questions go through one route. A failure returns that route's own typed status, never a silent retry through another planner, and a source not on the allow-list gets a clear not-enabled answer.
  • A validated-plan cache that still runs live. Plans persist in memory and in a durable SQLite store. A hit skips only the embedding and model calls; validation and execution run again against current data.
  • Uploaded CSV and Excel datasets, reports and exports. A separate, simpler path for uploaded files: profiling, generated reports, simple questions, and exports to CSV, Excel and PDF. Uploaded files do not go through SQL generation.
  • Measure answer accuracy and response latency. Not measured in this release, by her own statement. Load and model-quality evaluation is listed as future work, and her testing guide leaves a blank table for cold and warm timings.
  • A controlled pilot. Her README describes the project as ready for a controlled pilot once the listed infrastructure is in place. Nothing in the repository shows a pilot, a deployment or a user.
  • Managed secrets, SSO and a tenant-isolation review. Listed as work needed before critical or regulated workloads, with key rotation, managed metadata storage and backups, and central monitoring. The sign-in screen's Google and Microsoft buttons are placeholders that say social login is not connected.
  • Database engines beyond SQL Server. Live question answering supports Microsoft SQL Server only. More connectors are listed as future work.
  • Deployment automation and a full container image. The container image packages the backend only, and local setup is the path her documentation verifies.
  • Split the largest source files. Her README names the main frontend file and the main routes file as very large and in need of refactoring. They are 5,710 and 3,784 lines at the pinned commit.

Meet the builder

Harpreet Kaur

Colaberry learner

Project contribution

Per her repository, she defined the product requirements and designed and built the system: connection-time metadata profiling, embedding-based schema retrieval, the single model-backed question route, the syntax-tree validator, the bounded read-only executor, clarification and follow-up handling, the validated-plan cache, answer, chart and export formatting, scheduling, and the React interface, along with the tests behind them. Her README discloses that AI-assisted development tools were used during implementation and verification, and that she owned the requirements, architectural decisions, testing, validation and final delivery.

Skills demonstrated

  • Keeping a model out of the execution pathGenerated SQL is parsed into a T-SQL syntax tree and must be exactly one read-only statement over known tables, columns and joins before anything runs. Seventeen write and control statement forms each have a rejection test.
  • Bounding what a query can doThe executor runs validated SQL unmodified under a real query timeout, 30 seconds by default, and a hard row cap of 1,000 by default. It never rewrites, repairs or retries a query.
  • Asking instead of guessingA local ambiguity check with no model call runs before validation and returns one concise clarification question when the evidence cannot settle what the user meant.
  • Caching without serving stale answersA cached plan is keyed on user, source, schema fingerprint, model, prompt version and policy versions, and a cache hit is still validated again and executed against current data. Result rows and credentials are not stored.
  • Retiring code honestlyWhen the older multi-path planner was retired, its eight contract tests were kept and marked skipped with a stated reason rather than deleted.
  • Stating limits in her own documentationHer architecture document lists answer accuracy, response latency and business impact as not measured, and says no numbers are claimed.

From the repository record.

What this project shows

The lesson in this build is where the trust boundary sits. The model writes a candidate; a syntax-tree validator, a read-only executor with a 1,000-row cap and a 30-second timeout, and a clarification question for ambiguous requests stand between that candidate and the data. She also wrote down what she had not measured, accuracy, latency and impact, before anyone asked. The 6,136 backend tests are defined in her repository and were not run for this record.

Build one of these

Start the program that produced this work.

See the program