Building a Production-Ready Business Analytics Assistant with ChatGPT

microsoft · Tech · 2023 · source Agentic: yes · promotional bias: low · source-backed · extracted with prompt 0.5.4 (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: Business analytics assistant over structured SQL data

Microsoft's reference implementation explored how to make ChatGPT answer complex analytical questions over structured business data despite LLM weaknesses in quantitative reasoning, schema selection, output consistency, hallucination, and token limits.

Constraints:

Architecture

The design uses ChatGPT as the planning brain and external tools for the actual data work. A Data Scientist agent interacts with the user, plans the analysis with ReAct, asks a Data Engineer agent to retrieve source data from SQL systems, executes Python analytics and visualization code, and presents results through a Streamlit application. The platform wraps SQL, Python, Plotly, display, persistence, and session-state utilities so the agents can use simple tool actions rather than direct complex APIs.

Diagram confidence: explicit (topology described by the source).

flowchart LR
  user[User] --> streamlit-application[Streamlit Application]
  streamlit-application --> data-scientist-agent[Data Scientist Agent]
  streamlit-application --> session-state[Session State]
  data-scientist-agent --> data-engineer-agent[Data Engineer Agent]
  data-engineer-agent --> schema-retrieval-tool[Schema Retrieval Tool]
  schema-retrieval-tool --> sql-database[SQL Database]
  data-engineer-agent --> sql-query-tool[SQL Query Tool]
  sql-query-tool --> sql-database
  sql-query-tool --> python-console[Python Console]
  data-scientist-agent --> python-console
  python-console --> analytics-libraries[Analytics Libraries]
  analytics-libraries --> plotly-visualization[Plotly Visualization]
  plotly-visualization --> display-utility[Display Utility]
  display-utility --> streamlit-application
Drag to pan · scroll or use +/− to zoom · reconstructed from the source's described component topology

Components

Component Role Interacts with
User Business user asking complex analytical questions in natural language. Streamlit Application
Streamlit Application Application platform for UI, visualization, user interaction, and session state. User, Data Scientist Agent, Session State, Display Utility
Data Scientist Agent Primary ChatGPT agent that plans, analyzes, requests data, runs tools, and produces final answers. Streamlit Application, Data Engineer Agent, Python Console, Analytics Libraries, Plotly Visualization, Display Utility
Data Engineer Agent ChatGPT agent responsible for source-system data acquisition and SQL query formulation. Data Scientist Agent, SQL Query Tool, Schema Retrieval Tool
Schema Retrieval Tool Utility for identifying tables and retrieving table schemas needed for a question. Data Engineer Agent, SQL Database
SQL Query Tool Tool that executes SQL queries and returns dataframes to the agents. Data Engineer Agent, SQL Database, Python Console
SQL Database Structured data source, implemented with SQLite or SQL Server in the reference implementation. Schema Retrieval Tool, SQL Query Tool
Python Console Execution environment for retrieval, data analytics, ML code, and tool wrapping. Data Scientist Agent, SQL Query Tool, Analytics Libraries
Analytics Libraries Python data science and ML libraries used to compute business answers. Data Scientist Agent, Python Console, Plotly Visualization
Plotly Visualization Visualization layer for charts and rich analytical output. Analytics Libraries, Display Utility
Display Utility Tool that communicates results and visualizations to the end user. Streamlit Application, Plotly Visualization, Data Scientist Agent
Session State Stateful memory for an interactive analytics session. Streamlit Application

Data flow

A user asks a business question in the application. The Data Scientist agent plans the analysis, requests data from the Data Engineer agent, the Data Engineer identifies needed tables, retrieves schemas, writes SQL, and returns data. The Data Scientist then runs Python analytics or ML code, generates Plotly visualizations, and displays final results in Streamlit while ReAct observations let both agents adjust intermediate steps.

4 supporting quotes
“1. Data engineer: This agent is responsible for performing data acquisition from the source system (in this case a SQL database). The data engineer agent receives instructions from the data scientist agent.”article, stated
“The data scientist agent can request that the data engineer agent acquire the necessary data, and then the data scientist agent uses tools to perform data analytics to produce a final answer.”article, stated
“Agents are implemented following the ReAct framework, as mentioned earlier. With its built-in knowledge of business and data analytics and with an initial prompt, the agent plans how to solve an input question.”article, stated
“The run method coordinates the execution of tools and interacts with the LLM (ChatGPT in this example) in a loop.”article, stated

Why this architecture

The architecture separates high-level reasoning from numeric execution. ChatGPT plans, decomposes, and writes tool calls, while SQL, Python, analytics libraries, and Plotly do the reliable data access, computation, and visualization. Two agents split database acquisition from analytical reasoning, reducing task complexity and giving each agent a narrower prompt and tool surface.

4 supporting quotes
“instead of doing number crunching by hand, a trained professional can benefit from tools that help with the heavy lifting and produce accurate insights.”article, stated
“3. Give ChatGPT the necessary tools to perform data retrieval and data analysis. Here we can take advantage of the capabilities of ChatGPT to write SQL queries and Python data analysis code in designing the tool.”article, stated
“The use of two separate agents follows the design thinking of dividing a potentially complex task into multiple sub-tasks”article, stated
“To prevent agents from having to deal with the unnecessary complexity of interacting with external systems and applications, some utility functions and tools are provided such as display, persist, load, and so on. In this way, the agent needs to know only how to use the tools in the prompt.”article, stated

Models used: ChatGPT

Scale

Alternatives considered (roads not taken)

Have ChatGPT perform calculations directly

Rejected because: LLMs are less reliable for quantitative reasoning, so the design makes tools perform calculations and data retrieval.

“To date this has meant that they are less reliable for quantitative reasoning tasks, including documented instances in which ChatGPT and other LLMs have made errors in dealing with numbers.”article, stated
“3. Give ChatGPT the necessary tools to perform data retrieval and data analysis. Here we can take advantage of the capabilities of ChatGPT to write SQL queries and Python data analysis code in designing the tool.”article, stated

Use one general-purpose agent for all work

Rejected because: Splitting data acquisition from analysis made the problem more tractable for ChatGPT.

“The ChatGPT agents perform tasks on their own by using the tools, observing the results, and adjusting their actions based on their observations. There are two agents in this design:”article, stated
“The use of two separate agents follows the design thinking of dividing a potentially complex task into multiple sub-tasks that are easier for ChatGPT to work on.”article, stated

Load the full database schema into every prompt

Rejected because: Large schemas can exceed token limits, so context is built dynamically around the needed tables.

“If you use the entire schema, your message size may well exceed ChatGPT’s token limit.”article, stated
“a dynamic context building technique should be used so that only the necessary context for a question is loaded”article, stated

Expose complex APIs directly to the model

Rejected because: Complex tools confuse ChatGPT and consume few-shot budget, so the implementation wraps them behind simpler APIs.

“Complex APIs and interaction flow may confuse ChatGPT and consume multiple few-shot examples”article, stated
“Try to reduce the complexity by wrapping multiple complex APIs into a simple API before exposing to ChatGPT. * Reliability: Randomness and hallucination may impact the ability of ChatGPT — or any LLM — to deliver accuracy and reliability.”article, stated

Patterns

multi-agent-orchestration (agent-architecture)

A Data Scientist agent delegates source-data acquisition to a Data Engineer agent, then performs analysis and presentation.

“The data engineer agent receives instructions from the data scientist agent.”article, stated
“The data scientist agent can request that the data engineer agent acquire the necessary data”article, stated

tool-use-orchestration (analytics)

ChatGPT uses SQL, Python, data-science libraries, Plotly, and display utilities as tools rather than doing the work internally.

“tools for agents enable them to perform complex tasks via high level actions without having to worry about the technical details behind them.”article, stated
“Tools for the data scientist agent include Python Console, Data Analytics & ML Libraries, Plotly for visualization”article, stated

prompt-chaining (reasoning)

Both agents use ReAct thought/action/observation loops to plan, execute, observe, and adjust.

“augment this approach with a more advanced CoT technique called ReAct”article, stated
“Observations gained during these intermediate steps may change the original plan.”article, stated

structured-output-contract (reliability)

The implementation wraps tools and uses validation/retry flows to handle format inconsistency and unreliable outputs.

“Output format consistency: As a generative LLM, ChatGPT has a certain level of randomness in its output format”article, stated
“This should be expected and handled using a validation and retry flow.”article, stated

human-in-the-loop-gate (analytics-validation)

The application should expose intermediate SQL/code outputs so users can validate model-generated analytical steps.

“A good practice is to make intermediate output available for the user to validate”article, stated
“such as displaying the generated SQL query and code.”article, stated

Tradeoffs

Use ChatGPT as an orchestrator, not a calculator

Chose LLM planning plus SQL/Python execution over direct LLM quantitative reasoning.

Rationale: This preserves ChatGPT's high-level reasoning strengths while moving computations into deterministic tools.

“Fortunately, ChatGPT excels at providing the high-level knowledge component.”article, stated
“Give ChatGPT the necessary tools to perform data retrieval and data analysis.”article, stated

Split into Data Engineer and Data Scientist agents

Chose two specialized ChatGPT agents over one agent handling data access and analysis end to end.

Rationale: The split isolates database complexity from analytical reasoning and makes each subtask easier for ChatGPT.

“There are two agents in this design:”article, stated
“The use of two separate agents follows the design thinking of dividing a potentially complex task into multiple sub-tasks”article, stated

Use Streamlit as the application platform

Chose Streamlit over Dash, Bokeh, or a more custom UI stack.

Rationale: Streamlit provided stateful memory and simpler development for an interactive analytics assistant.

“There are many great Python-based platforms that can support web-based data visualization and interaction such as Dash and Bokeh”article, stated
“I prefer Streamlit because of its capability to support stateful memory and its simplicity in development.”article, stated

Dynamically build database context

Chose table identification, schema retrieval, and query construction over static full-schema prompting.

Rationale: Dynamic context avoids token limits and narrows the prompt to the question-specific schema.

“If you use the entire schema, your message size may well exceed ChatGPT’s token limit.”article, stated
“a dynamic context building technique should be used so that only the necessary context for a question is loaded”article, stated

Gotchas (what bit them)

LLMs are unreliable at quantitative reasoning when left unaided.

Root cause: ChatGPT is trained primarily around language and communication rather than numeric computation.

Resolution: The system delegates data retrieval and calculation to SQL, Python, and analytics tools.

“LLMs, including ChatGPT, are trained with a focus on the language and communication aspects of information, and not quantitative reasoning.”article, stated
“instead of doing number crunching by hand, a trained professional can benefit from tools that help with the heavy lifting”article, stated

Database schemas can overflow the prompt.

Root cause: Analytics sources may contain many tables and objects, and loading the full schema can exceed token limits.

Resolution: Build context dynamically by selecting tables, retrieving only needed schemas, and then constructing SQL.

“A data source for an analytics application may have numerous data objects and tables with complex schema”article, stated
“only the necessary context for a question is loaded as part of the message.”article, stated

Output format inconsistency needs production handling.

Root cause: Generative models retain randomness even with clear instructions.

Resolution: Use validation and retry flows around outputs.

“ChatGPT has a certain level of randomness in its output format, even with clear instruction.”article, stated
“This should be expected and handled using a validation and retry flow.”article, stated

Complex tools confuse agents and consume prompt budget.

Root cause: Complex APIs and interaction flows require many examples for the model to learn.

Resolution: Wrap APIs behind simple utility functions before exposing them to ChatGPT.

“Complex APIs and interaction flow may confuse ChatGPT and consume multiple few-shot examples”article, stated
“wrapping multiple complex APIs into a simple API before exposing to ChatGPT.”article, stated

Hallucination remains a reliability risk for analytics.

Root cause: LLM randomness can affect accuracy even when tools are available.

Resolution: The design calls for multiple validation mechanisms and visible intermediate SQL/code.

“Randomness and hallucination may impact the ability of ChatGPT — or any LLM — to deliver accuracy and reliability.”article, stated
“the application must be designed to have multiple validation mechanisms at intermediate processing steps.”article, stated

Evaluation

The article frames evaluation as production-hardening work rather than benchmarked deployment results: validate and retry inconsistent outputs, show intermediate SQL/code for user inspection, reduce tool complexity, and use multiple validation mechanisms at intermediate processing steps.

Metrics: output format validity · SQL query correctness · Python code correctness · intermediate-step validation · token budget · visualization correctness · user inspection of generated SQL and code

3 supporting quotes
“This should be expected and handled using a validation and retry flow.”article, stated
“A good practice is to make intermediate output available for the user to validate”article, stated
“the application must be designed to have multiple validation mechanisms at intermediate processing steps.”article, stated

Outcomes

This was a reference implementation rather than a reported production deployment. Its concrete scale claims are architectural: support for SQLite and SQL Server, a three-step dynamic schema-context strategy, and optional production deployment as REST backends plus Streamlit frontend.

3 supporting quotes
“I present a methodology, coupled with a practical reference implementation, to turn ChatGPT into a powerful business analytics assistant.”article, stated
“In a production deployment, you may choose to deploy the agents as restful back-end APIs”article, stated
“SQL or structured data is the primary source for data analysis.”article, stated