Inspiration

Non-technical people have data but can't write SQL. I wanted: type "What was budget of Product 12?" → get SQL + answer + rows, with proof it didn't hallucinate.

What it does

Live: https://askdb-text-to-sql.streamlit.app/

  • Ask the data — chat in English, streams SQL + runs it + shows rows
  • Self-healing SQL — failed query auto-fixed against schema, up to 3 retries
  • Read-only guard — only SELECT/WITH allowed, everything else blocked
  • Schema page — browse tables, columns, types, row counts
  • Evaluate page — 1-click 5-question RAGAS benchmark (Context Precision + Helpfulness 1-5), history charted in eval_history.json
  • Database page — import CSV as new table, rebuild 6 seeded tables, delete user tables

How we built it

frontend.py (Streamlit, 4 pages) + backend.py (LangChain LCEL: schema → prompt → LLM → parser). Primary gemini-flash-lite-latest, fallback openai/gpt-oss-120b on Groq. DB via st.connection('app_db') — SQLite locally, Neon Postgres on cloud. RAGAS for eval, all-MiniLM-L6-v2 for embeddings. Started from 1.py (minimal Gemini chain), 2.py (Groq + RAGAS), create_db.py (CSVs in Data_CSV/ → text_to_sql.db), then evolved to full app.

Challenges we ran into

  • LLM invented columns — fixed with schema-in-prompt + validator + auto-fix loop
  • Streamlit Secrets TOML ordering bug — keys after [connections.app_db] get swallowed, top-level keys must come first
  • ragas broke on import without vertexai — added vertexai_shim.py
  • SQLite → Neon type differences in CSV seeding
  • Streaming SQL + rows in bounded chat panel without layout jump

Accomplishments that we're proud of

  • Text-to-SQL that actually runs, not just generates — with guardrails
  • Self-heal + dual-LLM failover so demo never dies on 429
  • Built-in RAGAS eval with 1.0 precision / 5.0 helpfulness on benchmarks + trend charts

What we learned

Prompt without schema = hallucinations. Eval matters more than vibes — RAGAS forced me to fix retrieval. st.connection abstraction saves a ton for SQLite → Postgres switch.

What's next

JOIN visualizer, query explanations in plain English, save/favorite queries, bigger benchmark set, chart answers automatically, Postgres-only RAG search.

Built with: Streamlit, LangChain, Gemini, Groq, Neon Postgres, RAGAS

Built With

Share this project:

Updates