An advanced NLP-powered system that converts natural language queries into executable SQL using Large Language Models (LLMs), with built-in schema awareness and automatic error correction.
QueryGenie allows users to interact with databases using plain English instead of writing SQL queries manually. It leverages modern NLP techniques and LLM capabilities to understand user intent, generate SQL queries, execute them, and return structured results.
This project demonstrates how natural language interfaces can simplify database interactions and improve accessibility for non-technical users.
-
Converts user queries like:
- “Show students in Data Science class”
- into valid SQL queries automatically.
- Dynamically reads database schema
- Ensures generated queries match actual table structure
- Reduces hallucinations and errors
- Detects SQL execution failures
- Uses LLM to refine and fix incorrect queries
- Improves robustness and reliability
-
Clean and responsive interface
-
Displays:
- Generated SQL
- Query results in table format
-
Provides user-friendly interaction
-
Supports queries across:
STUDENTMARKSCOURSES
-
Handles JOIN operations automatically
This project is not just an API wrapper — it applies real NLP concepts:
-
Natural Language Understanding (NLU) Interpreting user intent from free-text input
-
Semantic Parsing Converting natural language → structured SQL queries
-
Prompt Engineering Designing structured prompts for accurate LLM output
-
Context Injection (Schema Awareness) Providing database schema to guide model reasoning
-
Iterative Refinement Using error feedback to improve generated queries
| Component | Technology Used |
|---|---|
| Language | Python |
| UI Framework | Streamlit |
| Database | SQLite |
| LLM Backend | Google Gemini API |
| Data Handling | Pandas |
| Environment | python-dotenv |
QueryGenie/
│
├── app.py # Main Streamlit application
├── sql.py # Database utilities (if used)
├── student.db # Sample SQLite database
├── requirements.txt # Dependencies
├── .env # API key (NOT included in repo)
├── README.md # Project documentationgit clone https://github.com/your-username/querygenie.git
cd querygeniepip install -r requirements.txtCreate a .env file in the root directory:
GOOGLE_API_KEY=your_api_key_here
.env to GitHub
streamlit run app.pyTry asking:
- Show all students
- List students in Data Science class
- Show students with marks greater than 80
- Display student names along with their marks
- User inputs a natural language query
- Schema is extracted from the database
- Prompt + schema + query → sent to LLM
- SQL query is generated
- Query is executed on SQLite
- If error occurs → auto-correction triggered
- Final result displayed to user
- Educational tools for learning SQL
- Natural language database querying
- Business analytics without SQL knowledge
- Rapid data exploration
- Dependent on LLM API availability and quota
- Performance may vary based on prompt quality
- Limited to predefined schema (can be extended)
- Chat-style conversational interface
- Support for PostgreSQL / MySQL
- Query explanation in natural language
- Visualization (charts/graphs)
- Offline fallback models
Gautam N Chipkar GitHub: gee-46
If you found this project useful:
- ⭐ Star the repository
- 🍴 Fork it
- 💡 Use it in your own projects
This project is open-source and available under the MIT License.