Personal Project

NL2SQL Bot

Multi-agent system that converts natural language to validated SQL with safe execution and interactive visualization.

Multi-Agent Orchestration SQL-First RAG Security-Hardened

The Problem

Business users need answers from databases but can't write SQL. Existing chatbots either generate unsafe queries or produce results that are hard to interpret. NL2SQL Bot bridges this gap with a multi-agent pipeline that understands intent, generates validated SQL, and renders interactive visualizations — all in one conversation.

Built during my internship at Kaixin Technology, this system was designed for production fintech terminals where correctness and security are non-negotiable. Every query passes through 18 SQL security checks before execution, with table allowlisting and dialect-aware validation across MySQL, PostgreSQL, and SQLite.

The system uses Google ADK (Agent Development Kit) to orchestrate 5 specialized agents with session state passing, loop-guarded retry mechanisms, and per-agent LLM overrides for optimal cost-performance tuning.

Technical Highlights

  • 5-Agent Orchestration

    Intent classifier, SQL generator, SQL validator, execution engine, and visualization agent — each with dedicated LLM overrides and session state passing for optimal performance.

  • Security-First Execution

    Read-only execution enforced through 18 blocked SQL patterns, table allowlisting, and abstracted dialect rules. No DROP, DELETE, or UPDATE ever reaches the database.

  • Smart Visualization

    Results are automatically rendered as interactive Plotly.js charts — bar graphs, line charts, or tables — chosen based on the query structure and data shape.

  • Loop-Guarded Retry

    When SQL validation fails, the system retries with corrective context — but with hard iteration limits to prevent infinite loops and cost runaway.

Under The Hood

Agent Pipeline

Google ADK orchestrates a linear pipeline: Intent Classification → SQL Generation → Validation → Execution → Visualization. Each agent receives structured context from the previous stage via session state, enabling precise handoffs.

Dialect Abstraction

The SQL generator produces dialect-aware queries using abstracted rules for MySQL, PostgreSQL, and SQLite. Schema introspection happens at startup, and table metadata is injected into the generation prompt for accurate column references.

Streaming Results

FastAPI endpoints stream SQL, reasoning traces, and chart-ready JSON as they're produced. The frontend receives real-time updates showing the bot's thought process alongside the final visualization.

Product Demo

Screenshots and interactive demo coming soon