Deterministic verification middleware for banking and financial AI.
Part of the QWED Ecosystem - Verification Infrastructure for AI
QWED-Finance is a middleware layer that applies QWED's deterministic verification to banking and financial calculations. It ensures AI-generated financial outputs are mathematically correct before they reach production.
| Feature | Description |
|---|---|
| NPV/IRR Verification | Validate net present value and internal rate of return calculations |
| Loan Amortization | Verify payment schedules and interest calculations |
| Compound Interest | Check compound interest formulas with precision |
| Currency Safety | Prevent floating-point errors in money calculations |
| ISO 20022 Schemas | Built-in support for banking message standards |
- Verification middleware that checks LLM-generated financial outputs
- Deterministic โ uses symbolic math (SymPy) and formal proofs (Z3)
- Open source โ integrate into any fintech workflow, no vendor lock-in
- A safety layer โ catches calculation errors before they cause real losses
A trading platformโ use Bloomberg or Refinitiv for thatA market data providerโ use AlphaSense or FactSet for thatAn analytics dashboardโ use Koyfin or Morningstar for thatA replacement for risk modelsโ we just verify their outputs
Think of QWED-Finance as the "unit test" for AI-generated financial calculations.
Bloomberg provides data. AlphaSense analyzes. QWED verifies the math.
| Aspect | Bloomberg / Refinitiv / AlphaSense | QWED-Finance |
|---|---|---|
| Approach | Probabilistic AI analytics | Deterministic symbolic verification |
| Output | "NPV is approximately $180.42" | VERIFIED: NPV = $180.42 โ (with proof) |
| Accuracy | ~95% (estimation, approximation) | 100% mathematical certainty |
| Tech | ML models, LLMs | SymPy + Z3 SMT Solver |
| Model | $20k+/year enterprise SaaS | Free (Apache 2.0 License) |
| Data | Proprietary market data | Your data, verified locally |
โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ
โ Bloomberg โ โโโบ โ QWED-Finance โ โโโบ โ Verified โ
โ (AI outputs) โ โ (verifies) โ โ Output โ
โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ
KYC/AML regulatory verification with formal boolean logic proofs.
from qwed_finance import ComplianceGuard
guard = ComplianceGuard()
# Verify AML flagging decision
result = guard.verify_aml_flag(
amount=15000, # Over $10k threshold
country_code="US",
llm_flagged=True # LLM flagged it
)
# result.compliant = True โ
Supports:
- AML/CTR threshold checks (BSA/FinCEN)
- KYC completion verification
- Transaction limit enforcement
- OFAC sanctions screening
Deterministic day counting for interest accrual - no date hallucinations.
from qwed_finance import CalendarGuard, DayCountConvention
from datetime import date
guard = CalendarGuard()
# Verify 30/360 day count
result = guard.verify_day_count(
start_date=date(2026, 1, 1),
end_date=date(2026, 7, 1),
llm_days=180,
convention=DayCountConvention.THIRTY_360
)
# result.verified = True โ
Supports:
- 30/360 (Corporate bonds)
- Actual/360 (T-Bills)
- Actual/365 (UK gilts)
- Business day verification
Options pricing and margin verification using pure calculus.
from qwed_finance import DerivativesGuard, OptionType
guard = DerivativesGuard()
# Verify Black-Scholes call price
result = guard.verify_black_scholes(
spot_price=100,
strike_price=105,
time_to_expiry=0.25, # 3 months
risk_free_rate=0.05,
volatility=0.20,
option_type=OptionType.CALL,
llm_price="$3.50"
)
# result.greeks = {"delta": 0.4502, "gamma": 0.0389, ...}Validate LLM-generated banking messages conform to industry standards.
from qwed_finance import MessageGuard, MessageType
guard = MessageGuard()
# Verify ISO 20022 pacs.008 message
result = guard.verify_iso20022_xml(
xml_string=llm_generated_xml,
msg_type=MessageType.PACS_008
)
# result.valid = True/False with detailed errors
# Verify IBAN checksum
iban_result = guard.verify_iban(
iban="DE89370400440532013000",
llm_says_valid=True
)
# Uses MOD 97 checksum - 100% deterministicSupports:
- ISO 20022: pacs.008, pacs.002, camt.053, camt.054, pain.001
- SWIFT MT: MT103, MT202, MT940, MT950
- BIC/IBAN validation with MOD 97 checksum
Prevent LLM-generated SQL from mutating data or accessing restricted tables.
from qwed_finance import QueryGuard
guard = QueryGuard(allowed_tables={"accounts", "transactions"})
# Verify query is read-only
result = guard.verify_readonly_safety(
sql_query="SELECT * FROM accounts WHERE balance > 10000"
)
# result.safe = True โ
# Block mutation attempts
result = guard.verify_readonly_safety(
sql_query="DROP TABLE accounts;" # LLM hallucinated this
)
# result.safe = False, result.risk_level = CRITICAL โPrevents:
- DELETE, UPDATE, INSERT, DROP statements
- Unauthorized table access
- PII column exposure (SSN, passwords)
- SQL injection patterns
Combine multiple guards for comprehensive verification.
from qwed_finance import CrossGuard
guard = CrossGuard()
# SWIFT message + Sanctions check
result = guard.verify_swift_with_sanctions(
mt_string=llm_mt103_message,
sanctions_list=["SANCTIONED CORP", "BLOCKED ENTITY"]
)
# Validates MT format AND scans for sanctioned entities
# SQL + PII protection
result = guard.verify_query_with_pii_protection(
sql_query="SELECT * FROM customers",
allowed_tables=["customers", "orders"],
pii_columns=["ssn", "password", "credit_card"]
)Yield and duration calculations for fixed income verification.
from qwed_finance import BondGuard
guard = BondGuard()
# Verify YTM calculation
result = guard.verify_ytm(
face_value=1000,
coupon_rate=0.05, # 5% annual coupon
price=950, # Trading at discount
years_to_maturity=10,
llm_ytm="5.73%" # LLM's answer
)
# Uses Newton-Raphson solver - 100% deterministic
# Verify Duration
result = guard.verify_duration(
face_value=1000,
coupon_rate=0.05,
ytm=0.06,
years_to_maturity=10,
llm_duration="7.8 years"
)
# Verify Convexity
result = guard.verify_convexity(
face_value=1000,
coupon_rate=0.05,
ytm=0.06,
years_to_maturity=10,
llm_convexity="68.5"
)Supports:
- Yield to Maturity (YTM) - Newton-Raphson solver
- Macaulay Duration
- Modified Duration
- Convexity
- Accrued Interest
- Dirty Price
Foreign exchange rate verification using Interest Rate Parity.
from qwed_finance import FXGuard
guard = FXGuard()
# Verify Forward Rate (Interest Rate Parity)
result = guard.verify_forward_rate(
spot_rate=1.10, # EUR/USD spot
domestic_rate=0.05, # USD rate
foreign_rate=0.02, # EUR rate
days=90, # 90-day forward
llm_forward="1.1081" # LLM's answer
)
# Formula: F = S ร (1 + rd ร T) / (1 + rf ร T)
# Verify Cross Rate Triangulation
result = guard.verify_cross_rate(
rate_a_b=1.10, # EUR/USD
rate_b_c=150.0, # USD/JPY
llm_rate_a_c="165.00", # EUR/JPY
pair_a="EUR", pair_b="USD", pair_c="JPY"
)
# Verify NDF Settlement
result = guard.verify_ndf_settlement(
notional=1000000,
contract_rate=1.10,
fixing_rate=1.12,
llm_settlement="$17,857.14"
)Supports:
- Forward Rate (IRP)
- Cross Rate Triangulation
- Swap Points
- NDF Settlement
- Currency Conversion
- Triangular Arbitrage Detection
Portfolio risk metrics verification - VaR, Beta, Sharpe.
from qwed_finance import RiskGuard
guard = RiskGuard()
# Verify VaR (Parametric)
result = guard.verify_var(
portfolio_value=1000000,
daily_volatility=0.02, # 2% daily vol
confidence_level=0.95, # 95% confidence
holding_period_days=1,
llm_var="$32,900" # LLM's answer
)
# Formula: VaR = P ร ฯ ร z ร โt
# Verify Sharpe Ratio
result = guard.verify_sharpe_ratio(
portfolio_return=0.12, # 12% annual return
risk_free_rate=0.03, # 3% risk-free
portfolio_volatility=0.15,
llm_sharpe="0.60"
)
# Verify Beta
result = guard.verify_beta(
asset_returns=[0.02, -0.01, 0.03, 0.01, -0.02],
market_returns=[0.01, -0.005, 0.02, 0.005, -0.01],
llm_beta="1.45"
)
# Verify Maximum Drawdown
result = guard.verify_max_drawdown(
portfolio_values=[100, 110, 105, 95, 100, 98],
llm_max_dd="-13.64%"
)Supports:
- Value at Risk (Parametric VaR)
- Portfolio Beta
- Sharpe Ratio
- Sortino Ratio
- Maximum Drawdown
- Expected Shortfall (CVaR)
- Information Ratio
Validate AI-generated payment messages against ISO 20022 JSON schemas.
from qwed_finance import ISOGuard
guard = ISOGuard()
# Verify ISO 20022 pacs.008 payment message
result = guard.verify_payment_message({
"MsgId": "MSG001",
"CreDtTm": "2026-01-15T10:30:00Z",
"NbOfTxs": 1,
"TtlIntrBkSttlmAmt": {"amount": 50000.00, "currency": "USD"}
})
# result.verified = True โ
# result.standard = "ISO 20022"pip install qwed-financefrom qwed_finance import FinanceVerifier
verifier = FinanceVerifier()
# Verify NPV calculation
result = verifier.verify_npv(
cashflows=[-1000, 300, 400, 400, 300],
rate=0.10,
llm_output="$180.42"
)
if result.verified:
print(f"โ
Correct: {result.computed_value}")
else:
print(f"โ Wrong: LLM said {result.llm_value}, actual is {result.computed_value}")# Net Present Value
verifier.verify_npv(cashflows, rate, llm_output)
# Internal Rate of Return
verifier.verify_irr(cashflows, llm_output)
# Future Value
verifier.verify_fv(principal, rate, periods, llm_output)
# Present Value
verifier.verify_pv(future_value, rate, periods, llm_output)# Monthly Payment
verifier.verify_monthly_payment(principal, annual_rate, months, llm_output)
# Amortization Schedule
verifier.verify_amortization_schedule(principal, rate, months, llm_schedule)
# Total Interest Paid
verifier.verify_total_interest(principal, rate, months, llm_output)# Compound Interest
verifier.verify_compound_interest(
principal=10000,
rate=0.05,
periods=10,
compounding="annual", # "monthly", "quarterly", "daily"
llm_output="$16,288.95"
)
# Simple Interest
verifier.verify_simple_interest(principal, rate, time, llm_output)โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ YOUR APPLICATION โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ QWED-FINANCE โ
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โ
โ โ Finance โ โ Banking โ โ
โ โ Verifier โ โ Schemas โ โ
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ QWED-VERIFICATION (Core) โ
โ โโโโโโโโโโโ โโโโโโโโโโโ โโโโโโโโโโโ โ
โ โ Math โ โ Logic โ โ Schema โ โ
โ โ (SymPy) โ โ (Z3) โ โ (JSON) โ โ
โ โโโโโโโโโโโ โโโโโโโโโโโ โโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Financial calculations must be exact. AI hallucinations in banking can cause:
- ๐ธ Wrong loan payments
- ๐ Incorrect investment projections
- โ๏ธ Regulatory violations
- ๐ฆ Customer trust issues
QWED-Finance uses SymPy (symbolic math) instead of floating-point arithmetic, ensuring:
# Floating-point problem
>>> 0.1 + 0.2
0.30000000000000004
# QWED-Finance (SymPy)
>>> verifier.add_money("$0.10", "$0.20")
"$0.30" # Exact!๐ See Determinism Guarantee for how QWED ensures 100% reproducible verification.
Your financial data never leaves your machine.
| Concern | QWED-Finance Approach |
|---|---|
| Data Transmission | โ No API calls, no cloud processing |
| Storage | โ Nothing stored, pure computation |
| Dependencies | โ Local-only (SymPy, Z3, SQLGlot) |
| Audit Trail | โ Cryptographic receipts, fully reproducible |
Perfect for:
- Banks with strict data residency requirements
- Transactions containing PII (SSN, account numbers)
- SOC 2 / PCI-DSS compliant environments
- Air-gapped trading systems
Is QWED-Finance free?
Yes! QWED-Finance is open source under the Apache 2.0 license. Use it in commercial fintech products, modify it, distribute it - no restrictions.
Does it handle floating-point precision issues?
Yes! QWED-Finance uses SymPy for symbolic mathematics, avoiding the classic 0.1 + 0.2 = 0.30000000000000004 problem. All monetary calculations are exact.
Can it verify Black-Scholes calculations?
Yes! The DerivativesGuard includes full Black-Scholes implementation with Greeks (delta, gamma, theta, vega, rho). All calculations use symbolic math for precision.
Does it support ISO 20022?
Yes! MessageGuard validates ISO 20022 XML messages (pacs.008, camt.053, pain.001) and legacy SWIFT MT formats (MT103, MT202, MT940).
Can I use it to prevent SQL injection in AI agents?
Yes! QueryGuard uses SQLGlot for AST-based analysis. It can block mutations, restrict table access, and prevent PII column exposure - all deterministically.
How fast is verification?
Typically <5ms for simple calculations, <50ms for complex derivatives pricing. The symbolic engine is highly optimized.
- FinanceVerifier: NPV, IRR, FV, PV calculations
- ComplianceGuard: KYC/AML verification (Z3)
- CalendarGuard: Day count conventions
- DerivativesGuard: Black-Scholes, Greeks
- MessageGuard: ISO 20022, SWIFT MT, IBAN/BIC
- QueryGuard: SQL safety, PII protection
- CrossGuard: Multi-layer verification
- Verification Receipts with audit trail
- TypeScript/npm SDK (@qwed-ai/finance)
- BondGuard: YTM, Duration, Convexity verification
- FXGuard: Forward rates, Cross rates, NDF settlement
- RiskGuard: VaR, Beta, Sharpe, Sortino, Max Drawdown
-
verification_modefield (SYMBOLIC/HEURISTIC)
- More regulatory frameworks (MiFID II, Basel III)
- Credit risk models (PD, LGD, EAD)
- Real-time market data validation
- Integration with OpenBB Terminal
- VS Code extension for trading desk
| Package | Description |
|---|---|
| qwed-verification | Core verification engine |
| qwed-legal | Legal contract verification |
| qwed-tax | Tax calculation verification |
| qwed-ucp | E-commerce verification |
| qwed-mcp | Claude Desktop integration |
Automatically verify your banking AI agents in your CI/CD pipeline!
- Create
.github/workflows/qwed-verify.ymlin your repo:
name: QWED Finance Verification
on: [push, pull_request]
jobs:
verify:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: QWED-AI/qwed-finance@v2.0.1
with:
test-script: tests/verify_agent.py- Create your verification script
tests/verify_agent.py:
from qwed_finance import ComplianceGuard, OpenResponsesIntegration
def test_aml_compliance():
guard = ComplianceGuard()
result = guard.verify_aml_flag(
amount=15000,
country_code="US",
llm_flagged=True
)
assert result.compliant, f"AML check failed!"
print("โ
Verification passed!")
if __name__ == "__main__":
test_aml_compliance()- Commit and push - the action runs automatically! ๐
| Input | Required | Default | Description |
|---|---|---|---|
test-script |
โ | - | Path to your Python test script |
python-version |
โ | 3.11 |
Python version to use |
fail-on-violation |
โ | true |
Fail workflow on verification failure |
To block PRs that fail verification, add this to your branch protection rules:
- Settings โ Branches โ Add Rule
- Check "Require status checks to pass"
- Select "verify" job
Show that your project uses QWED verification! Choose the badge that matches your use case:
| Badge | Use Case | Markdown |
|---|---|---|
| General - Any QWED-Finance integration | See below | |
| FinanceVerifier/BondGuard - Symbolic math only | See below | |
| ComplianceGuard - Z3 + LLM hybrid | See below |
General Badge:
[](https://github.com/QWED-AI/qwed-finance)100% Deterministic (for FinanceVerifier, CalendarGuard, BondGuard, FXGuard):
[](https://docs.qwedai.com/docs/engines/overview#deterministic-first-philosophy)AI + Verification (for ComplianceGuard with Z3):
[](https://docs.qwedai.com/docs/engines/overview#deterministic-first-philosophy)Apache 2.0 - See LICENSE
Contributions welcome! Please read CONTRIBUTING.md first.