Mini Text-to-SQL Demo
Offline, LLM-free demo of the schema-linking + validate + execute loop described in the article Text-to-SQL 与 Agentic Query.
Dependencies
- Python 3.9+
sqlglot==25.6.1
pip install sqlglot==25.6.1Run
python mini_text2sql.pyWhat it shows
The script builds an in-memory SQLite database with
customers and orders tables, then
runs four natural-language questions through the
pipeline:
how many orders?— counts rows.what is the average amount?— aggregatesAVG.top orders by amount— ORDER BY … DESC LIMIT.please hallucinate a column— deliberately generates invalid SQL so you can observe the validator rejectingghost_coland the join with noONclause.
The Mock LLM is deterministic; replace it with any real
LLM (OpenAI, Ollama, llama-cpp-python …) by providing the
same
generate(prompt, question, schema) -> str
interface.
Offline
No network access is required. sqlglot is a
pure-Python SQL parser.