raedmajid / schema-aware-ai-sql-agent

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.

Home Page:https://youtu.be/8PF6nWXB8iE

Repository from Github https://github.comraedmajid/schema-aware-ai-sql-agentRepository from Github https://github.comraedmajid/schema-aware-ai-sql-agent

🧠 Schema-Aware AI SQL Agent

βš™οΈ Translate natural language into secure, production-ready SQL β€” built for real-world enterprise use.
βœ… Built with LangChain, FastAPI, Streamlit, and your preferred LLMs.
πŸ” Enforces schema validation, RBAC, RLS, and query sanitization.


πŸ” What It Does

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.

🎬 Watch the Walkthrough Video
πŸ‘‰ https://youtu.be/8PF6nWXB8iE


✨ Key Features

  • πŸ’¬ 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

🧩 Architecture Snapshot

A high-level view from UI to LLM to SQL execution:

System Architecture


πŸš€ Quickstart

Prefer a visual walkthrough? Watch the full setup & architecture demo here

git 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 values

Start the backend:

uvicorn backend.api.api:app --host 127.0.0.1 --port 8000 --reload

Start the frontend UI:

python3 -m streamlit run frontend/chat_UI.py

Access the app at http://localhost:8501


πŸ“– Full Documentation

For detailed setup, advanced features, and system architecture, see:
πŸ‘‰ README_FULL.md

Tip: Use Ctrl+Shift+V (or Cmd+Shift+V on Mac) in most editors to preview markdown files.


πŸ› οΈ License

MIT License β€” use it, modify it, build on it.

About

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.

https://youtu.be/8PF6nWXB8iE

License:MIT License


Languages

Language:Python 100.0%