Skip to content

dffesalbon-python/llm-inquiry-agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LLM-Powered Database Assistant

An agentic LLM-powered assistant that converts natural language into SQL queries, executes them safely, and returns conversational answers from a PostgreSQL database.


Project Overview

This project implements a Text-to-SQL system with tool-augmented reasoning, enabling users to interact with a database using plain English.

Features

  • Natural language → SQL query generation
  • Safe SQL execution (read-only)
  • Conversational response synthesis
  • Dynamic schema awareness
  • Modular workflow using LangGraph

Architecture Overview


Workflow

flowchart LR
    A[User Input] --> B[SQL Generator LLM]
    B --> C[DB Executor]
    C --> D[Result Synthesizer LLM]
    D --> E[Final Answer]

    C --> F[(PostgreSQL DB)]
    B --> F
Loading

Approach

Agentic Workflow (LangGraph-based)

This system follows a structured agentic pipeline:

  • Text-to-SQL Agent Generates SQL queries from user input

  • Tool Augmentation Uses:

    • Database schema inspection
    • SQL execution tools

Components

1. SQL Generator

  • Converts user queries into SQL
  • Uses schema context for accuracy

2. DB Executor

  • Executes SQL queries
  • Restricts to SELECT only

3. Schema Inspector

  • Retrieves:
    • Tables
    • Columns
    • Relationships

4. Result Synthesizer

  • Converts SQL results into conversational responses

5. Workflow Engine

  • Managed via LangGraph
  • Controls execution flow and state

Stack

  • LLM: LLaMA 3.2 (via Ollama)
  • Orchestration: LangGraph
  • Framework: LangChain
  • Database: PostgreSQL
  • ORM: SQLAlchemy

Safety Measures

  • Only allows SELECT queries (read-only)
  • Blocks INSERT / UPDATE / DELETE
  • Schema-aware prompting to reduce hallucinations

Installation

# Clone the repo
git clone <your-repo-url>
cd <your-repo>

# Install dependencies
pip install -r requirements.txt

Environment Variables

Create a .env file:

DB_USER=your_user
DB_PW=your_password
DB_HOST=localhost
DB_PORT=5432
DB_NAME=your_db

Running the App

python main.py

Example Usage

You: Show me all customer accounts with balances above 10,000
AI: Here are the accounts with balances above 10,000...

Project Classification

This project can be described as:

  • Agentic LLM Workflow
  • Tool-Augmented LLM System
  • Text-to-SQL Application

Future Improvements

  • Add memory (conversation history)
  • Add retry & error handling
  • Add query validation layer
  • Integrate vector DB for hybrid retrieval
  • Add evaluation benchmarks

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages