Skip to content
47% off: the complete course for $79 (reg. $149)Order now →
Agent Builder
Module 13Full course19 min read

Capstone 5: A Data Analyst Agent

Build an agent that answers business questions from a SQL database: schema discovery, safe read-only queries, charts, and checks on its own answers.

"Can you pull last quarter's revenue by category?" is one of the most common questions in any company, and one of the easiest to get subtly wrong. Count line items instead of orders, forget to exclude refunds, or compare a half-finished month with a full one, and you get a confident number that's simply false. An agent with database access makes those mistakes faster unless you design against them.

In this capstone you'll build a data analyst agent that answers business questions from a SQL database. It discovers the schema itself, runs queries through a read-only layer that's enforced in code, draws charts from real query results, and can't submit an answer until code has re-run the SQL behind every number. Then you'll write an eval set that scores it against answers you computed yourself.

What you'll build

A command-line analyst you run like this:

npx tsx main.ts "Which product category brought in the most revenue last quarter?"

It logs each tool call, then prints a short answer, the key numbers with the SQL behind each one, assumptions, caveats, and any charts it saved. Everything runs against a local SQLite file of invented store data, so you need nothing beyond an Anthropic API key.

It draws on the analysis habits from Data Analysis with Agents, database access patterns from Connecting Agents to Databases and APIs, the hand-written loop from A Minimal Agent Loop in 60 Lines, strict tool schemas from Structured Outputs, and least privilege from Sandboxing and Least Privilege.