DevTools Logo

AI SQL Query Generator

AI SQL Query Generator

NL to SQL with on-device WebLLM — formatted with sql-formatter

Describe the query

Examples

Filter and sort by date

Input
List users who signed up since January 1, 2026, newest first

A date filter plus sort order — verify the model used the literal date, not a guessed interval.

Aggregate with GROUP BY

Input
Show total revenue per customer for orders placed in 2025, highest first

Filter + SUM + GROUP BY + ORDER BY in one prompt; naming the aggregation helps.

Join two tables

Input
Find customers who have never placed an order

Anti-join pattern (LEFT JOIN … IS NULL); joins are where small models err most — review carefully.

Group by status

Input
Count orders by status for the last 7 days

COUNT + GROUP BY with a relative time filter; double-check the interval the model picks.

About this tool

Generate SQL from plain English and format with sql-formatter — on-device WebLLM.

How to use

  1. Describe the query

    Write what you want in plain English; name tables and columns if you know them.

  2. Pick a model

    Quality (1.5B) is recommended for joins and date filters.

  3. Generate and review

    Check the SQL against the assumptions and warnings the model reports.

  4. Adapt to your schema

    The model guesses table names — rename them to your real schema before running.

Use cases

Exploring a schema

Ask in plain English while learning which tables and joins you need.

Drafting analytic queries

Get a starting SELECT for aggregations instead of a blank editor.

Learning SQL

Compare your mental model with the generated SQL and its stated assumptions.

Common mistakes

Mistake:Assuming the model knows your tables.

Fix:It invents plausible names — include table and column names in the prompt.

Mistake:Trusting date and interval math.

Fix:Small models frequently swap literals for NOW() - INTERVAL guesses; check every WHERE clause.

Mistake:Running generated SQL unreviewed.

Fix:Destructive statements are blocked, but wrong UPDATE or INSERT still destroys data — review first.

Mistake:Vague prompts like 'get stats'.

Fix:Name the metric, grouping and sort order; vague prompts produce vague SQL.

Frequently asked questions

References & standards