An AI-powered system that allows users to interact with PostgreSQL databases using natural language instead of SQL.
Users can create a personal database and query it using plain English. The system converts natural language → SQL → executes safely → returns structured results.
- React SPA (Vite)
- JWT-based authentication
- Database selector (1 DB per user in dev mode)
- Chat-style interface
- Query result modal (table + CSV export)
- Mutation confirmation modal
Flow:
User → Chat Input → /query API → Render Result
FastAPI REST API with:
- JWT Authentication
- Database creation endpoint
- Natural language query endpoint
- Confirmation handling for mutations
- Error middleware + structured logging (Loguru)
| Endpoint | Purpose |
|---|---|
/auth/* |
Login / Register |
/databases |
Create & fetch user DB |
/query |
Convert NL → SQL → Execute |
Used for:
- Converting natural language → PostgreSQL SQL
- Strict SQL-only generation
- No explanations, no markdown
- Temperature = 0.1 for deterministic output
Uses:
- LangChain
- FAISS vector store
- Schema embeddings
- Store database schema as embeddings
- Retrieve relevant schema context before SQL generation
- Reduce hallucination
- Improve table understanding
- Check SQL intent
- Validate table existence
- Detect mutation queries
- Require explicit confirmation
- Execute inside transaction
Mutation flow:
User → LLM generates INSERT/UPDATE/DELETE
→ Backend returns "confirmation_required"
→ User approves
→ Query executed
- 1 User → 1 PostgreSQL Database
- Database name stored in
User.database_name - Schema introspected dynamically
- Table names fetched using SQLAlchemy inspector
User Question
↓
Retrieve Schema (FAISS)
↓
Generate SQL (LLM)
↓
Validate SQL
↓
If mutation → Ask confirmation
↓
Execute Query
↓
Return structured result
- No raw SQL from user
- No automatic destructive execution
- Schema-aware generation
- Deterministic LLM behavior
- Clear error handling
- Modular architecture
- Multi-database per user (production mode)
- Fuzzy table matching
- Schema auto-reindexing
- Query history
- Role-based access
- Streaming LLM responses



