Keep the LLM Out of the Arithmetic: Let It Classify, Let Code Compute
TL;DR — An LLM-powered planning feature had to combine qualitative judgment with exact financial arithmetic: real versus nominal values, inflation, exchange rates, and range direction. Letting a single model call do both meant every calculation inherited the model’s completion habits — plausible numbers that were quietly wrong. The architecture that held: the model fills a fixed set of about 11 structured blocks with plain categorical fields, deterministic code owns every calculation and sign, and inputs that fit no block produce an explicit “unsupported” outcome with a qualitative fallback — logged, never forced. We verified it by replaying six historically decided cases through the new format and requiring exact reproduction of the signed results.
The real risk is subtle error, not obvious failure
Section titled “The real risk is subtle error, not obvious failure”When an LLM is asked to both judge and calculate, the arithmetic does not fail loudly. A model asked for a number produces a plausible one — that is what completion engines do. The failure mode you actually encounter is a figure that is off by a sign, a year of inflation, or a currency unit, presented with the same confidence as a correct one. Nothing flags it, because nothing in the output indicates that the value was constructed rather than derived.
| What the model does well | What the model cannot guarantee |
|---|---|
| Judging whether an input is a transfer or a purchase | Compounding inflation over N years |
| Classifying a messy description | Preserving sign through an asset-versus-liability subtraction |
| Recognizing that real and nominal values differ | Producing the exact real value every time |
| Producing a plausible figure on demand | Producing the derivable figure on demand |
The left column is pattern recognition — a genuine model strength. The right column is deterministic transformation, where a single silent error corrupts everything downstream. The mistake is not asking the model to do hard math; it is asking it to do exact math, where exactness is not a capability an LLM has at all.
The setup
Section titled “The setup”The feature in question takes a user’s free-form description of a financial situation and turns it into quantitative figures — values adjusted for inflation, converted across currencies and time, and ranges with an attached direction. That is two distinct kinds of work in one pipeline: categorical judgment over messy human input, and precise computation over the result.
The naive design — one prompt in, one report out — collapses the two. The model reads the situation, decides the categories, does the math, and formats the output in a single pass. Every downstream figure inherits every upstream error, and there is no seam where a check could be inserted.
flowchart LR
U["User input"] --> M["LLM: judge + calculate + format"]
M --> O["Report with figures"]
O --> S["Shipped — no seam to verify"]
Diagnosis: exactness is a property of the mechanism, not the model
Section titled “Diagnosis: exactness is a property of the mechanism, not the model”Two findings drove the redesign.
-
The model’s strength conflicts with exactness. A completion engine fills gaps plausibly; an arithmetic pipeline must close them deterministically. These are different mechanisms, not points on a single quality axis. Prompting harder (“be precise with the math”) asks a probability-shaping instrument for a property it cannot supply. When errors do occur, they are subtle: a plausible figure, a flipped direction, a real-versus-nominal mix-up — invisible in review, fatal in a report.
-
An undifferentiated call leaves no seam to verify. With judgment and computation fused in one output, you cannot check the arithmetic without re-deriving it — and if you trusted the model to derive it once, you will trust it again. The fix is not a better model call; it is an architecture that separates the two kinds of work by a boundary a test can sit on.
The fix: blocks in, arithmetic out, unsupported explicit
Section titled “The fix: blocks in, arithmetic out, unsupported explicit”The redesign splits the work at the natural seam.
The model classifies, in two phases. It first selects which categories apply to the input, then fills the selected blocks — a fixed, closed set of about 11 structured categories. Every field in a block is plain and categorical: which values, which years, which currency, which direction. There is no arithmetic anywhere in the model’s contract.
Code computes everything. Inflation, real-versus-nominal conversion, exchange rates, risk premium, and range direction are all derived deterministically from the block fields. A sign flip is now impossible upstream of computation, because the model never emits a sign to flip; it emits a category, and the code attaches the sign.
“Unsupported” is a first-class outcome. When an input fits no block, the system does not force a structured answer. It logs a distinct “unsupported” event and falls back to qualitative reasoning with no figures. A graceful-degradation path you can query is worth more than a fabricated fit you cannot find: unsupported inputs appear in the log as a count, not as wrong numbers in a report.
flowchart LR
U["User input"] --> P1["Phase 1: LLM selects applicable blocks"]
P1 --> P2["Phase 2: LLM fills plain categorical fields"]
P2 --> C["Deterministic code: inflation, FX, signs, ranges"]
P1 -->|"fits no block"| UNQ["'Unsupported' event logged"]
UNQ --> Q["Qualitative fallback — no figures"]
C --> O["Verified report with figures"]
What was deliberately not done: no arithmetic hints were added to the prompt, no “show your work” scaffolding was added, and no second model was asked to check the first. Once computation lives in code, none of those compensations are load-bearing — and each would have added cost and latency to guard a seam that no longer exists.
Outcome: verified against history, not plausibility
Section titled “Outcome: verified against history, not plausibility”The acceptance bar was set before the new format shipped. Six historically decided cases — real, previously verified decisions — were hand-encoded in the block schema as fixtures. The new pipeline had to reproduce the exact previously verified outputs, signs and range direction included, before any other testing proceeded.
| Configuration | Arithmetic error surface | Out-of-domain inputs | Verifiability |
|---|---|---|---|
| One-call LLM (judge + compute + format) | Every figure | Silently forced into an answer | None — no seam to check |
| Blocks + code computes | Zero — no math in model output | Logged as “unsupported”, qualitative fallback | Block fields checkable; computation replayable from fixtures |
The six historical fixtures reproduced their original signed results across three scenarios, with correct range direction. One known gap — a zero-value line the block schema did not capture — was carved out of the test explicitly rather than left as an implicit pass.
The honest limit of this pattern: the block vocabulary is the contract. An input the about-11 categories cannot express lands in “unsupported,” which is correct behavior but still a gap until a new block is added — and each new block extends the fixture set. The design makes the gap visible and countable; it does not make it zero.
A checklist for LLM features that touch numbers
Section titled “A checklist for LLM features that touch numbers”- Split judgment from computation at a hard seam. If the model emits a number, ask what mechanism guarantees it — “the prompt asked nicely” is not a mechanism.
- Give the model a closed set of categories, not an open output space. Categorical choices are checkable; free-form figures are not.
- Make the model’s output the input to calculation, never the result of it. Signs, units, and directions attach in code, where they are deterministic.
- Make “unsupported” explicit and logged. An input that fits no category is an event you count, not a gap the model fills.
- Verify new formats by replaying history. Hand-encode known-good past cases in the new schema and require exact reproduction — signs included — before trusting it on new inputs.
- Carve out known gaps explicitly. A documented hole in the fixture set is honest; a silent pass is not.
Conclusion
Section titled “Conclusion”The LLM was not bad at math — it was the wrong kind of mechanism for it. Restricting the model to categorical judgment and handing computation to code means every figure in the output is derived, not recalled or invented: invented values are indistinguishable in form from real ones, and derived ones are the only kind you can replay from fixtures. Judgment and exactness both survive — each on the side of the seam where it is genuinely a strength.
This is the fourth post in a series on verification and decision patterns for LLM-powered features. The thesis reflects the provenance-enforcement story: do not trust the artifact — trust the mechanism that produced it.