Why simple "prompt β SQL" fails, and how 12 specialized agents fix it.
π Live Demo β
| β Naive Approach | β ReasonSQL |
|---|---|
| Schema + Question β LLM β SQL | 12 Specialized Agents in Pipeline |
| Hallucinates table names | Explores schema BEFORE generating |
| Assumes meaning of "recent", "best" | Asks clarifying questions |
| Returns errors, not answers | Self-corrects on failures |
| No safety (SELECT * on 1M rows) | Safety-validated, enforces LIMIT |
| Black box | Full reasoning trace visible |
Result: ~50% accuracy β 85%+ on complex queries
- 12 Specialized AI Agents β Intent analysis, schema exploration, SQL generation, safety validation, self-correction, response synthesis
- Batch-Optimized Pipeline β Only 4-6 LLM calls per query (vs. 12+ with naive approaches)
- Self-Correction β Automatically retries and fixes errors
- Safety Validation β Blocks DROP/DELETE/UPDATE, enforces SELECT-only with LIMIT
- SQL Syntax Highlighting β Color-coded keywords, strings, numbers, functions
- Copy Buttons β One-click copy for answers and generated SQL
- CSV Export β Download query results as CSV
- Shareable Links β Share queries via URL (
?q=your+query) - Keyboard Shortcuts β
Ctrl+Enterto submit queries - Saved Queries / Bookmarks β Star queries for quick re-use
- Query Suggestions β Preset query pills for quick exploration
- Live Execution Timer β Real-time countdown while processing
- Toast Notifications β Slide-in feedback for all actions
- Schema Explorer β Browse database tables and columns in the sidebar
- System Status β Live connection indicators for API and database
- Agent Pipeline Visualization β See which agents ran in sequence
- Architecture Section β Expandable "How it works" with agent descriptions
- Responsive Design β Collapsible sidebar with hamburger menu on mobile
- Analytics Dashboard β Query stats, success rate chart, top queries (
/dashboard) - PWA Support β Installable on mobile/desktop
- OpenGraph Social Preview β Branded card when sharing on LinkedIn/Twitter
- Async Pipeline β Fully asynchronous with
asyncpgfor non-blocking database calls - Redis Caching β LLM response caching with automatic in-memory fallback
- Multi-turn Context β Follow-up questions with pronoun resolution ("show me their albums")
- Vector Search (RAG) β Semantic schema selection for large databases (15+ tables)
- CSV Upload β
POST /uploadendpoint to ingest CSV files on-the-fly - PostgreSQL + SQLite β Supabase PostgreSQL in production, SQLite for local dev
- CI/CD Pipeline β GitHub Actions for automated testing on push/PR
- Quota Management β Gemini API key rotation and rate limiting
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Next.js Frontend β
β ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ β
β β Query β β Schema β β Dashboardβ β System β β
β β Input β β Explorer β β /dashboardβ β Status β β
β ββββββ¬ββββββ ββββββββββββ ββββββββββββ ββββββββββββ β
β β β
βββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β POST /query
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β FastAPI Backend β
β β
β βββββββββββ βββββββββββ ββββββββββββ ββββββββββββββ β
β β Intent ββ β Schema ββ β SQL ββ β Safety β β
β βAnalyzer β βExplorer β βGenerator β β Validator β β
β βββββββββββ βββββββββββ ββββββββββββ βββββββ¬βββββββ β
β β β
β βββββββββββ βββββββββββ ββββββββββββ βββββββΌβββββββ β
β βResponse ββ β Self ββ β Query ββ β FK β β
β β Synth β βCorrectorβ β Executor β β Validator β β
β βββββββββββ βββββββββββ ββββββββββββ ββββββββββββββ β
β β
βββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββ
β PostgreSQL (Supabase) β
β or SQLite (local) β
βββββββββββββββββββββββββ
# 1. Clone & install backend
git clone https://github.com/The-Harsh-Vardhan/ReasonSQL.git
cd ReasonSQL
pip install -r requirements.txt
# 2. Configure environment
cp .env.example .env
# Add your GEMINI_API_KEY to .env
# 3. Start backend
python -m uvicorn backend.api.main:app --port 8000
# 4. Start frontend (new terminal)
cd frontend-next
npm install && npm run dev
# Visit http://localhost:3000| Variable | Required | Description |
|---|---|---|
GEMINI_API_KEY |
β | Google Gemini API key |
DATABASE_URL |
For PostgreSQL | Supabase connection string |
DATABASE_PATH |
For SQLite | Path to .db file (default: data/chinook.db) |
NEXT_PUBLIC_API_URL |
For deploy | Backend API URL |
ReasonSQL/
βββ backend/ # Core modular API (FastAPI)
β βββ api/ # Routers, deps, schemas
β βββ agents/ # 12 specialized agent definitions
β βββ orchestrator/ # Multi-agent logic
β βββ adapters/ # DB Adapters (SQLite/Postgres)
βββ frontend-next/ # Next.js 16 Dashboard
βββ tests/ # API and Integration tests
βββ data/ # Sample datasets (Chinook)
βββ configs/ # Environment & provider configs
βββ docs/ # Hosting & usage guides- Ask a Question: Type any natural language question about the database (e.g., "Who are the top 10 customers by spend?").
- Observe the Reasoning: Click the "Reasoning" tab to see how the 12 agents analyzed your intent, explored the schema, and validated the SQL.
- Review Results: View the generated SQL and the live data preview in the "Result" tab.
- Export & Share: Download results as CSV or share the specific query URL with your team.
| Platform | Component | Free Tier | Status |
|---|---|---|---|
| Vercel | Next.js Frontend | β Free | Live β |
| Render | FastAPI Backend | β 750 hrs/mo | Active |
| Supabase | PostgreSQL DB | β 500MB | Connected |
See HOSTING.md for detailed instructions.
- Hosting Guide β Step-by-step Supabase, Render, Vercel setup
- Hosting Guide β Step-by-step Supabase, Render, Vercel setup
- Agent Pipeline β Complete 12-agent workflow (Legacy)
- Contributing Guide β How to contribute
- Contributing Guide β How to contribute
| Layer | Technology |
|---|---|
| Frontend | Next.js 16, React, Tailwind CSS |
| Backend | Python, FastAPI, Pydantic |
| LLM | Google Gemini (with key rotation) |
| Database | PostgreSQL (Supabase) / SQLite |
| Caching | Redis (with in-memory fallback) |
| Embeddings | sentence-transformers (all-MiniLM-L6-v2) |
| Hosting | Vercel (frontend) + Render (backend) |
| CI/CD | GitHub Actions |
| Analytics | Vercel Analytics |
MIT License β see LICENSE for details.
Contributions are welcome! Please read CONTRIBUTING.md for guidelines.
Built with ReasonSQL
12 Agents β’ 4 LLM Calls β’ Full Transparency
Live Demo β’
Source Code