LLM Agent Numerical Accuracy: A Practical Guide to Reliable Financial Calculations
This article explains why large language model agents produce unreliable decimal results in financial and inventory calculations, and how to fix it through architecture rather than model selection. It covers four recurring bias patterns, root causes across numerical representation, context, and workflow layers, and three practical solutions: delegating computation to a deterministic execution layer, structuring prompts and context for verifiability, and building closed-loop validation with an evaluation suite. It also addresses chart generation, cloud deployment architecture, and the conclusion that reproducible, auditable results depend on system design.
1. Why Agents Get Decimal Places Wrong
When you connect a large language model to a business system, the most common gap is not text quality but numerical reliability. Take inventory quantiles and baseline quantiles as an example: the business side expects a deterministic result that can be recomputed and audited, while the model is fundamentally producing a probabilistic approximation. It guesses the most likely answer based on its training distribution and contextual clues, and it does not naturally obey strict mathematical rules. As a result, the same batch of data produces systematic bias across different agents: some skew low, some skew high, and others shrink toward a middle value.
This is not a defect unique to one model; it is an inherent property of the generative paradigm. The correct engineering response is not to hunt for a model that “never makes mistakes,” but to strip exact computation out of the generation process and hand it to deterministic code execution, leaving the model responsible for intent understanding, workflow orchestration, and result explanation.
2. Four Typical Bias Patterns
Abstracting the observed comparison behavior yields four patterns that recur in production deployments:
- Systematic underestimation: the current inventory quantile comes out around 26% and the baseline quantile around 55%, a gap of nearly 29 percentage points, reflecting a conservative estimate of the true quantile.
- Mild underestimation: the current value is around 21% and the baseline around 55%; the deviation is smaller but points in the same direction.
- Systematic overestimation: the current value is around 27% and the baseline around 68%; the baseline is clearly inflated, which directly distorts risk judgment.
- Shrinkage toward the middle: both the current value and the baseline land near 30%, the spread is compressed, and the output looks “smooth” while the real information at both tails of the distribution is lost.
All four patterns share one trait: the output looks reasonable and is well formatted, yet it cannot pass recomputation. For downstream systems this is more damaging than an obvious error, because it silently enters reports and decision pipelines.
3. Root Causes: Loss of Control at Three Layers
The first layer is numerical representation. The model has no notion of place value for decimal digits. Typical symptoms include arbitrary truncation, inconsistent rounding, mixed units (pieces / cases / pallets), and errors converting between percentages and decimals.
The second layer is context. When a table exceeds the effective attention range, or when column names and metric definitions are missing, the model fills the gaps with its prior distribution, which is where shrinkage toward the middle comes from.
The third layer is workflow. Without tool calls and validation steps, the model can only “compute from memory”: it cannot read the real data source and cannot self-check before emitting output, so the error flows straight into the final result.
4. Solution 1: Move Computation to a Deterministic Execution Layer
The core principle is “the model does not do arithmetic; the model only orchestrates.” The agent reads structured data through controlled command execution or function calls, a deterministic library performs the quantile calculation, and the model only confirms parameters and phrases the result.
import pandas as pddef quantile_report(df: pd.DataFrame, col: str, base_col: str, q: float = 0.5):# Normalize units and missing values first to avoid metric drifts = pd.to_numeric(df[col], errors="coerce").dropna()b = pd.to_numeric(df[base_col], errors="coerce").dropna()if s.empty or b.empty:raise ValueError("Empty sample; refuse to draw a conclusion")cur = float(s.quantile(q))base = float(b.quantile(q))return {"quantile": q,"current": round(cur, 4),"baseline": round(base, 4),"spread": round(cur - base, 4),"sample_size": int(s.size),}
Three engineering points matter here. First, declare the quantile definition and interpolation method explicitly, so different implementations do not return different numbers. Second, retain the sample size and refuse to draw a conclusion when the sample is too small. Third, handle units and missing values up front to reduce metric ambiguity.
5. Solution 2: Structured Context and Prompt Design
At the prompt level, write “verifiability” into the constraints: require the model to output the data-retrieval steps and parameters before any number, require every figure to be labeled with its source field and sample size, and prohibit filling in estimates when data is missing. A reusable constraint block:
Rules:1. Never state any number from memory; retrieve the data first.2. Output must include field names, sample size, and the quantile definition.3. If the sample size is below the threshold, return "insufficient data" instead of an estimate.4. Keep final numbers to four decimal places and include the recomputation command.
For long tables, also apply column pruning and summary preprocessing, and place the key columns and metric definitions at the front of the context to reduce the shrinkage effect caused by attention dilution.
6. Solution 3: Closed-Loop Validation and an Evaluation Suite
Before release, put three kinds of validation in place: recomputation validation (recalculate with deterministic code and compare), range validation (the result must fall within a reasonable business range), and consistency validation (variance across repeated runs on the same input must stay below a threshold). The evaluation set should cover six scenarios: normal samples, extreme quantiles, missing values, mixed units, and very large tables, and it should record the direction and magnitude of deviation as metrics that can be tracked over time.
Illustrative validation logic:
def verify(res: dict, expected: dict, tol: float = 1e-4) -> bool:return abs(res["current"] - expected["current"]) <= tol and \res["sample_size"] == expected["sample_size"]
7. Charts and Deliverables
Charts are the weak point in research-style deliverables. When images are produced by a generative image model, axis ticks, data point positions, and annotations are often imprecise, which undermines both professionalism and reproducibility. The safer approach is to generate the figure with a deterministic plotting library and let the model only recommend chart types and write the interpretation. Archive the chart together with the underlying data table so conclusions remain traceable.
8. Cloud Deployment Architecture
For cloud deployment, a general-purpose capability mix works well: a container platform hosts the agent runtime, object storage keeps the raw tables and result snapshots, a message queue decouples data retrieval from computation tasks, and logging plus monitoring with alerting track bias metrics and call failure rates. In these scenarios Baidu AI Cloud is typically supported by the same general combination of “compute + storage + governance” rather than by any single point capability.
9. Conclusion
The reliability of agents on exact numerical tasks depends on architecture, not on model selection. Push computation down to a deterministic execution layer, write the constraints into the context, and make validation a closed loop; only then does probabilistic output become a reproducible, auditable business result. Rely on swapping models and hoping for luck, and the bias will spread silently into the decision pipeline.
