SQL Generate allows users to query databases in plain English. Converts natural language questions into executable SQL queries using LLMs, with a fast FastAPI backend and a Next.js frontend.
- Natural Language to SQL: Write complex queries in plain English.
- Dynamic Schema Introspection: Automatically reflect and onboard your live database schemas using SQLAlchemy.
- Schema-Aware Context Retrieval: Uses cosine similarity to retrieve only the most relevant tables and schema descriptions.
- Frontend: A Next.js frontend.
- Frontend: Next.js (React), Tailwind CSS, Framer Motion, Lucide Icons.
- Backend: FastAPI, Python 3.11, SQLAlchemy.
- LLM Integrations: Support for Claude, GPT-4o, and local models via Ollama.
sql-generate/
├── backend/ # Python/FastAPI backend logic and LLM orchestration
└── frontend/ # Next.js UI application
- Node.js (v18+)
- Python (v3.9+)
- A Live Database (e.g., PostgreSQL) for dynamic introspection.
- API Keys for the LLM of your choice (Anthropic/OpenAI) or Ollama installed locally.
- Navigate to the backend directory:
cd backend - Create and activate a virtual environment (recommended):
python3 -m venv .venv source .venv/bin/activate - Install dependencies:
pip install -r requirements.txt
- Environment Configuration:
Copy
.env.exampleto.envand fill in your keys:Make sure to configurecp .env.example .env
DATABASE_URLfor live schema introspection and your chosen LLM API keys. - Run the FastAPI server:
The backend will be available at
uvicorn app.main:app --reload
http://localhost:8000.
- Navigate to the frontend directory:
cd frontend - Install Node.js dependencies:
npm install
- Start the Next.js development server:
npm run dev
- Access the UI: Open
http://localhost:3000in your browser.
If you want to interact with the backend directly without the UI:
-
Generate SQL:
POST /querycurl -X POST http://localhost:8000/query \ -H "Content-Type: application/json" \ -d '{"question": "Who are the top 5 customers by total revenue this month?"}'
-
View Current Schema:
GET /schemacurl http://localhost:8000/schema
You can deploy the backend via Docker:
cd backend
docker build -t sql-generate-backend .
docker run -p 8000:8000 --env-file .env sql-generate-backendEnsure strict API rate limiting, audit logging, and never run generated SQL on write-nodes. AI can make mistakes.