Data Analysis Agents: From Spreadsheet to Insight
Data analysis agents turn tables into decisions by pairing sandboxed code execution with narrative insight.
Search across all documentation pages
Data analysis agents turn tables into decisions by pairing sandboxed code execution with narrative insight.
They do not replace statisticians for causal claims.
They do accelerate the path from "here is a CSV" to "here are the patterns, caveats, and charts a human should review."
A spreadsheet question has two hard parts: computing the right number and saying what it means.
Models are weak at longhand arithmetic over large tables and strong at framing hypotheses and explanations.
Code execution flips that: pandas, SQL, or a warehouse query engine computes; the model chooses the next transform and writes the story.
The agent loop looks like knowledge work with a deterministic tool in the middle:
"Insight" here means a reviewable claim about the data, not a business strategy decree.
Good outputs name the filter, time range, metric definition, and result.
Bad outputs say "sales are up" without the query that produced the number.
Analysis agents sit between coding agents and research agents.
Like coding agents, they verify with execution.
Like research agents, they must narrate uncertainty and keep an evidence trail (here: code + result snapshots, not web citations).
Profiling before analysis prevents fantasy joins.
Feed the model schema, 5-20 sample rows, and basic stats - not a 200k-row paste into the prompt.
Large data stays in the sandbox or warehouse; the model sees summaries and query results only.
Tool design matters more than the model logo.
Minimum useful tools:
list_tables / get_schemarun_sql or run_python (sandboxed)savefig or render_chart (optional)export_result to a draft artifact storeReturn small, typed observations: row counts, head previews, error messages, checksum of output frames.
Do not return multi-megabyte frames into the chat transcript every turn.
Metric definitions are a second knowledge problem.
"Revenue" may mean booked, billed, or cash.
Either bind the agent to a metrics catalog (RAG over certified definitions) or force it to declare the formula it used in code.
Undefined metrics are the top source of executive distrust.
Narrative generation should consume structured results.
Prefer: code computes a table → model writes bullets referencing that table id.
Avoid: model invents percentages, then code is asked to "confirm" a pre-decided story.
Safety for code-executing analysis:
# Pattern sketch: model proposes code; runtime executes; only summary returns
def analyze_step(propose_code, sandbox, max_rows_preview=20):
code = propose_code()
result = sandbox.exec(code, timeout_s=30)
return {
"ok": result.ok,
"error": result.error,
"preview": result.frame_head(max_rows_preview),
"rowcount": result.rowcount,
"code_hash": result.code_hash,
}SQL-first vs Python-first.
Warehouse-native agents should push compute to SQL for scale and governance.
Python shines for awkward files, quick plots, and one-off munging.
Hybrid agents choose per step; policy can require SQL for production metrics.
Reproducibility.
Persist the exact code, parameters, data version (file hash or table snapshot id), and result digest.
Without lineage, last week's "insight" cannot be defended in a metrics review.
Multi-table and join risk.
Agents will happily fan-out join on poorly named keys.
Require explicit join keys in the plan, row-count sanity checks pre/post join, and a maximum join complexity before human approval.
Charting and decks.
Charts are tools, not proof.
Every chart artifact should pair with the query and filters that produced it.
Auto-building full slide narratives is possible; auto-sending them to leadership without review is usually not.
When not to use an analysis agent.
| Approach | Strength | Weakness | Best fit |
|---|---|---|---|
| Paste table into prompt | Zero infra | Breaks at scale; weak math | Tiny tables, demos |
| Fixed SQL templates | Reliable, cheap | Inflexible questions | Known Q&A set |
| Agent + SQL sandbox | Flexible, governed compute | Needs good schema tools | Warehouse Q&A |
| Agent + Python sandbox | Great for files/plots | Harder governance | CSV/Excel ad-hoc |
| Full auto BI agent | Broad exploration | High wrong-insight risk | Shadow mode only at first |
The model chooses successive transforms based on prior query results, rather than running one fixed SQL string every time.
If numbers matter, yes - or call a governed metrics API. Freeform numeric generation is a last resort for tiny examples only.
Require row counts before and after filters/joins in the observation schema, and fail the step if counts move unexpectedly without explanation.
Only with explicit permission and versioning. Default to export of a new sheet or artifact, not overwrite of source data.
Cite code cell / query id, table version, filters, and result snapshot - the data analog of a URL citation.
Often a mid tier for planning plus a capable model for final narrative. Tiny models struggle with multi-step SQL reasoning; verify at build.
The primary artifact is a correct, explained statistic or chart, not a merged PR. Tests are row-count checks and metric definitions, not unit tests.
As retrieval tools that return certified formulas before the agent invents one. Prefer catalog hits over free invention.
Known answers on fixture CSVs: totals, group-bys, join pitfalls, null handling, and "refuse when definition missing" cases.
Yes with care: pin a time window per run so results are reproducible, and avoid claiming live accuracy without a watermark.
Separate observed numbers from interpretation. Use language like "in this extract" and list data quality issues from profiling.
When the same question is asked weekly with a stable definition. Promote the agent's successful SQL to a scheduled job and demote the agent to ad-hoc only.
No. Any sandboxed compute that returns structured results works: SQL engines, Spark jobs, or warehouse notebooks - with the same observation discipline.
Read-only SQL on one certified mart, five template questions, structured answers, and human review in Slack before any dashboard publish.
Stack versions: Pins from the category manifest (verify at build): OpenRouter (~315+ models, July 2026 pricing/fees); LangGraph 1.0+; CrewAI 1.14+; Microsoft Agent Framework 1.0; Vercel AI SDK 6; Pydantic AI (latest); LlamaIndex (latest); OpenAI Agents SDK (latest + MCP); MCP (Linux Foundation governance); A2A (HTTP+SSE+JSON-RPC 2.0); Solana
@solana/web3.js+@solana/spl-token.
Reviewed by Chris St. John·Last updated Jul 16, 2026