A Practical Guide to LLM Agent Data Analysis: From Probabilistic Output to Verifiable Results

    This article explains why large language models should not be asked to produce precise statistical results directly, and how an Agent pattern shifts the model's role from answer provider to programmer. It covers a code-first workflow for quantile calculation and chart generation, methods for validating result consistency across runs, a comparison matrix for evaluating different Agent environments, and a four-layer pipeline design. Readers will learn how to keep probabilistic generation for planning and explanation while delegating calculation and deliverables to deterministic execution.

    1. The Starting Problem: Why a Model Should Not “Just Say” a Quantile

    In data analysis, a common request is to compute the quantile of a metric against the current inventory and the current basis. The definition is unambiguous: sort the historical series and find the relative position of the target value. Yet when this kind of task goes through a large language model’s natural language output channel, the results are often unstable. The reason is not that the model “cannot calculate,” but how it works: it predicts the next most likely token probabilistically based on training data and context. It does not enforce mathematical rules and does not guarantee decimal precision. As a result, the same dataset and the same question can produce slightly different approximate values across repeated runs.

    This yields the first engineering principle: anything that can be solved exactly with code should not be handed to probabilistic generation. Having the model generate and invoke a script to parse tables is the more reliable path. Script output is deterministic and reproducible, and the source of error narrows from “model guessing” to “code logic and data quality” — both of which can be tested and audited.

    2. The Core Paradigm: The Agent as a Programmer, Not a Quiz Taker

    The key change in the Agent pattern is switching the model’s role from “answer provider” to “programmer.” Instead of stating a conclusion directly, it plans the steps, writes code, calls tools, reads results, fixes errors, and finally produces a deliverable. A typical execution chain looks like this:

    1. Parse the request and break it into a task list;
    2. Locate and read the structured data file, validating fields and types;
    3. Write a calculation script that outputs the metric and its quantile;
    4. Call a plotting library to generate the chart;
    5. Merge the written conclusions and the chart into a deliverable document.

    An illustrative prompt constraint could be written as:

    1. Complete the task in the following steps:
    2. 1) Read the data file and print its fields and missing rates;
    3. 2) Use a script to compute the historical quantile of the target metric, rounded to four decimals;
    4. 3) Automatically call a plotting library to generate the chart; every point in the chart must be computed by the script;
    5. 4) Merge the report body and the chart into a single archivable document file.

    Step 3 matters most. Code-based plotting and “draw a picture” from a generative image model are fundamentally different: in the former, every pixel position is mapped from a concrete value, and axes, ticks, and legends are traceable; the latter is probabilistic pixel synthesis that may look polished but cannot support professional judgment. In rigorous settings such as finance, industrial operations, and business operations, traceability takes priority over appearance.

    3. Verifying Result Consistency: Turning “Approximate” into “Checkable”

    Early practice surfaced a phenomenon worth digging into: quantiles of the current inventory from different execution paths clustered in the 20%–30% range with little divergence, while quantiles of the current basis split noticeably, with one end stable around 55% and the other close to 70%. A pattern where “one metric converges and another diverges” usually points to three causes:

    • Inconsistent data definitions: different time windows, adjustment methods, or missing-value handling for the basis shift the sorted result;
    • Different calculation implementations: quantile interpolation methods (nearest rank, linear interpolation, and so on) produce visible differences with small samples;
    • Approximate output: if the conclusion comes from the language channel rather than a script, the last few decimal places are essentially untrustworthy.

    The corresponding engineering fix is to move verification to the front:

    1. import pandas as pd
    2. def quantile_report(series, q):
    3. s = pd.to_numeric(series, errors="coerce").dropna()
    4. return {
    5. "sample_size": int(s.shape[0]),
    6. "missing_count": int(pd.to_numeric(series, errors="coerce").isna().sum()),
    7. "quantile": round(float(s.quantile(q)), 4),
    8. }

    Fixing the randomness, fixing the data version, fixing the interpolation method, and having the script print both sample size and missing count allow any result to be independently recomputed by a third party. This is also the fastest way to judge whether a given output is trustworthy.

    4. Cross-Environment Comparison

    Differences between Agent runtime environments show up mainly in tool reachability and output form: some are strong at local file I/O and script execution, some rely on cloud sessions and built-in skills, and some are more mature at document layout. Rather than ranking them by subjective experience, build a unified evaluation matrix and measure them horizontally with the same dataset, the same prompt, and the same acceptance criteria:

    Dimension Acceptance criterion
    Numerical correctness Exactly matches an independent script result, with fixed decimal places
    Process auditability Emits intermediate steps and execution logs
    Chart trustworthiness Generated from computed data, with verifiable coordinates
    Deliverable completeness Text and chart merged into a single archivable document
    Stability Variance across repeated runs stays controlled

    Evaluation also has to account for resource constraints: session quotas, concurrency limits, and maximum single-run duration all affect how many steps can be completed, and should be recorded in the report as environment variables rather than omitted.

    5. A Production-Ready Pipeline Design

    Combining the points above into a usable production pipeline suggests four layers:

    • Data layer: unified ingestion with recorded versions and definition notes, archived in object storage when needed;
    • Computation layer: scripted metric and quantile calculation, with unit tests covering boundary samples;
    • Orchestration layer: the Agent generates the task list and executes it step by step, with retries and resume-from-checkpoint on failure;
    • Delivery layer: automatic plotting and document merging, with logging and monitoring alerts tracking each run.

    On Baidu AI Cloud, these four layers can be supported by composing general capabilities: object storage for data and artifacts, a container platform to host the script execution environment so dependencies stay consistent, and logging plus monitoring alerts for run traceability and anomaly notification. This keeps the automation advantage of the Agent while returning determinism to code.

    6. Conclusion

    The real value of the Agent pattern is not making the model “sound more like an analyst,” but making it work like an engineer: decompose the task, write code, call tools, and produce checkable deliverables. Precise calculations such as quantiles must go to scripts; charts must be data-driven; conclusions must be independently recomputable. Holding the line that “probabilistic generation handles planning and expression, deterministic execution handles calculation and output” is what moves intelligent data analysis from demo to reliable production.