LLM Agents for Data Analysis: A Reproducible Workflow for Automated Research Reports

    This article explains how to combine LLM agents with deterministic scripts to produce daily data research reports that can be re-run and audited. It covers fixing data snapshots before task decomposition, defining validation rules for inputs, disambiguating percentile rank versus percentile value with pseudocode, generating charts from a single computed metrics result, verifying external sources separately from statistical conclusions, and running acceptance tests based on reproducibility rather than visual polish.

    1. The hard part of report automation isn’t generation speed — it’s whether results can be verified

    A routine data research report usually answers three questions: what the metric is today, where it sits relative to history, and which factors might explain the change. The first depends on data access, the second on statistical rules, and the third on business context and external material. These three tasks have different accuracy requirements, so it is unwise to hand all of them to a model and let it infer everything from context.

    LLM agents are well suited to orchestrating the workflow: splitting a task into steps, calling data processing and charting components, checking intermediate artifacts, and assembling confirmed numbers and sources into a report. Statistical computation should be done by scripts that can be inspected. A script won’t autocomplete a plausible-looking number the way a language model can, but that doesn’t make scripts inherently correct: reading the wrong worksheet, treating nulls as zero, or picking the wrong quantile algorithm can all produce consistently wrong results. Trustworthy automation rests on three things: traceable inputs, explicit computation rules, and outputs that can be cross-checked.

    2. Fix the inputs first, then let the agent break down the task

    Take an inventory and basis daily report as an example. The workflow can be split into seven steps: confirm the data version, read and validate the tables, compute metrics, generate charts, collect external material, assemble the report, and review before publishing. Each step should have a defined input and artifact. The computation step, for instance, outputs structured metrics plus validation information; the charting step reads that confirmed data; the report step does not recompute anything from the raw tables.

    Data input should come from a fixed snapshot rather than the latest file in a location that keeps changing. The task record should include at least the data cutoff time, the worksheet, the time field, the metric fields, and the units of measure. On read, check for duplicate dates, whether the data is sorted, whether numeric columns contain text, and whether units change across dates. When duplicate records appear, handle them according to a rule agreed in advance; without such a rule, pause the task instead of letting the agent keep the first or last row on its own.

    The distinction between trading days and calendar days is also worth fixing. “The last year” of history can mean one calendar year before the cutoff, or the most recent set of valid trading days, and the two won’t necessarily match in sample size or start and end dates. A daily report should show the statistical window and keep the actual number of samples used, so readers know what the result was computed from.

    3. Disambiguating the word “percentile”

    Daily reports often say “the current inventory percentile is X%,” but what is usually meant is the historical percentile rank of the current inventory: the relative position of the current value within a set of historical observations. That is not the same as “what is the Nth percentile of historical inventory.” The first takes the current value as input and outputs a percentage; the second takes a target percentile as input and outputs a value in the same units as inventory. If a prompt only says “compute the inventory percentile,” different runs may adopt different definitions, and the results won’t be comparable.

    If the business chooses “the share of historical samples strictly below the current value” as the ranking definition, it can be expressed as pseudocode:

    1. history = valid observations earlier than the report date within the statistical window
    2. require: current value is valid, and the number of history samples meets the business minimum
    3. sample_count = number of history samples
    4. below_count = number of history samples strictly less than the current value
    5. tied_count = number of history samples equal to the current value
    6. percentile_rank = below_count / sample_count * 100
    7. persist: current value, window start and end dates, sample_count, below_count, tied_count, and the result

    This is one definition, not the only rule. When historical records contain many identical values, excluding tied samples, counting all of them, or counting them as half can produce noticeably different results. For example, with ten historical samples where three are below the current value and two equal it, the strictly-below definition gives 30%, while a less-than-or-equal definition gives 50%. Both rules can be executed exactly by a script; the difference comes from the definition, not from decimal precision. This example also belongs in the test suite, so later code changes don’t silently alter the statistical definition.

    Basis metrics require fixing the sign convention first. If the business defines basis as spot price minus futures price, then data extraction, computation, charting, and interpretation must all use the same convention; when different contracts or quote times are involved, the selection and alignment rules should be stated. The final display can round to an agreed number of decimals, but compute first and round once at the end, rather than letting the prose, the charts, and the appendix tables each handle the same number differently.

    4. Make charts and prose cite the same computed results

    For time series, distributions, and percentile markers in a report, prefer programmatic charting driven by data. Dates, axes, reference lines, and annotations should all come from explicit data fields or computed results, not from an image generation model drawing from a description. The latter can produce decorative illustrations that carry no numeric meaning, but it can’t be used for trends, ticks, or value markers that need exact verification.

    Charts should be chosen around the reader’s question. A time series chart suits explaining recent movement; a distribution chart suits showing where the current value sits among historical samples. If missing intervals affect how the trend is read, the line should break visibly or be annotated, rather than connecting across missing dates by default. The charting script should also check units, axis ranges, and annotation placement, so a correctly drawn curve isn’t misread because of a truncated scale or a misplaced marker.

    In practice, save the current value, historical rank, sample count, and statistical window as one metrics result. Charts use it to mark the current value and rank, the prose template uses it to fill in key numbers, and the appendix table uses it to show the calculation basis. Compared with distributing the data to multiple steps that each compute independently, this makes image-text inconsistency easier to avoid. After export, check fonts, pagination, legend overlap, and clipped labels; a file that was generated successfully is not necessarily a readable page.

    5. Verify external material separately from statistical conclusions

    An automated daily report can add announcements, industry news, or authorized internal material, but these sources and the statistical metrics are different kinds of evidence. Inventory sitting at a certain historical position is a result computed under an agreed rule; whether the change in inventory was caused by supply, demand, or transportation requires other evidence. A report can present an event alongside a metric change, but it cannot turn a hypothesis into a confirmed causal claim just because the timing is close.

    The retrieval step should record the source, the publication time, and the event time, so a retrospective piece published today isn’t mislabeled as an event that happened today. When external material is missing, keep the quantitative part that already passed validation and note that the background has not been verified; when key data is missing, the definition is unclear, or computation validation fails, the formal report should not be published. Handling these two kinds of exceptions separately keeps the agent from fabricating explanations or numbers in order to deliver a document that merely looks complete.

    6. Acceptance testing: can it be re-run, not just does it look good

    Start with a small set of manually verifiable baseline cases built from data you can check by hand, covering tied values, missing values, insufficient samples, out-of-order dates, and a current value outside the historical range. After every change to a computation script, a prompt, or the report template, re-run those cases and check the metrics results and the final layout separately. For business users, readable charts matter; for maintainers, being able to tell whether a difference came from a data update, a rule change, or an execution error matters just as much.

    In production, retain the data version, rule version, execution logs, validation results, and the final report. For a transient execution failure, retry according to the predefined rules; for field changes, unit conflicts, or insufficient samples, escalate to a human instead of re-running repeatedly. Assign permissions per task as well: read raw data only, write generated files to a designated location, and authorize formal publishing separately from draft generation.

    A simple acceptance check for whether a research report agent is reliable: re-run with the same data snapshot and statistical rules, and confirm the key metrics and chart data match; then pick any number in the prose and verify it can be traced back to the computation result and the original samples. The wording can change; the statistical facts should not change with the model’s phrasing. Letting the agent organize the workflow, letting scripts do the computation, and letting validation rules decide whether to publish is what turns a one-off demo into a maintainable daily report.