I want to talk about a problem that comes up constantly in production AI agent systems, and gets far less attention than it deserves.
LLMs are bad at math. Not always, not catastrophically, but unreliably enough that you should not be betting your agent's output on it.
This is not a hot take. It is a well-documented limitation. Models drift on floating point operations, produce plausible-but-wrong statistical summaries, and give you different answers to the same calculation across runs. For exploratory work, this is fine. For agents making decisions based on numeric data, it is a real problem.
The usual answer and why it is incomplete
Most teams reach for a code execution tool. You give the agent access to a Python sandbox, and it writes and runs the calculation itself.
This works for simple cases. It gets messy when:
- You need reproducible results across agent runs (different seeds, non-deterministic execution)
- The math is part of a longer pipeline where output shape matters (the regression result needs to go directly into a chart tool)
- You are working with large arrays that you do not want to re-send through the model context on every step
- You need the operation to be verifiable, not just correct-looking
What we built
DataGrout Math is a set of MCP tools that cover the numeric operations agents actually need. Twelve tools across three categories.
Generation
math.range — evenly-spaced sequences from start to stop with exact step computation to avoid cumulative float drift. Up to 10,000 values per call.
math.linspace — generate exactly N points between two bounds, equivalent to NumPy's linspace.
math.sequence — named mathematical sequences: arithmetic, geometric, Fibonacci, triangular, square, prime, and powers.
math.sample — draw samples from uniform, normal, or exponential distributions. Pass a seed for reproducible output across runs.
math.interpolate — apply lerp, inverse lerp, clamp, remap, smoothstep, smootherstep, and with 12 easings + 6 modes (lerp, inverse_lerp, clamp, remap, smoothstep, smootherstep) = 18 modes
Analysis
math.describe — full descriptive statistics: count, mean, median, standard deviation, variance, min, max, sum, range, skewness, percentiles (p5 through p95), and a binned histogram. Up to 100,000 values per call.
math.window — sliding window operations: moving average, moving sum, cumulative sum, first differences, percent change, lag, and EWMA with configurable alpha.
math.normalize — z-score, min-max, and percentile rank normalization. Returns both normalized values and original values in records for comparison charting.
math.outliers — IQR and z-score outlier detection. Returns outlier indices, threshold bounds, a clean array with outliers removed, and per-value boolean flags.
math.rank — ordinal, dense, average, and percentile ranking with ascending or descending order.
Modeling
math.correlate — Pearson and Spearman correlation with r-squared, interpretation labels (strong positive, weak negative, etc.), and paired records for scatter plot visualization.
math.trend — fit linear, polynomial (degree 2 through 5), exponential, and logarithmic regressions. Returns coefficients, r-squared, direction label, equation string, fitted values for overlay charting, and optional forward forecast points.
How it fits into an agent pipeline
Every tool returns two output shapes: a values array and a records array. This is intentional.
values feeds into other math tools. records feeds directly into prism.chart for visualization, no reshaping required.
Tools also accept a cache_ref parameter. If you ran a Data or Frame tool in a previous step and got a cache reference back, you pass that reference directly to a math tool. The array never goes back through the LLM context. This matters when you are working with datasets of any real size.
Every response includes a deterministic receipt under _meta.datagrout. The gateway verifies the result is reproducible. Same inputs always produce same outputs.
All tools are versioned at data-grout@1/math.*@1. You can pin your agent instructions to a specific version and they will not break when we ship updates.
A concrete example
Here is a workflow that shows how these tools chain together.
An agent pulls revenue records from a Salesforce integration. It passes the cache_ref to math.outliers to detect anomalous months using IQR. It takes the clean_values output and passes it to math.trend with a 3-step forecast. It pipes the fitted records from trend into prism.chart with the original values overlaid. The entire numeric pipeline runs without a single LLM token spent on arithmetic.
That is the point. The agent's cognition is reserved for reasoning about the results, not computing them.
Getting started
DataGrout Math is available through the DataGrout MCP gateway. Connect your agent and call any tool at DataGrout.
Full parameter reference and examples are in the documentation at library.datagrout.ai/math-tools.
We launched on Product Hunt today if you want to follow along or leave feedback.
Top comments (0)