AI Agent for Self-Service Business Intelligence with Text-to-SQL

bgl · Finance · 2026 · source Agentic: yes · promotional bias: med · source-backed · extracted with prompt 0.5.2 (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: Financial business intelligence

BGL needed business users to query complex compliance and financial data without depending on data teams or unreliable generic text-to-SQL.

Constraints:

Architecture

BGL built a governed text-to-SQL analytics agent on top of its existing Athena/dbt data platform. dbt and Athena prebuild business-ready analytic tables as a single source of truth. A Claude Agent SDK agent hosted on Amazon Bedrock AgentCore receives natural-language questions, loads project context from CLAUDE.md and product-domain skills from SKILL.md, discovers relevant table metadata, writes SELECT-only SQL, runs it in Athena, downloads CSV results from S3 into the AgentCore file system, and writes Python code for aggregations, filtering, and charts without stuffing large result sets into the model context.

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

flowchart LR
  business-user-interface[Business user interface] --> agentcore-claude-runtime[AgentCore Claude runtime]
  claude-project-context[CLAUDE project context] --> agentcore-claude-runtime
  skill-domain-modules[SKILL domain modules] --> agentcore-claude-runtime
  skill-domain-modules --> analytic-table-metadata[Analytic table metadata]
  agentcore-claude-runtime --> sql-security-validator[SQL security validator]
  sql-security-validator --> athena-query-engine[Athena query engine]
  analytic-table-metadata --> athena-query-engine
  athena-query-engine --> s3-result-store[S3 result store]
  s3-result-store --> python-code-executor[Python code executor]
  python-code-executor --> agentcore-claude-runtime
Drag to pan · scroll or use +/− to zoom · reconstructed from the source's described component topology

Components

Component Role Interacts with
Business user interface Slack or similar user-facing entry point for natural-language analytics questions. AgentCore Claude runtime
AgentCore Claude runtime Stateful hosted Claude Agent SDK session that orchestrates SQL generation, code execution, files, and responses. Business user interface, CLAUDE project context, SKILL domain modules, SQL security validator, Athena query engine, Python code executor
CLAUDE project context Global project instructions, folder layout, environment settings, and SQL execution guidance. AgentCore Claude runtime
SKILL domain modules Product-line domain expertise and table metadata loaded progressively on demand. AgentCore Claude runtime, Analytic table metadata
Analytic table metadata Schema, sample data, and statistics for business-ready Athena/dbt tables. SKILL domain modules, Athena query engine
SQL security validator Allows only SELECT queries and blocks destructive SQL operations. AgentCore Claude runtime, Athena query engine
Athena query engine Runs SQL over prebuilt analytic tables and stores results in S3. SQL security validator, S3 result store
S3 result store Stores query result CSV files for the agent to download. Athena query engine, Python code executor
Python code executor Processes CSV files, aggregates data, and generates charts or refined datasets inside the isolated session. AgentCore Claude runtime, S3 result store

Data flow

A business user asks an analytics question. The AgentCore-hosted Claude agent uses CLAUDE.md for project instructions and SKILL.md product files for domain expertise, discovers relevant analytic tables, generates a SQL SELECT query, passes it through a security validator, executes it in Athena over dbt-built tables, stores results in S3, downloads the CSV into the isolated AgentCore session, then writes Python to process and visualize results before responding.

5 supporting quotes
“The analytic tables are pre-built daily using Athena and dbt, and serve as the single source of truth.”article, stated
“2. Schema discovery and SQL generation: The agent identifies relevant tables using skills and writes SQL queries.”article, stated
“3. SQL security validation: To help prevent unintended data modification, a security layer allows only SELECT queries and blocks DELETE, UPDATE, and DROP operations.”article, stated
“5. Result Download: The agent downloads the resulting CSV file to the file system on AgentCore, completely bypassing the context window to avoid token limits.”article, stated
“6. Analysis and visualization: The agent writes Python code to analyze the CSV file and generate visualizations or refined datasets depending on the business question.”article, stated

Why this architecture

BGL explicitly avoided making the agent reason over raw schemas and business logic. The data platform handles joins, aggregations, and business rules deterministically, leaving the agent to translate questions into reliable SELECTs and code. Code execution was chosen because analytics outputs can be thousands of rows or megabytes, which would overwhelm an LLM context window if passed through ordinary tool calls.

3 supporting quotes
“When engineering teams implement an AI agent for analytics use cases, a common anti-pattern is to have the agent handle everything including understanding database schemas, transforming complex datasets, sorting out business logic for analyses and interpreting results.”article, stated
“The data system handles complex business logic in a more deterministic way: joins, aggregations, and business rules are validated by the data team ahead of time.”article, stated
“Analytics queries often return thousands of rows and sometimes beyond megabytes of data. Standard tool-use, function calling, and Model Context Protocol (MCP) patterns often pass retrieved data directly into the context window”article, stated

Models used: Claude · Claude Agent SDK · Amazon Bedrock foundation model hosting

Scale

Alternatives considered (roads not taken)

Let the agent handle raw schemas, transformations, business logic, and result interpretation

Rejected because: BGL calls this an anti-pattern that leads to inconsistent joins, missed edge cases, and incorrect aggregations.

“The AI agent is likely to produce inconsistent results and fail by joining tables incorrectly, missing edge cases, or producing incorrect aggregations.”article, stated

Pass large query results directly into the model context through tools/MCP

Rejected because: BGL uses SQL plus Python-on-files because large result sets can exceed context limits.

“BGL implemented a different approach: the agent writes SQL to query Athena, then writes Python code to process the CSV file results directly in its file system.”article, stated

Stateless agent hosting without per-session isolation

Rejected because: Financial-services analytics needs isolated state, credentials, and compliance-aligned execution sessions.

“provides fully-managed, stateful execution sessions, each session has its own isolated microVM with a separate CPU, memory, and file system.”article, stated

Patterns

tool-use-orchestration (analytics)

The agent executes SQL/code against curated analytics tables rather than trying to infer all business logic from raw schemas.

“agent-based text-to-SQL solutions * How BGL designed its AI agent using Claude Agent SDK for code execution, context management, and domain-specific expertise”article, stated

safety-policy-enforcement (security)

AgentCore stateful sessions provide security isolation for production data analysis.

“text management, and domain-specific expertise * How BGL used AgentCore to provide the ideal stateful execution sessions in production for a more secure, scalable AI agent.”article, stated

Tradeoffs

Where to put business logic.

Chose curated dbt/Athena data foundation over agent improvisation over raw data.

Rationale: BGL sacrificed some genericity to gain consistent, governed answers for business users.

“Those tables are aggregated, denormalized datasets (with metrics and, summaries) that serve as a business-ready single source of truth for business intelligence (BI) tools, AI agents, and applications. For details on how to build a serverless data transformation architecture with Athena a”article, stated

Data-platform responsibility boundary.

Chose dbt/Athena business-ready tables as the source of truth over agent improvisation over raw business data.

Rationale: Validated transformations and metrics keep business logic deterministic while the agent focuses on query interpretation and result processing.

“Business logic resides in the data system, not in the AI’s context window. This helps ensure that the AI agent relies on the same single source of truth as other consumers, such as BI tools.”article, stated

Large-result processing strategy.

Chose SQL to Athena plus Python over CSV files over putting retrieved rows directly into the LLM context window.

Rationale: File-based code execution handles thousands of rows or megabytes without exhausting tokens.

“This enables the agent to handle large result sets, perform complex aggregations, and generate charts without reaching context window limits.”article, stated

Gotchas (what bit them)

Letting the agent handle raw schema interpretation is an anti-pattern.

Root cause: Agents can join tables incorrectly, miss edge cases, and produce wrong aggregations in regulated BI.

Resolution: Build aggregated, denormalized, business-ready tables as a single source of truth before adding the agent.

“When engineering teams implement an AI agent for analytics use cases, a common anti-pattern is to have the agent handle everything including understanding database schemas, transforming complex datasets, sorting out business logic for analyses and interpreting results.”article, stated

Evaluation

The case reports adoption and productivity outcomes rather than a public benchmark.

Metrics: 200+ employees · business self-service · reduced data-team dependency

“This democratized data access for over 200 employees, enabling product managers, compliance teams, and customer success managers to self-serve analytics without SQL knowledge or data team dependencies.”summary, stated

Outcomes

AWS co-authored customer story; results are customer-reported.

“BGL’s customers and employees need to find insights from the data.”article, implied