Skip to content

bhavyam3011/SQL-Agent-V2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

SQL Agent – Natural Language Database Interface (v2)

Using LangChain-Langgraph

v1 without Langgraph

πŸ“Œ Overview

This project implements a natural-language to SQL agent that allows users to query and modify multiple mock databases using plain English. It supports CRUD operations with a human-in-the-loop verification system to ensure safe database modifications.

The project is built with:

  • Python + FastAPI for backend REST API
  • SQLite for multiple mock databases (HR, Healthcare, E-commerce, Finance, Education)

πŸš€ Features

  • πŸ”Ή Interact with 5 mock databases (hr.db, healthcare.db, ecommerce.db, finance.db, education.db)
  • πŸ”Ή Natural language CRUD support (Read/Write/Update/Delete)
  • πŸ”Ή Human-in-the-loop approval for Create/Update/Delete before commit
  • πŸ”Ή Pending queue manager to track and approve/reject modifications
  • πŸ”Ή FastAPI REST endpoints with interactive Swagger UI

βš™οΈ Setup

1. Clone the Repository

git clone https://github.com/your-username/mini-sql-agent.git
cd mini-sql-agent

2. Create Virtual Environment (Optional)

python -m venv venv
source venv/bin/activate   # on Linux/Mac
venv\Scripts\activate      # on Windows

3. Install Dependencies

pip install -r requirements.txt
after completed,
pip install langchain_google_genai

4. Environment Variables

Create a .env file in the project root and add your Gemini API key:

GEMINI_API_KEY=your_api_key_here

5. Run FastAPI App

with Uvicorn:

uvicorn main:app --reload --port 8000

πŸ–₯️ API Usage

Once running, access:

  • API Docs: [http://localhost:8000/docs] (http://localhost:8000/docs) and initialize database and test your nl-queries
  • Example endpoint: /query?text=Show all employees in HR&db=hr
  • Make sure that the backend url set in app.js is same as localhost port, else change it accordingly.

FASTAPI Screenshots and also with Frontend.

Screenshot (218) Screenshot (219) Screenshot (238) Screenshot (239) Screenshot (240) Screenshot (241) Screenshot (242) Screenshot (243) Screenshot (244) Screenshot (245) Screenshot (246)

LangGraph Workflow

ss

βœ… Status

This is a classic agentic made with (langchain-LangGraph) but yet slow with other LLMs. Do try LangSmith Integration, added in the requirements. Add your LangSmith api directly via env file.


=======

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published