Abstract
Schema Aware AI SQL Agent is an open-source Cybersecurity & Ethical Hacking project. This project enables users to **generate SQL queries from natural language** using **LLM** of their choice while enforcing **Role-Based Access Control (RBAC)** and **Row-Level Security (RLS)**. It also includes **SQL injection detection** and **sensitive data logging** for compliance and security. The Schema-Aware AI SQL Agent bridges the gap between LLMs and production databases. It turns plain English into SQL — safely — with full guardrails in place. It is built using Python, LangChain. Key capabilities include: Natural language to SQL with LLMs (OpenAI, OpenRouter, Ollama); Role-based access control (RBAC) and row-level security (RLS); Schema-aware validation and SQL sanitization. The complete source code is publicly available on GitHub under the MIT License, making it a useful reference for students building a Cybersecurity & Ethical Hacking mini project or final-year project.
1. Introduction
The Schema-Aware AI SQL Agent bridges the gap between LLMs and production databases. It turns plain English into SQL — safely — with full guardrails in place.
Built entirely in Python with open-source tools, it’s designed for environments where security, compliance, and accuracy matter.
2. Objective
This project enables users to **generate SQL queries from natural language** using **LLM** of their choice while enforcing **Role-Based Access Control (RBAC)** and **Row-Level Security (RLS)**. It also includes **SQL injection detection** and **sensitive data logging** for compliance and security.
This project demonstrates how Python, LangChain can be applied to a real-world Cybersecurity & Ethical Hacking problem.
3. Key Features / Modules
- Natural language to SQL with LLMs (OpenAI, OpenRouter, Ollama)
- Role-based access control (RBAC) and row-level security (RLS)
- Schema-aware validation and SQL sanitization
- Memory-aware chat agent with clarification flow
- REST API + Streamlit front-end
- Sample PostgreSQL database (Northwind) included for testing
4. Technology Stack
5. System Requirements
General requirements for this technology stack — check the README for exact versions.
- Python 3.8 or later
- pip / virtualenv for dependencies
- VS Code, PyCharm or Jupyter Notebook
- Git (to clone the repository)
6. Installation & Setup
git clone https://github.com/raedmajid/schema-aware-ai-sql-agent.git
cd schema-aware-ai-sql-agentgit clone https://github.com/raedmajid/schema-aware-ai-sql-agent
cd schema-aware-ai-sql-agent
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
cp .env.example .env # then edit with your valuesuvicorn backend.api.api:app --host 127.0.0.1 --port 8000 --reloadpython3 -m streamlit run frontend/chat_UI.pyFull setup instructions are in the project README.
7. Future Enhancements
Suggested extensions you can add to make this your own project.
- Add logging and alert notifications (email / Telegram)
- Write a threat model document for the tool
- Package it with Docker for safe lab testing
8. Viva / Review Questions
Common questions examiners ask for projects in this domain.
- Which threat or attack does this project defend against?
- What detection or protection technique is used and what are its limits?
- How are false positives and false negatives handled?
- Which cryptographic algorithms or security standards are involved?
- What legal and ethical rules apply when testing a tool like this?
9. Source Code & License
This project is developed by raedmajid and published on GitHub under the MIT License. Please follow the license terms and credit the original author when you use or modify this code.
Want to build this as your internship project?
Work on a Cybersecurity & Ethical Hacking project like this with mentor guidance, weekly reviews and an internship certificate from Training Trains, Erode — online or offline.
Apply for Cybersecurity & Ethical Hacking Internship