---
title: "Stop LLM hallucinations in financial calculations"
description: "A model can always write a wrong figure. How to stop a wrong figure from being used: get the inputs, recompute with exact decimals, and act only on a match."
url: https://qwedai.tech/guides/llm-finance
---

[Engines](https://qwedai.tech/engines)

# How do you stop LLM hallucinations in financial calculations?

In finance, a wrong figure reads exactly like a right one. This guide covers why a model's financial figures go wrong, how to check each one before it reaches a ledger, a customer or a report, what QWED Finance recomputes, and what such a check cannot tell you.

QWED project · Published 3 December 2026 · Updated 3 December 2026

## The short answer

You cannot stop a model from writing a wrong figure, but you can stop a wrong figure from being used. Have the model return the inputs and the formula, not only the number. Recompute the figure outside the model with exact decimal arithmetic, the compounding and day count the question asks for, and money rounded to the cent. Act only when the two agree within a tolerance you can name. QWED Finance, open source under Apache-2.0, does this for interest, loan payments, NPV and IRR, and has guards for bonds, FX, risk metrics and payment messages. It checks the arithmetic of the inputs it is given, not whether those inputs are right.

## Why do financial figures go wrong?

-   **The wrong formula.** Simple interest where the question meant compound, or a payment formula for the wrong term.
-   **The wrong convention.** Monthly compounding instead of annual, or a 360-day year instead of 365.
-   **Inexact arithmetic.** Ordinary floating-point numbers cannot hold most decimal fractions exactly, and small errors add up over many payments.
-   **A figure that changes on the way.** Even when a tool computed it, the model copies the result into its answer, and a digit can change there.

"Hallucination" is the usual word for all of these. A check does not detect hallucinations in general text; it recomputes a figure and compares. [Can LLMs do maths?](https://qwedai.tech/guides/llm-math)

## How do you check a financial figure?

1.  **Ask for the inputs, not only the answer** Have the model return the principal, rate, term, compounding and cash flows it used, as structured output, beside the figure it claims.
2.  **Recompute outside the model** Work the figure out again from those inputs with exact decimal arithmetic, the compounding and day count the question asks for, and money rounded to the cent.
3.  **Compare within a stated tolerance** Accept the figure only when the two agree within a tolerance you can name, such as one cent.
4.  **Act only on a match** Hold anything else for the model to try again, or for a person, and keep the inputs, both figures and the result as the record.

## An example

A model is asked for the value of 10,000 at 5% a year, compounded annually, after 10 years. Two answers, checked with QWED Finance 3.0.1:

| The model said | Recomputed | Difference | Result |
| --- | --- | --- | --- |
| $16,288.95 | $16,288.95 | 0 | `verified: True` |
| $16,470.09 | $16,288.95 | 181.14 | `verified: False` |

The second figure is what monthly compounding gives. It is a plausible number, and a reader would not notice; the recomputation does. To run it (`pip install qwed-finance`):

python

```
from qwed_finance import FinanceVerifier

verifier = FinanceVerifier()

# The question asked for annual compounding.
for figure in ("$16,288.95", "$16,470.09"):
    result = verifier.verify_compound_interest(
        principal=10000, rate=0.05, periods=10, compounding="annual", llm_output=figure
    )
    print(result.verified, result.computed_value, result.difference, result.formula_used)
# True $16,288.95 None A = P(1 + r/1)^(1t)
# False $16,288.95 181.14 A = P(1 + r/1)^(1t)
```

## What QWED Finance checks

Its `FinanceVerifier` recomputes five kinds of figure from the inputs you pass, in Python's `Decimal` rather than floating point, with money rounded half up to the cent, and accepts the model's figure within a fixed tolerance:

| Check | Recomputes | Accepted within |
| --- | --- | --- |
| `verify_npv` | Net present value of a series of cash flows | one cent |
| `verify_irr` | Internal rate of return | 0.0001 by default |
| `verify_monthly_payment` | The monthly payment on a loan | one cent |
| `verify_total_interest` | Total interest paid over a loan | ten cents |
| `verify_compound_interest` | A compounded amount, annual to daily | one cent |

The package also has guards for other figures and messages: bond yields and duration, FX rates by interest rate parity, risk metrics such as VaR, beta and Sharpe, day-count conventions, Black-Scholes prices, ISO 20022 and SWIFT payment messages, KYC and AML rules checked with Z3, and SQL. [QWED Finance](https://qwedai.tech/platform/finance) · [Banking and payments](https://qwedai.tech/solutions/banking)

The package returns `verified: True` or `False` with the recomputed figure. Your application decides what happens next; QWED Finance does not hold or release anything by itself.

## What it does not check

-   **Whether the inputs are right.** The check recomputes from the principal, rate and terms it is given. If the model picked the wrong rate, the check confirms the arithmetic on the wrong rate.
-   **Which formula the question needed.** You choose the check and the compounding. A figure that matches the wrong formula passes that formula.
-   **Anything inside the tolerance.** A figure within a cent passes, as does a total within ten cents.
-   **The currency.** The figure is read without its currency symbol, so €16,288.95 passes a check in dollars ([qwed-finance#114](https://github.com/QWED-AI/qwed-finance/issues/114), open).
-   **Its own open bugs.** QWED Finance is a beta package with open bug reports, some of which change a result for some inputs. Read the list before relying on it for a case. [Known open issues](https://qwedai.tech/limits#open-issues)
-   **Regulation.** It checks figures and messages. It is not a trading platform, a market data feed or a replacement for your risk models, and checks for MiFID II and Basel III are still in progress.

[Everything QWED does not verify](https://qwedai.tech/limits)

## Sources and further reading

-   [qwed-finance](https://github.com/QWED-AI/qwed-finance). The package’s source, README and open issues.
-   [QWED Finance documentation](https://finance.qwedai.tech). The package’s own documentation.
-   [Python documentation: decimal](https://docs.python.org/3/library/decimal.html). Decimal fixed point and floating point arithmetic, the kind money needs.

Written and reviewed by the QWED maintainers under the project's [governance model](https://qwedai.tech/governance). Found an error? [Contact us](https://qwedai.tech/contact).

## More guides

-   [### Runtime verification for AI output Checking each output before it is used Read](https://qwedai.tech/guides/runtime-verification)
-   [### How to verify LLM output What each kind of check catches Read](https://qwedai.tech/guides/verify-llm-output)
-   [### What fail-closed means For AI checks, and when fail-open is fine Read](https://qwedai.tech/guides/fail-closed)
-   [### Deterministic guardrails Rules, parsers and solvers for agents Read](https://qwedai.tech/guides/deterministic-guardrails)
-   [### How a claim gets proven What a proof engine does with a claim Read](https://qwedai.tech/guides/how-a-claim-gets-proven)
-   [### Can LLMs do maths? How to check AI calculations Read](https://qwedai.tech/guides/llm-math)
-   [### Checking reasoning with Z3 What a solver can settle, and what it cannot Read](https://qwedai.tech/guides/llm-reasoning-z3)
-   [### JSON Schema for LLM output Checking shape and values Read](https://qwedai.tech/guides/llm-json-schema)
-   [### LLM-generated SQL Guardrails that check a query before it runs Read](https://qwedai.tech/guides/ai-sql)
-   [### AI-generated code Is it safe to run, and what a check shows first Read](https://qwedai.tech/guides/ai-code)
-   [### Agent tool calls and MCP Three checks before a tool call runs Read](https://qwedai.tech/guides/agent-tool-calls)
-   [### Audit trails What each decision record holds Read](https://qwedai.tech/guides/ai-audit-trail)
