An AI-powered SQL assistant that converts plain English prompts into executable SQL queries, complete with sample outputs and explanations. Describe the data you want โ QueryMind generates the SQL instantly.
QueryMind is an AI-powered SQL query generator that translates natural language prompts into SQL queries using Googleโs Gemini AI.
Instead of manually writing complex SQL queries, users can simply describe the data they want in plain English, and the system will automatically:
- Generate the correct SQL query.
- Show a sample tabular output of the expected result.
- Provide a human-readable explanation of the query logic.
Built using Streamlit, the application offers an intuitive interface that allows developers, students, and analysts to quickly generate SQL queries without deep database expertise.
| Feature | Description |
|---|---|
| ๐ง AI-Powered SQL Generation | Converts natural language prompts into SQL queries |
| ๐ Sample Output Generation | Displays expected result tables |
| ๐ Query Explanation | Provides easy-to-understand explanation of SQL logic |
| โก Fast Interactive UI | Built with Streamlit for rapid interaction |
| ๐ Secure API Key Management | Uses .env configuration with python-dotenv |
| ๐ Learning Tool | Great for students learning SQL concepts |
graph TD
A[๐ค User Input - Natural Language] --> B[Streamlit Web Interface]
B --> C[Prompt Processing]
C --> D[Google Gemini AI]
D --> E[SQL Query Generation]
D --> F[Sample Output Generation]
D --> G[Query Explanation]
E --> H[Display Results in UI]
F --> H
G --> H
The system follows a simple yet effective pipeline:
1๏ธโฃ User Prompt
- The user enters a query request in plain English.
Example:
Retrieve employee names and departments from the employees table where department is Sales
2๏ธโฃ AI Interpretation
-
Gemini AI interprets the prompt and understands:
- table name
- fields
- conditions
3๏ธโฃ SQL Generation
- The model generates the corresponding SQL statement.
4๏ธโฃ Output Simulation
- The system generates a sample result table.
5๏ธโฃ Explanation
- Gemini explains the SQL query in simple terms.
| Component | Technology |
|---|---|
| Programming Language | Python |
| Web Framework | Streamlit |
| AI Model | Google Gemini AI |
| Environment Management | python-dotenv |
| Data Processing | Python Standard Libraries |
SQL-Query-Generator-using-Gemini-AI/
โ
โโโ app.py # Streamlit application
โโโ query_generator.py # Gemini AI prompt handler
โโโ utils/
โ โโโ prompt_templates.py
โ
โโโ requirements.txt # Python dependencies
โโโ .env # API key configuration
โโโ README.md
- Python 3.9+
- Google AI Studio API Key
git clone https://github.com/kishorekrrish3/SQL-Query-Generator-using-Gemini-AI.git
cd SQL-Query-Generator-using-Gemini-AIpip install -r requirements.txtOr install individually:
pip install streamlit
pip install google-generativeai
pip install python-dotenvCreate a .env file in the project root.
GOOGLE_API_KEY=your_google_api_key_here
The application automatically loads the key using python-dotenv.
Start the Streamlit application:
streamlit run app.pyThe application will run locally at:
http://localhost:8501
Example prompt:
Retrieve all employee names and departments from the employees table where the department is Sales
Click Generate SQL Query.
The system sends the prompt to Gemini AI.
The interface displays:
| Output | Description |
|---|---|
| SQL Query | Generated SQL statement |
| Sample Output | Example result table |
| Explanation | Human-readable query explanation |
Retrieve all employee names and departments from the employees table where the department is Sales
SELECT name, department
FROM employees
WHERE department = 'Sales';| name | department |
|---|---|
| John Doe | Sales |
| Jane Roe | Sales |
The query retrieves the name and department fields from the employees table, filtering records where the department equals Sales.
| Setting | File | Description |
|---|---|---|
| API Key | .env |
Google Gemini API authentication |
| Prompt Templates | prompt_templates.py |
Query generation prompts |
| Streamlit UI | app.py |
Interface and interaction logic |
Check that:
.envfile existsGOOGLE_API_KEYis valid- Internet connection is active
Restart the server:
streamlit run app.py- ๐ง Database schema awareness
- ๐ Direct database execution
- ๐ Visual query builder
- ๐ SQL learning mode for beginners
- ๐ Multi-database support (MySQL, PostgreSQL, SQLite)
Contributions are welcome.
- Fork the repository
- Create a feature branch
- Commit your changes
- Open a pull request
This project is licensed under the MIT License.
Making databases accessible through natural language.
QueryMind โ where English becomes SQL.