Building Production-Ready SQL and Charting Agents with RAG Integration

numbers_station · Tech · year n/a · source Agentic: yes · promotional bias: med · source-backed · extracted with prompt 0.5.5 (schema v2)

Generated from extraction.json — do not edit by hand. Every claim cites verbatim source evidence; stated means the quote directly asserts the claim, implied means it supports it indirectly.

Problem

Domain: Self-service enterprise analytics agents

Numbers Station needed to turn natural-language analytics demos into production systems that can answer business questions, write SQL, generate charts, find dashboards, and respect enterprise context and permissions.

Constraints:

Architecture

Numbers Station's production architecture combines a unified knowledge layer, RAG tools, and a hierarchical multi-agent framework. Connectors ingest metadata and business knowledge from the modern data stack; the knowledge layer stores tables, columns, metrics, dimensions, dashboard/report context, Slack/message history, and customer-specific semantics; a SQL agent uses tool calling to search that knowledge and execute warehouse queries with retry/correction loops; a charting agent uses Python execution and documentation retrieval; and a planner agent decomposes user requests, routes to specialized agents, and preserves shared conversation history across handoffs.

Diagram confidence: reconstructed (reconstructed from prose).

flowchart LR
  user[User] --> planner-agent[Planner agent]
  planner-agent --> sql-agent[SQL agent]
  planner-agent --> charting-agent[Charting agent]
  planner-agent --> report-search-agent[Report search agent]
  planner-agent --> messaging-agent[Messaging agent]
  modern-data-stack-connectors[Modern data stack connectors] --> knowledge-layer[Knowledge layer]
  modern-data-stack-connectors --> governance-layer[Governance layer]
  knowledge-layer --> rag-tool[RAG tool]
  rag-tool --> sql-agent
  sql-agent --> sql-execution-tool[SQL execution tool]
  sql-execution-tool --> data-warehouse[Data warehouse]
  data-warehouse --> governance-layer
  charting-agent --> python-execution-tool[Python execution tool]
  charting-agent --> documentation-search-tool[Documentation search tool]
  sql-agent --> shared-conversation-history[Shared conversation history]
  charting-agent --> shared-conversation-history
  messaging-agent --> shared-conversation-history
  shared-conversation-history --> planner-agent
Drag to pan · scroll or use +/− to zoom · reconstructed from the source's described component topology

Components

Component Role Interacts with
User Business or analytics user who asks natural-language questions through chat. Planner agent
Planner agent Top-level coordinator that decomposes user requests and routes subtasks to specialized agents. User, SQL agent, Charting agent, Report search agent, Messaging agent, Shared conversation history
SQL agent Agent that generates, executes, debugs, and revises SQL queries using tool calls. Planner agent, RAG tool, SQL execution tool, Knowledge layer, Data warehouse, Shared conversation history
Charting agent Agent that turns query results into charts using Python execution and chart documentation retrieval. Planner agent, Python execution tool, Documentation search tool, Shared conversation history
Report search agent Specialized agent for finding dashboards or existing reports. Planner agent, Knowledge layer
Messaging agent Specialized agent for sharing results through messaging tools such as Slack. Planner agent, Shared conversation history
Modern data stack connectors Connectors to warehouses, dashboarding tools, catalogs, Slack, and other knowledge sources. Knowledge layer, Governance layer
Knowledge layer Unified business-context layer containing schemas, metrics, dimensions, dashboard/report metadata, and unstructured organizational knowledge. Modern data stack connectors, RAG tool, SQL agent, Report search agent
RAG tool Retrieval component that searches text or embedding indexes and injects top-K context into prompts. Knowledge layer, SQL agent
SQL execution tool Tool that runs generated SQL in the original warehouse and returns results or errors for self-correction. SQL agent, Data warehouse
Data warehouse Enterprise source system where generated SQL executes under existing access controls. SQL execution tool, Governance layer, Modern data stack connectors
Python execution tool Tool used by the charting agent to run chart-generation code. Charting agent
Documentation search tool Retrieval tool for charting examples and documentation. Charting agent
Shared conversation history Cross-agent memory that lets one agent hand results to another, such as SQL output to chart generation. Planner agent, SQL agent, Charting agent, Messaging agent
Governance layer Permission model inherited from source systems rather than rebuilt inside the agent platform. Modern data stack connectors, Data warehouse

Data flow

Connectors pull metadata and knowledge from warehouses, dashboards, catalogs, Slack, and other sources into a unified knowledge layer. A user asks the planner; the planner routes to a SQL, charting, report, or messaging agent; the SQL agent retrieves relevant business definitions from the knowledge layer, writes SQL, executes it against the warehouse, reads any error, and retries if needed. Results can then be handed through shared conversation history to a charting or messaging agent.

4 supporting quotes
“it started with connectors to all the tools used in the modern data stack so things like the data warehouse dashboarding tools data cataloges”transcript, stated
“we then automatically uh create a unified knowledge layer that captures all that Knowledge from from the tools that the organization uses”transcript, stated
“the rag tool is essentially going to run embedding or text similarity search over that large index get um top K results”transcript, stated
“if it if it writes and tries to run the first query doesn't compile it can go back and correct that query based on the error message”transcript, stated

Why this architecture

The architecture exists because basic prompting and fixed pipelines do not meet production analytics needs. Tool-using agents can recover from SQL execution errors; RAG gives the model business definitions it cannot infer; a planner lets one chat surface expose multiple specialized capabilities; shared history makes handoffs natural; and source-system permissions avoid duplicating governance.

4 supporting quotes
“with a manual control flow we're kind of stuck after the model fails and so we could add edge cases and like consider all the scenarios that could happen but this quickly gets very complicated and so we want to have a more flexible and a more robust approach”transcript, stated
“the key to fix this accuracy problem is to bring in the context in the model uh through retrieval augmented generation”transcript, stated
“ultimately the user only talks to the planner um but the planner has a lot of capabilities because it can talk to all the sub agents”transcript, stated
“all we do is whenever we use a tool we just make sure to respect that access control we don't try to rebuild our own internal”transcript, stated

Models used: Large language models · Embedding models

Scale

Alternatives considered (roads not taken)

Basic few-shot or zero-shot SQL prompting

Rejected because: It produces SQL text but leaves the user to copy, paste, execute, and handle failures manually.

“the obvious first thing to try is uh prompting an llm with few shot or zero shot learning so I'm going to create a prompt which has an instruction like please help me write this SQL for this request I'm going to provide a natural language question from the”transcript, stated
“I have to take that SQL copy paste it into my SQL executor and run the query to get the result so it's like essentially using Chad GPC but there's no action there's no way to actually run the query and so this is time consuming and and how can we do better”transcript, stated

Manual generation-then-execution control flow

Rejected because: A fixed pipeline gets stuck when a query does not compile unless many edge cases are hand-coded.

“the naive way to implement this would be manually writing code that implements those step the first step is Generation and the second step is execution”transcript, stated
“if a query fails to compile, the system gets stuck unless extensive edge cases are coded. Stage 3: Agentic Systems - The key shift is making the control flow non-deterministic and LLM-directed. Using tool calling, the LLM decides what actions to take next.”summary, stated

Put all organizational context directly into the prompt

Rejected because: The organization has too much context for the model context window, so retrieval is needed.

“we can't just feed all the context in the prompt because there's a lot of context in an organization um and there's just not enough context in the in the models to like put out of that as a as a prompt context so we use retrieval to get all those fragments”transcript, stated
“there's just not enough context in the in the models to like put out of that as a as a prompt context so we use retrieval to get all those fragments of SQL database schema pretty much anything that we think is relevant for the model into the prompt to make”transcript, stated

Rebuild internal access control

Rejected because: Governance already exists in source systems, so the platform should respect those permissions instead of recreating them.

“already been somehow solved or is like people are working on this in the organization like they have governance in place they have access control for all these tools so all we do is whenever we use a tool we just make sure to respect that access control we don't try to rebuild our own”transcript, stated
“tool we just make sure to respect that access control we don't try to rebuild our own internal because it's just like not our scope and also we have that information already in the source system so it's really just about respecting whatever privacy is set in the original tool and that can be”transcript, stated

A single flat hierarchy for very large agent counts

Rejected because: At 50 or hundreds of agents, the planner's routing space becomes too large; the speaker expects multiple hierarchy levels.

“if we had like 50 or hundreds obviously this design like the hierarchical would not work but the way we envision thing is having like multiple levels of hierarchies with smaller groups of Agents so you can reduce kind of the amount of possibilities and paths”transcript, stated
“multiple levels of hierarchies with smaller groups of Agents so you can reduce kind of the amount of possibilities”transcript, stated

Patterns

rag-retrieval (context-engineering)

Numbers Station retrieves business-specific schema, metric, dashboard, and documentation context from a knowledge layer before asking the LLM to generate analytics answers.

“we can interact with that knowledge through rag retrieval augmented generation to give context to the models for every question that a user asks”transcript, stated
“the rag tool is essentially going to run embedding or text similarity search over that large index get um top K results”transcript, stated

tool-use-orchestration (agent-architecture)

The SQL and charting agents register execution and retrieval tools, then let the LLM decide which tool call or final response comes next.

“for the tool we have to register all the tools that the elm has access to”transcript, stated
“we don't have anything that tells the llm to stop or what to do next”transcript, stated

multi-agent-orchestration (agent-architecture)

A planner coordinates SQL, charting, report-search, messaging, and other specialized agents under one chat interface.

“we can coordinate the operations with the planner so ultimately the user only talks to the planner”transcript, stated
“if I'm asking for a chart directly I can first go to the SQL agent write the query then the chart is going to take it over”transcript, stated

agent-memory (state-management)

Shared conversation history lets specialized agents hand off context and results across an analytics workflow.

“the nice thing also is they all share the same history so you can also do things like jump from one h to the other”transcript, stated

guardrails-io-filtering (safety-and-reliability)

The system grounds answers in a knowledge layer and can admit uncertainty instead of fabricating unsupported analytics answers.

“we can't give them answers that are wrong it has to be grounded into something that is real”transcript, stated
“we're capable of saying I actually don't know and you better not believe what I say next”transcript, stated

latency-optimization (production-optimization)

The framework skips unnecessary model calls for some routing decisions to keep user-facing flows smooth.

“if we don't even a model call to make the routing decision we we ski that”transcript, stated
“it does like make the performance faster and the and and the flow a bit more smooth for the user”transcript, stated

Tradeoffs

Use agent-directed control flow for SQL

Chose LLM tool-calling that decides whether to retrieve, execute, retry, or answer over A deterministic generate-then-execute pipeline.

Rationale: Agentic control flow can recover from compilation errors and wrong table names without hand-coding every edge case.

“the control flow of operations that the model takes is actually non-deterministic and it's set by the llm itself”transcript, stated
“if it writes and tries to run the first query doesn't compile it can go back and correct that query based on the error message”transcript, stated

Ground SQL generation with retrieval

Chose RAG over indexed organizational knowledge over Relying on vanilla prompting and model guesses.

Rationale: RAG lets the agent use customer-specific definitions and avoids making up calculations.

“this approach is really much better than um the vanilla approach of just prompting an llm”transcript, stated
“the big big piece that improves this is really this knowledge layer piece”transcript, stated

Coordinate specialized agents through a planner

Chose A hierarchical planner plus specialized SQL, charting, report, and messaging agents over One monolithic agent or forcing the user to choose each tool manually.

Rationale: The planner keeps the user interface simple while still exposing many capabilities and enabling handoffs through shared history.

“ultimately the user only talks to the planner um but the planner has a lot of capabilities because it can talk to all the sub agents”transcript, stated
“they all share the same history so you can also do things like jump from one h to the other”transcript, stated

Respect source-system governance

Chose Permission pass-through from original tools over Rebuilding an internal governance system.

Rationale: Source systems already know the organization's access rules, and recreating them is outside the platform's scope.

“they have governance in place they have access control for all these tools”transcript, stated
“we don't try to rebuild our own internal because it's just like not our scope”transcript, stated

Gotchas (what bit them)

Demo-quality SQL generation fails when business semantics are missing.

Root cause: The model cannot guess customer-specific metric definitions such as the active-customer filter from generic pretraining.

Resolution: Build and retrieve from a knowledge layer that stores the organization's actual metric and schema definitions.

“the calculation that the model used could be completely made up and uh it doesn't match the user's expectation”transcript, stated
“that definition the model will not guess out of the of the box we have to get it from somewhere in the organization”transcript, stated

Manual control flow breaks at the first unhandled SQL error.

Root cause: A fixed generate-then-execute pipeline has no adaptive step when compilation fails or a wrong table name is used.

Resolution: Let the agent read execution errors, revise the query, and retry through tool calling.

“let's say for instance the query doesn't compile and then uh the model used for instance the wrong table name”transcript, stated
“it can go back and correct that query based on the error message run the query again and get a final response”transcript, stated

The essential production work is often data wrangling, not novel model logic.

Root cause: Accurate analytics requires parsing, ingesting, and normalizing metadata stored across many enterprise tools.

Resolution: Treat ingestion and metadata wrangling as first-class platform work, even if it is not flashy AI work.

“a lot of that work is just parsing ingesting data wrangling work from all the metad data stored in the tools”transcript, stated
“it's not like fancy AI work but we've learned that this is the key to actually get the AI to work correctly”transcript, stated

A single planner hierarchy may not scale to very large agent catalogs.

Root cause: As agent count grows, the number of possible routes and paths grows beyond what a single flat planner should consider.

Resolution: Use multiple levels of hierarchies with smaller agent groups and skip model calls where routing can be optimized.

“if we had like 50 or hundreds obviously this design like the hierarchical would not work”transcript, stated
“multiple levels of hierarchies with smaller groups of Agents so you can reduce kind of the amount of possibilities and paths”transcript, stated

Enterprise permissioning is easy to underestimate.

Root cause: Agent performance and data access control are separate concerns, and enterprises care deeply about who can see which data.

Resolution: Pass through and respect source-system permissions rather than building a competing internal authorization model.

“people are are almost more concerned with the permissioning right”transcript, stated
“just like not our scope and also we have that information already in the source system so it's really just about respecting whatever privacy is set in the original tool and that can be done uh in the straightforward way like basically when someone authenticates based on their permission they have”transcript, stated

Evaluation

The talk describes evaluation mostly through customer-realistic benchmarks, production demos, daily usage confidence, and setup/onboarding feedback rather than a formal published metric suite. The speaker specifically contrasts customer benchmarks with easy public benchmarks and says knowledge-layer grounding plus retry mechanisms produced large improvements.

Metrics: Accuracy on real customer SQL benchmarks · Comparison against vanilla prompting · Query retry/correction behavior · User confidence in grounded results · Setup time from customer onboarding · Planner smoothness at current agent counts

4 supporting quotes
“we did see like huge improvements on real benchmarks from customers which are usually more realistic for the SQL that happens in the real world”transcript, stated
“mostly that knowledge layer piece uh it's very easy for me to build a demo and the model is going to generate great SQL”transcript, stated
“we've learned that this is the key to actually get the AI to work correctly”transcript, stated
“at most a dozen of agents and the experience is still very smooth”transcript, stated

Outcomes

The transcript includes a decade-long modern data stack context, a Vouch customer example, onboarding reduced from a couple of weeks to a couple of hours, current use with at most a dozen agents, and an explicit 50/hundreds-of-agents scalability threshold.

4 supporting quotes
“we did see like huge improvements on real benchmarks from customers”transcript, stated
“we help them self- serve and um bring AI experience for the end users through a chat uh interface”transcript, stated
“like a year ago it was a very big process like couple of weeks of setup and US manually sitting with customers we've brought that down to like a couple of hours of training where essentially users I mean admin users start using the platform and provide feedback and we take that feedback and”transcript, stated
“today like we have at most a dozen of agents and the experience is still very smooth”transcript, stated