LLM Agent Data Analysis in Practice: Workflow, Numeric Accuracy, and Tool Use
Hands-on comparison of agent-style LLM data analysis versus direct model answers: planning and Python execution, quantile precision, chart generation, and practical prompt and validation guidance.
LLM Agent Data Analysis in Practice: Workflow, Numeric Accuracy, and Tool Use
Why data analysis needs an agent workflow
On structured data tasks, asking a language model to “mental math” numeric results is a fundamental mismatch. LLMs predict from training data and context; they do not strictly follow arithmetic rules, and decimal handling is often approximate. With tables of hundreds of rows and dozens of columns, that approximation quickly becomes a material error.
A more reliable engineering path is to treat the model as a programmer: generate and run Python to parse tables and compute. Python is a deterministic runtime with no probabilistic memory drift; each step can be checked and reproduced. That is the core value of agent mode in data analysis—the model becomes a tool orchestrator, exact computation stays in code, and the model owns task breakdown and logic.
Typical agent capabilities include building a task list, running Python to load data, retrieving related information from the web or a local knowledge base, drawing charts with visualization libraries, and merging text and figures into a PDF or similar document. The loop is the familiar plan–execute–verify cycle used by mainstream coding assistants.
Typical agent structure and execution logic
In practice, a mature data-analysis agent usually follows these stages.
Stage 1: Task planning. After the user prompt, the model splits the request into an ordered checklist. For example, “analyze a factor series and produce a daily report” becomes: read the file → compute statistics such as quantiles → retrieve related news → write analysis → plot → merge and export PDF. A task list makes multi-step work traceable and failures easier to locate.
Stage 2: Code generation and execution. For each subtask the agent writes and runs Python: data libraries for tables, numeric libraries for stats, Python visualization libraries for plots. Charts are drawn from computed coordinates, not from a generative image model sampling pixels. The former is more accurate and professional; the latter can misalign axis values and legends.
Stage 3: Assembly and output. Results, retrieved notes, and figures are assembled into a structured document. If the prompt explicitly asks to “call a visualization library for figures and merge the daily write-up and charts into a PDF research note,” the agent can finish layout and export at the end of the pipeline.
Illustrative analysis script the agent might generate:
# Illustrative analysis script generated by an agentimport pandas as pdimport numpy as npimport matplotlib.pyplot as pltdf = pd.read_excel("factor_data.xlsx")quantiles = df["factor_value"].quantile([0.05, 0.25, 0.5, 0.75, 0.95])current = df["factor_value"].iloc[-1]percentile = (df["factor_value"] < current).mean() * 100plt.plot(df["date"], df["factor_value"])plt.axhline(current, linestyle="--")plt.title(f"Current percentile: {percentile:.1f}%")plt.savefig("report_chart.png")
Quantiles and percentiles come from pandas and numpy; the chart is rendered from data coordinates in matplotlib. Numeric trust is much higher than asking the model to estimate the answer.
Numeric accuracy: agent vs. non-agent
The most important empirical split is precision. On quantile tasks, models that actually run code in agent mode can emit precise decimals. Modes that answer from the language model alone tend to round or give coarse estimates.
The reason is simple: a direct numeric answer is a guess from training patterns and context, not a row-by-row sort and interpolation. Even with the table in the context window, comparisons and accumulations remain unstable. In agent mode the model only needs correct script logic; the interpreter produces values under floating-point rules.
Hence a common prompt practice: explicitly require “compute with code; do not estimate.” That is not a denial of model skill; it is matching a probabilistic system to deterministic work at the architecture level.
Cross-model observations of agent behavior
Among models with agent mode, differences showed up along three dimensions.
Completeness of tool use. Some models finish the full path: read table → compute → plot → export, and they honor extra output-format instructions. Others fall back to generative images at the plotting step, so axis numbers drift from the real series. Those charts may look nicer but fail as research-note figures because readers cannot trust the numbers.
Stability of the task list. Checklist quality drives multi-step completion. Over-coarse splits skip steps; over-fine splits wander. A better pattern is a moderate number of items, each with a verifiable artifact, in an order that respects data dependencies.
Error recovery. When a script fails, whether the agent reads the traceback, patches the code, and retries is a maturity signal. Some implementations stall after the first error; better ones self-repair a limited number of times.
Cloud agent environments also differ in free quota and how you invoke them. Some do not require a personal API key at the start, which lowers the barrier for early tests, but when quota is gone you cannot keep iterating. Engineering practice should keep a reproducible local runtime.
Quantile results and how to read them
Recorded inventory and basis quantile results (models labeled by letter):
| Mode | Model | Current inventory quantile | Current basis quantile |
|---|---|---|---|
| Agent | Model A | 26.3% | 55.0% |
| Agent | Model B | 21.2% | 55.2% |
| Agent | Model C | 27.4% | 68.0% |
| Agent | Model D | Near 30% | Near 30% |
The first three rows include explicit decimals, consistent with real code execution. The fourth uses vague “near 30%” language, which suggests approximation rather than exact calculation. Inventory and basis quantiles measure different distributions; nearly identical values for both can mean the model did not separate the two series.
In production, keep the computation script for every reported metric and add assertions at key points—for example print intermediate stats and cross-check against an independent calculation. Trust should rest on reproducible code, not on how confident the model sounds.
Practical recommendations
- Constrain computation in the prompt. Require Python for numbers and visualization libraries for charts, not image generators.
- Keep intermediate artifacts. Scripts, intermediate files, and chart sources support audit and replay.
- Add check steps for key metrics. Put independent cross-validation on the task list.
- Prefer correct charts over pretty pixels. Research figures must convey data relationships; cosmetics are secondary.
- Judge task lists and recovery, not brand names. Decomposition and error handling often decide output quality more than a single headline score.
The main shift from agent mode is turning the LLM from a catch-all answerer into an orchestrator that knows which tools to call. Exact math in code, organization in the model, verification in the engineering process—that split is a trustworthy data-analysis setup under current technology.
