← All models

text2text-generation Β· text Β· WASM Β· ~80 MB

Text-to-SQL β€” ask in English, get a query

This is a small encoder-decoder (T5-small, ~60M) fine-tuned for one job: writing SQL from a database schema and a plain-language question. Unlike a general text model, it is schema-conditioned β€” you paste your CREATE TABLE statements in front of the question, and the model grounds its query in your columns and table names. The decoder writes the SELECT one token at a time; watch it stream. Nothing leaves your device.

Calibrate expectations: at 60M params it is genuinely good at single-table filters, counts, GROUP BY aggregations, and simple joins over a schema you give it β€” and it will sometimes get complex multi-join logic wrong. The page shows the real generated SQL, correct or not, never a canned answer. Always review generated SQL before running it against a real database.

At a glance

ModelXenova/t5-small-awesome-text-to-sql (ONNX of cssupport/t5-small-awesome-text-to-sql)
Task / pipelinetext2text-generation (sequence-to-sequence)
ArchitectureT5-small encoder-decoder (~60M params) β€” encoder reads schema + question, decoder writes SQL
TrainingFine-tuned on b-mc2/sql-create-context + Clinton/Text-to-sql-v1 — schema-grounded NL→SQL pairs
Input formattables:\n<CREATE TABLE …>\nquery for:<question> β€” the schema is the conditioning
Quantizationq8 (8-bit) ONNX β€” encoder + merged decoder
BackendWebAssembly (runs anywhere; no WebGPU needed)
Download~80 MB, cached after first load
LicenseApache-2.0
Web APIsWebAssembly, Web Workers, Clipboard β€” all Baseline widely available

Run it

Paste your schema (one or more CREATE TABLE statements), ask a question in plain English, and hit Generate. The schema plus the question is what conditions the model β€” change the schema and the same question produces different SQL.

Generated SQL

See inside β€” the schema-conditioned input the model actually reads

There is no hidden prompt engineering. The model was trained on one exact shape: the word tables:, your CREATE TABLE lines, then query for: and the question. Below, the schema conditioning is dimmed and the question is highlighted, so you can see exactly how the schema steers the query. Then the encoder's tokens (T5 uses SentencePiece β€” a leading Β· marks a word boundary) and the decoder's real per-token timeline.

Generate a query to inspect the exact input the model was fed.

Why it matters

Natural-language querying is one of the most-requested database features, and it usually means shipping every schema and question to a cloud LLM. An 80 MB model in a tab does the common cases privately, offline, and for free β€” the schema and the question never leave the device.

Use cases

Basics

One schema, many questions β€” feel how a plain-English question becomes SQL.

Practical

A query console over a fixed schema: ask, get copyable SQL, run it against an in-browser database and see rows.

Wild

Push it: multi-table joins, aggregations, and nested subqueries β€” find where a 60M model shines and where it breaks.

Multi-model

The full loop: question β†’ SQL β†’ run it in SQLite β†’ FLAN-T5 answers in plain English. Two models plus a database.

How the API works

The whole task lives in the input string β€” the schema is the conditioning, no template roles:

import { pipeline } from "@huggingface/transformers";

const text2sql = await pipeline(
  "text2text-generation",
  "Xenova/t5-small-awesome-text-to-sql",
); // downloads + caches ~80 MB once

// paste the schema in front of the question β€” this exact shape is what it was trained on:
const prompt =
  "tables:\n" +
  "CREATE TABLE students (student_id INT, name VARCHAR, gpa FLOAT);" +
  " CREATE TABLE attendance (student_id INT, course_id INT)\n" +
  "query for:List the names of students who never attended a course.";

await text2sql(prompt, { max_new_tokens: 128 });
// β†’ [{ generated_text: "SELECT name FROM students WHERE NOT student_id IN
//        (SELECT student_id FROM attendance)" }]

For the live token stream and the decode timeline, this page passes a TextStreamer so it can timestamp each generated token β€” all inside a Web Worker so the UI never janks.

References