Spaces:
Running
Running
π§© NL2SQL Copilot
A modular Text-to-SQL Copilot that converts natural language questions into safe and verified SQL queries.
Built with FastAPI, LangGraph, and SQLAlchemy, designed for read-only databases and evaluation on Spider/Dr.Spider benchmarks.
π Quick Start
1οΈβ£ Clone the repo
git clone https://github.com/melika-kheirieh/nl2sql-copilot.git
cd nl2sql-copilot
2οΈβ£ Build and run with Docker
docker build -t nl2sql-copilot .
docker run --rm -p 8000:8000 nl2sql-copilot
Then open http://localhost:8000/docs π
π§± Project Structure
nl2sql-copilot/
β
βββ app/ # FastAPI app, routers, schemas
βββ nl2sql/ # Core pipeline (planner β generator β safety β executor β verifier)
βββ adapters/ # Database and LLM adapters
βββ benchmarks/ # Evaluation scripts and results
βββ ui/ # Streamlit dashboard
β
βββ Dockerfile
βββ requirements.in
βββ requirements.txt
βββ README.md
π§ͺ Development
Install dependencies
(Recommended: Python 3.12+ and virtualenv)
pip install -r requirements.txt
Run tests
pytest -q
Lint and type-check
ruff check .
mypy .
π§ Features
- β Modular multi-stage pipeline (Planner β Generator β Safety β Executor β Verifier β Repair)
- π‘οΈ SQL safety filters (SELECT-only, forbidden keywords)
- π Self-repair loop on failed executions
- π Streamlit benchmark dashboard (latency, accuracy, cost)
- π§© PostgreSQL + SQLite adapters
- π§ Powered by
pydantic-aiandLangGraph
π§° Tech Stack
| Layer | Tools |
|---|---|
| Backend API | FastAPI, Uvicorn |
| Pipeline Core | Python 3.12, Pydantic, SQLGlot |
| LLM Interface | pydantic-ai (OpenAI, Anthropic, Ollama) |
| Database | SQLite (default), PostgreSQL |
| Evaluation | Spider / Dr.Spider |
| UI | Streamlit + Plotly |
| Containerization | Docker / Docker Compose |
π License
MIT Β© 2025 Melika Kheirieh