Text2SQL using Hugging Face Dataset Viewer API and Motherduck DuckDB-NSQL-7B
Hugging Face
Hugging Face shows how to turn plain-English questions into SQL using MotherDuck's DuckDB-NSQL-7B model. It runs right against any of HF's 120K+ hosted datasets via parquet files, no database setup needed.
Based on reporting by Hugging Face — read the original for the full story.
Summary, retelling and take written by AI under human oversight; images are AI-generated illustrations. How we work · Report an error
Text-to-SQL has been one of the more obvious LLM use cases for a while, but a new tutorial from Hugging Face makes the plumbing unusually concrete. It walks through connecting DuckDB-NSQL-7B, a 7-billion-parameter model built by MotherDuck and Numbers Station on top of Llama-2, directly to Hugging Face's dataset viewer API, letting anyone query one of the platform's 120,000-plus datasets with a sentence instead of a SELECT statement.
The trick is in how the schema gets to the model. Rather than requiring a live database, the demo pulls the first auto-converted parquet file for a dataset — in this case jamescalam/world-cities-geo — and uses DuckDB to fake a CREATE TABLE statement from a single row. That DDL gets slotted into a fixed instruction prompt alongside the user's natural-language question, something like "Cities from Albania country," and fed to the model running locally through llama.cpp on a quantized GGUF checkpoint.
What comes back is real DuckDB SQL, referencing a table called "data" that doesn't actually exist anywhere. The workaround is almost comically simple: swap "FROM data" for the actual parquet URL and execute the query with DuckDB's own engine, which can read remote parquet files without downloading them first. In the example given, the model correctly produces a WHERE clause filtering on country = 'Albania', and running it returns the same 100 rows you'd get from manually searching the dataset viewer's UI or hitting its /search and /filter endpoints.
None of the individual pieces here are new — DuckDB-NSQL-7B has been public for months, and Hugging Face's parquet auto-conversion and search APIs already existed. What's notable is the packaging: a person with zero SQL knowledge can now describe what they want from a massive public dataset and get a working query back, verified against the same numbers the dataset viewer shows through its own search tools. The full notebook and a live Hugging Face Space are both linked for anyone who wants to swap in their own dataset.
It's a modest-looking demo, but it points at something bigger — treating every dataset on the Hub as queryable infrastructure rather than a static file to download and poke at locally.
My take — AI-written commentary, not fact-checked reporting
This is the unglamorous, plumbing-level AI work that actually matters more than another chatbot demo — turning static parquet files into queryable infrastructure without spinning up a database is genuinely useful. I'd rather see ten more integrations like this, open model and open API both, than another closed assistant wrapper charging you for the privilege of asking a question in English.
Read more about this at: Hugging Face