An AI-powered web application that allows users to convert natural language queries into SQL queries and retrieve results from a connected database. This tool bridges the gap between human language and database interaction, enabling non-technical users to access structured data efficiently.
👉 Live App: Intelligent SQL Assistant
- ✅ Convert natural language to SQL queries using LLMs
- ✅ View both the generated SQL and query results
- ✅ Simple and clean Streamlit UI
- ✅ Supports dynamic database schema
- ✅ Includes sample
users
andproducts
tables for testing - ✅ Error handling for invalid queries
- User Input: User enters a query in plain English (e.g., “Show all products with price greater than 500”).
- LLM Translation: The app uses an LLM to convert the input to a valid SQL query.
- SQL Execution: The SQL query is executed on the connected SQLite database.
- Display: Results and the SQL query are shown to the user in a readable format.
CREATE TABLE users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
age INTEGER,
email TEXT
);
INSERT INTO users (name, age, email)
VALUES
('Alice', 25, 'alice@example.com'),
('Bob', 30, 'bob@example.com');
CREATE TABLE products (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
price REAL,
stock INTEGER
);
INSERT INTO products (name, price, stock)
VALUES
('Laptop', 799.99, 10),
('Headphones', 199.99, 50),
('Mouse', 25.50, 100);
- "Show all users older than 25"
- "List all products with stock less than 20"
- "What is the average price of products?"
- "Count the number of users"
- "Get the names of products priced above 200"
- Frontend: Streamlit
- Backend: Python + SQLite
- AI Engine: Large Language Model (LLM) via OpenAI or compatible provider
- Database: SQLite (local and in-memory)
├── main.py # Streamlit app entry point
├── database.db # SQLite database file
├── models/ # Folder for prompt and LLM logic
│ └── llm_utils.py
├── utils/ # Utility functions for SQL execution and display
│ └── sql_executor.py
├── requirements.txt
└── README.md # This file
git clone https://github.com/yourusername/intelligent-sql-assistant.git
cd intelligent-sql-assistant
python -m venv venv
# Activate environment
# On Windows:
venv\Scripts\activate
# On Mac/Linux:
source venv/bin/activate
pip install -r requirements.txt
streamlit run main.py
If using OpenAI or another LLM API:
OPENAI_API_KEY=your_openai_api_key
- 🔄 Add support for other databases (PostgreSQL, MySQL)
- 🧠 Model fine-tuning with user feedback
- 🧾 Natural language INSERT, UPDATE, DELETE support
- 📊 Visualize SQL results (charts and graphs)
Hemavathi
Data Scientist & AI Developer
🌐 LinkedIn | ✨ Portfolio
This project is licensed under the MIT License - see the LICENSE file for details.