Convert natural language questions into SQL using Amazon Bedrock (Claude 3 Haiku). Includes a safety layer that blocks all destructive operations and returns only SELECT statements.
Writing SQL is a barrier to data access for non-technical users. SQLGenie removes that barrier: type a question in plain English, get a validated, safe SQL query back in under a second, with an explanation of what it does and why.
Safety-first: Only SELECT statements are returned. Any query containing INSERT, UPDATE, DELETE, DROP, TRUNCATE, or ALTER is automatically rejected before it reaches the user.
Input: "Show me the top 5 customers by total order amount in the last 90 days"
SQL:
SELECT c.customer_id, c.name, SUM(o.total) as total_spend
FROM customers c
JOIN orders o ON c.customer_id = o.customer_id
WHERE o.created_at >= NOW() - INTERVAL '90 days'
GROUP BY c.customer_id, c.name
ORDER BY total_spend DESC
LIMIT 5;
Explanation: Joins customers with orders, filters to last 90 days,
groups by customer, sums totals, returns top 5 by spend.
Safety check: PASS - SELECT only, no destructive operations.
User question + schema selection
|
v
FastAPI /generate endpoint
|
v
Prompt builder (schema + question -> structured prompt)
|
v
Amazon Bedrock (Claude 3 Haiku)
|
v
SQL extractor (parse SQL from LLM response)
|
v
Safety validator (SELECT-only enforcement)
|
|-- PASS -> return SQL + explanation
|-- FAIL -> return 400 + reason
Key design decisions:
- Schema injected into prompt so Claude understands your table structure
- Safety check runs on extracted SQL, not raw LLM output (avoids false positives)
- Three built-in schemas let you test without a real database
- Stateless API: each request is fully self-contained
| Component | Technology |
|---|---|
| LLM | Amazon Bedrock (Claude 3 Haiku) |
| API | FastAPI + uvicorn |
| Frontend | Streamlit |
| Containerization | Docker |
git clone https://github.com/Rajeshdevandla/sql-genie.git
cd sql-genie
cp .env.example .env
# Fill in your AWS credentials
pip install -r requirements.txt
uvicorn api.main:app --reloadAPI docs auto-generated at: http://localhost:8000/docs
Required environment variables:
| Variable | Description |
|---|---|
AWS_REGION |
AWS region (e.g. us-east-1) |
AWS_ACCESS_KEY_ID |
IAM user access key |
AWS_SECRET_ACCESS_KEY |
IAM user secret key |
docker build -t sql-genie .
docker run -p 8000:8000 --env-file .env sql-genie| Method | Path | Description |
|---|---|---|
| GET | /health | Health check |
| GET | /schemas | List available sample schemas |
| POST | /generate | Generate SQL from a question |
Generate SQL:
curl -X POST http://localhost:8000/generate \
-H "Content-Type: application/json" \
-d '{"question": "Show me top 5 customers by total order amount", "schema_name": "ecommerce"}'Response:
{
"sql": "SELECT customer_id, name, SUM(total) FROM orders GROUP BY 1,2 ORDER BY 3 DESC LIMIT 5;",
"explanation": "Groups orders by customer, sums totals, returns top 5 by spend.",
"safety_check": "PASS",
"schema_used": "ecommerce"
}Rejected query:
{
"detail": "Safety check failed: query contains prohibited operation DROP."
}- ecommerce -
customers,orders,products,order_items - hr -
employees,departments,projects - analytics -
events,sessions,users
sql-genie/
|-- config.py # env var config and validation
|-- core/
| |-- sql_generator.py # NL-to-SQL pipeline + safety validation
|-- api/
| |-- main.py # FastAPI routes
|-- frontend/
| |-- app.py # Streamlit UI
|-- schemas/ # built-in sample schemas
|-- requirements.txt
|-- .env.example
|-- Dockerfile
- Real DB connection - execute validated query against a live database and return actual results
- Schema auto-detection - infer schema from a live DB connection instead of manual input
- SQL parser safety - replace keyword matching with
sqlparsefor more accurate validation - Query history - save past queries with ratings for reuse and refinement
- Live hosted demo - deploy to Hugging Face Spaces
- AskDocs AI - PDF RAG chatbot using Amazon Bedrock and FAISS
- AgentFlow - Multi-agent orchestration with Constitutional AI safety layer
- SupportGPT - AI customer support with sentiment-aware escalation
Built by Rajesh Kumar - Full Stack Java & AI Developer | Chicago, IL# SQLGenie
Convert natural language questions into SQL using Amazon Bedrock (Claude 3 Haiku). Includes a safety layer that blocks all destructive operations and returns only SELECT statements.
Writing SQL is a barrier to data access for non-technical users. SQLGenie removes that barrier: type a question in plain English, get a validated, safe SQL query back in under a second, with an explanation of what it does and why.
Safety-first: Only SELECT statements are returned. Any query containing INSERT, UPDATE, DELETE, DROP, TRUNCATE, or ALTER is automatically rejected before it reaches the user.
Input: "Show me the top 5 customers by total order amount in the last 90 days"
SQL:
SELECT c.customer_id, c.name, SUM(o.total) as total_spend
FROM customers c
JOIN orders o ON c.customer_id = o.customer_id
WHERE o.created_at >= NOW() - INTERVAL '90 days'
GROUP BY c.customer_id, c.name
ORDER BY total_spend DESC
LIMIT 5;
Explanation: Joins customers with orders, filters to last 90 days,
groups by customer, sums totals, returns top 5 by spend.
Safety check: PASS - SELECT only, no destructive operations.
User question + schema selection
|
v
FastAPI /generate endpoint
|
v
Prompt builder (schema + question -> structured prompt)
|
v
Amazon Bedrock (Claude 3 Haiku)
|
v
SQL extractor (parse SQL from LLM response)
|
v
Safety validator (SELECT-only enforcement)
|
|-- PASS -> return SQL + explanation
|-- FAIL -> return 400 + reason
Key design decisions:
- Schema injected into prompt so Claude understands your table structure
- Safety check runs on extracted SQL, not raw LLM output (avoids false positives)
- Three built-in schemas let you test without a real database
- Stateless API: each request is fully self-contained
| Component | Technology |
|---|---|
| LLM | Amazon Bedrock (Claude 3 Haiku) |
| API | FastAPI + uvicorn |
| Frontend | Streamlit |
| Containerization | Docker |
git clone https://github.com/Rajeshdevandla/sql-genie.git
cd sql-genie
cp .env.example .env
# Fill in your AWS credentials
pip install -r requirements.txt
uvicorn api.main:app --reloadAPI docs auto-generated at: http://localhost:8000/docs
Required environment variables:
| Variable | Description |
|---|---|
AWS_REGION |
AWS region (e.g. us-east-1) |
AWS_ACCESS_KEY_ID |
IAM user access key |
AWS_SECRET_ACCESS_KEY |
IAM user secret key |
docker build -t sql-genie .
docker run -p 8000:8000 --env-file .env sql-genie| Method | Path | Description |
|---|---|---|
| GET | /health | Health check |
| GET | /schemas | List available sample schemas |
| POST | /generate | Generate SQL from a question |
Generate SQL:
curl -X POST http://localhost:8000/generate \
-H "Content-Type: application/json" \
-d '{"question": "Show me top 5 customers by total order amount", "schema_name": "ecommerce"}'Response:
{
"sql": "SELECT customer_id, name, SUM(total) FROM orders GROUP BY 1,2 ORDER BY 3 DESC LIMIT 5;",
"explanation": "Groups orders by customer, sums totals, returns top 5 by spend.",
"safety_check": "PASS",
"schema_used": "ecommerce"
}Rejected query:
{
"detail": "Safety check failed: query contains prohibited operation DROP."
}- ecommerce -
customers,orders,products,order_items - hr -
employees,departments,projects - analytics -
events,sessions,users
sql-genie/
|-- config.py # env var config and validation
|-- core/
| |-- sql_generator.py # NL-to-SQL pipeline + safety validation
|-- api/
| |-- main.py # FastAPI routes
|-- frontend/
| |-- app.py # Streamlit UI
|-- schemas/ # built-in sample schemas
|-- requirements.txt
|-- .env.example
|-- Dockerfile
- Real DB connection - execute validated query against a live database and return actual results
- Schema auto-detection - infer schema from a live DB connection instead of manual input
- SQL parser safety - replace keyword matching with
sqlparsefor more accurate validation - Query history - save past queries with ratings for reuse and refinement
- Live hosted demo - deploy to Hugging Face Spaces
- AskDocs AI - PDF RAG chatbot using Amazon Bedrock and FAISS
- AgentFlow - Multi-agent orchestration with Constitutional AI safety layer
- SupportGPT - AI customer support with sentiment-aware escalation
Built by Rajesh Kumar - Full Stack Java & AI Developer | Chicago, IL