DB Assistant 📊👨🏻‍🏭

DB Assistant is an interactive AI-powered SQL agent built with Gradio and LangChain.
It enables users to connect to any relational database, ask natural language questions, and receive data-driven answers in real time — no manual SQL writing required.


  • Natural Language to SQL Conversion
    Ask questions like “Which genre has the longest tracks?” or “List the top 5 customers by purchase amount.”
    The assistant automatically generates and executes optimized SQL queries against your connected database.

  • Live SQL Agent Streaming
    The model’s reasoning, query generation, and intermediate steps are streamed to the interface, allowing you to see exactly how the LLM builds and refines its queries.

  • Collapsible Debug Panels (AI & Tool Messages)
    Intermediate tool calls and SQL executions are neatly displayed in collapsible accordions, making the output transparent yet organized.

  • Multi-Provider LLM Support
    Choose from a variety of providers:

    • 🧠 Google GenAI (Gemini 2.x)
    • 💬 OpenAI (GPT-4, GPT-4o, GPT-3.5)
    • 🦣 Anthropic (Claude-3 series)
    • ☁️ Azure OpenAI, AWS Bedrock, xAI, DeepSeek, Perplexity, and more.
      The interface automatically updates the available model list based on your provider choice.
  • Secure Database Connectivity
    Connect to SQL databases via a simple connection string — supporting SQLite, PostgreSQL, MySQL, and others through LangChain’s SQLDatabase utility.

  • Transparent Query Execution
    The agent inspects tables, analyzes schemas, and constructs precise SQL queries, always respecting safety rules (no DML statements like INSERT, UPDATE, DELETE, DROP).

  • Intuitive Gradio Interface
    Built with gr.Blocks() for clean layout:

    • Left Panel: LLM setup and database connection
    • Right Panel: Interactive chatbot and conversation history
    • Expandable sections for metadata and project credits

Component Purpose
LangChain Framework for connecting LLMs with external data tools
SQLDatabaseToolkit Provides database inspection, schema parsing, and safe query execution
Gradio Creates a user-friendly web UI for chatting with the agent
Python Core application logic and integration
Markdown + HTML Enhanced output formatting with collapsible accordions
Base64 Encoding Used to embed custom logo images directly in the interface

  1. Setup LLM
    Select your preferred provider and model, enter the corresponding API key, and click Setup LLM.

  2. Connect Database
    Paste your SQL connection string (e.g., sqlite:///Chinook.db or postgresql+psycopg2://user:pass@host/db) and click Connect.
    The app automatically lists available tables.

  3. Ask Questions
    Type a natural language question in the chat box — the agent:

    • Retrieves the database schema,
    • Generates SQL queries,
    • Executes them safely,
    • Returns a human-readable explanation and result summary.
  4. Inspect Reasoning
    Expand the AI Message or Tool Message accordions to see exactly what the model did under the hood (SQL statements, schema checks, etc.).


LLM Setup

Select Provider
Select Model

Database Connection

Chatbot Interface

User:

Which genre on average has the longest tracks?

AI Assistant:

  • 📊 Generates a SQL query joining Track and Genre tables
  • 🧩 Computes average Milliseconds per genre
  • 🧠 Returns:

On average, the genre with the longest tracks is "Sci-Fi & Fantasy",
followed by "Science Fiction", "Drama", and "TV Shows".


  • Data analysts and engineers exploring new databases
  • BI professionals needing quick insights without SQL writing
  • Educators demonstrating database–AI integration
  • Developers testing and debugging database schemas via conversational interface

  • ✅ Add visualizations (bar charts, pie charts) for query results
  • ✅ Support multiple database sessions
  • ✅ Enable query caching and history tracking
  • ✅ Integrate authentication for enterprise deployments

Developed using:

  • LangChain Community Modules
  • Gradio UI Framework
  • Python 3.12+

This project bridges the gap between conversational AI and structured data analytics, giving everyone a personal SQL-powered data assistant at their fingertips. 🤖💾


© 2025

This website is made with ❤ by SARATH CHANDRA