Skip to content

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.

License

Notifications You must be signed in to change notification settings

raedmajid/schema-aware-ai-sql-agent

Repository files navigation

🧠 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.

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Languages