<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
	<channel>
		<title>Abhishek Maurya</title>
		<link>https://traceabhishek.com</link>
		<description>Notes on backend systems, AI, and everything in between.</description>
		<language>en</language>
		<item>
			<title>Analytics-GPT — Ask Your Database Questions in Plain English</title>
			<link>https://traceabhishek.com/blog/analytics-gpt/</link>
			<guid>https://traceabhishek.com/blog/analytics-gpt/</guid>
			<description>How I built a tool that turns natural language questions into SQL queries, using LangChain and a swappable LLM backend.</description>
			<content:encoded><![CDATA[
<p>Every team I’ve worked with has the same problem: the data lives in a SQL database, but the people who need answers from it don’t write SQL. They end up pinging an engineer, waiting for a Slack reply, or just not asking the question at all.</p>
<p>Analytics-GPT is a small project I built to close that gap — a chat-style interface where you type a question in plain English and get back both the SQL query and the answer.</p>
<h2>How it works</h2>
<p>The flow is intentionally simple: a React front end takes the question, a Flask API passes it to a LangChain agent, and the agent does the two jobs that matter — writing the SQL and turning the result back into a sentence.</p>
<p><img
  src="https://traceabhishek.com/assets/blog/analytics-gpt/architecture.svg"
  alt="Architecture diagram showing the flow from user question through React UI, Flask API, and LangChain Agent to the LLM and SQL database"
></p>
<p>The agent is given the database schema up front, so it knows which tables and columns exist without needing a person to describe them. From there, it reasons about the question the same way a human analyst would: figure out what’s being asked, map it to tables, write the query, run it, and summarize.</p>
<h2>A worked example</h2>
<p>Here’s what happens end-to-end for a question like <em>“Which products had the highest revenue last quarter?”</em></p>
<p><img
  src="https://traceabhishek.com/assets/blog/analytics-gpt/query-flow.svg"
  alt="Diagram showing a natural language question turned into a generated SQL query, a result table, and a plain-English answer"
></p>
<p>The important part isn’t the SQL itself — GPT-4 is generally good at that — it’s making sure the agent has just enough schema context to avoid hallucinating a column or table that doesn’t exist, and enough guardrails to avoid destructive queries. Analytics-GPT restricts execution to read-only queries and validates the generated SQL before it ever touches the database.</p>
<h2>Local LLMs as a drop-in replacement</h2>
<p>Not every team is comfortable sending their schema and data to a hosted API. One of the design goals for Analytics-GPT was to make the LLM backend swappable, so a local, self-hosted model could stand in for GPT-4 without changing anything else in the pipeline.</p>
<p><img
  src="https://traceabhishek.com/assets/blog/analytics-gpt/local-vs-hosted.svg"
  alt="Diagram comparing a hosted GPT-4 backend and a local self-hosted LLM, both plugging into the same LangChain agent"
></p>
<p>Because the agent, prompts, and tool definitions all sit behind the same LangChain interface, swapping the model is a configuration change, not a rewrite. That matters for teams with data residency constraints, or anyone who just wants to avoid per-query API costs once usage grows.</p>
<h2>What I’d improve next</h2>
<p>A few things I’d still like to tackle:</p>
<ul>
<li><strong>Caching repeated questions</strong> — a lot of business questions get asked more than once with the same intent, just phrased differently.</li>
<li><strong>Chart generation</strong> — right now the output is a table and a sentence; a lot of questions would be better answered with a chart.</li>
<li><strong>Multi-table joins at scale</strong> — the agent does fine with a handful of tables, but reasoning gets shakier as schema size grows, which is where better retrieval over the schema (rather than dumping it all into the prompt) would help.</li>
</ul>
<p>Analytics-GPT started as a college project, but the core idea — giving non-technical users a safe, honest way to query structured data — is one I keep coming back to in production work too.</p>
]]></content:encoded>
			<pubDate>Wed, 09 Sep 2026 00:00:00 GMT</pubDate>
		</item>
	</channel>
</rss>