Agentic Data Visualization
Ask a question in plain English, get a live chart. No SQL, no BI tool, no analyst bottleneck.
The Problem
Business stakeholders can't access their own data without help from an analyst or engineer. Analysts spend 60-70% of their time answering one-off 'can you just pull X' requests instead of doing strategic work. Existing BI tools require pre-built dashboards and can't answer novel questions in real time.
My Role
AI engineer. Designed and implemented the ReAct agent loop, SQL generation and validation pipeline, chart-type selection heuristic, and React frontend. Built two parallel implementations (one with LangChain, one with LlamaIndex) to benchmark agent reasoning quality and latency.
Core Features
Natural Language to SQL Agent
A LangChain ReAct agent interprets the user's question, inspects the database schema via a tool, generates SQL, validates it against the schema, executes it, and returns structured results, all in one conversational turn.
Automatic Chart Type Selection
After query execution, the agent analyzes result shape (time-series vs. categorical vs. distribution) and selects the most appropriate chart type (line, bar, pie, scatter, or table) without user configuration.
Multi-Step Reasoning
Complex questions requiring JOINs, sub-queries, or aggregations across multiple tables are handled via multi-hop agent reasoning; the agent can issue multiple SQL queries and combine results.
Query Explanation & Transparency
Every chart includes an expandable 'How was this generated?' panel showing the SQL query, the agent's reasoning trace, and a plain-English interpretation of the result.
LangChain vs. LlamaIndex Benchmark
Built both frameworks side-by-side and benchmarked on accuracy (correct SQL generated), latency, and handling of ambiguous questions. Results documented in the README.
Tech Stack
Architecture Overview
FastAPI backend hosts the agent endpoint. The LangChain implementation uses a custom SQLDatabaseToolkit with schema introspection, a query validator tool that catches syntax errors before execution, and a chart selector tool that inspects result metadata. The LlamaIndex implementation uses NLSQLTableQueryEngine with a custom output parser. Both feed results to a React frontend that renders charts via Recharts. Pandas handles intermediate data transformation. The agent is stateless per request; chat history is maintained client-side and injected as context.
Impact
Eliminated an average of 3-5 ad-hoc analyst requests per day in a test scenario with a sample e-commerce database. Complex multi-table aggregation queries that previously took 20-30 minutes to write were answered in under 10 seconds. The LangChain implementation outperformed LlamaIndex on multi-hop queries (82% vs. 67% accuracy); LlamaIndex had lower latency on single-table lookups.
What I Learned
SQL generation quality degrades sharply on ambiguous column names and implicit joins, so I invested heavily in prompt engineering around schema context injection. Also learned that giving the agent a 'validate before execute' tool dramatically reduces hallucinated column names. The biggest insight: few-shot examples in the system prompt matter more than the choice of framework.