# Grounded Math & Quote Verification Compiler

> Zero-dependency Python verification compiler that grounds every LLM quote to exact character offsets and executes deterministic Decimal math with accounting, currency, and statute guardrails.

Grounded Math & Quote Verification Compiler is a paid AI agent skill on Agensi by Wasabi hu, in LLM Ops. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: $7.99 (one-time purchase)
- Creator: [Wasabi hu](https://www.agensi.io/creators/wasabi-hu)
- Category: [LLM Ops](https://www.agensi.io/skills/llm-ops)
- Version: 1.0.0
- Last updated: 2026-12-01
- Security: scan passed (2026-12-01); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/grounded-math-quote-verification-compiler
- Tags: llm-ops, finance, legal, verification, math, python

## About this skill

LLMs frequently hallucinate numbers, fail at mental arithmetic, and paraphrase quotes until they no longer match the source document. This skill turns any coding or research agent into a deterministic verification compiler—never letting the model guess figures or calculate math in prose.

### What it does
Three standalone, offline Python 3.11+ scripts verify every quote and calculation against unmodified source files:

1. **Stage 1 — Lossless Table Focusing (`scripts/focus_prompt_tables.py`)**: Slices wide multi-year Markdown tables (including empty leading header cells like `|| 2025 | 2024 |`) to target columns and prunes 30+ row statements to relevant lines ±2 neighbors. Automatically skips pruning on aggregation queries (`total`, `sum`, `highest`, `which`) and checks omitted rows before accepting an `ABSENT` verdict (`check-absent-retry`).
2. **Stage 2 — Grounded Span & Exact Decimal Math (`scripts/verify_grounded_math.py`)**: Strips `<think>` blocks and code fences from the model's single-line JSON DSL plan, locates every snippet character-for-character on the untouched source document using 1-to-1 Unicode and Traditional/Simplified CJK folding (`len(norm) == len(orig)`), executes exact `Decimal` operations (`VALUE`, `TEXT`, `ADD`, `SUB`, `ABS_DIFF`, `MUL`, `DIV`, `COUNT`, `COMPARE`, `ABSENT`, `CONFLICT`) including parenthesized accounting negatives like `(4,120)`, and enforces five strict firewalls:
   - Blocks `-`, `—`, `--`, and `N/A` placeholders from grounding numeric answers
   - Blocks silent cross-currency arithmetic (`RMB` + `USD`) and cross-dimension mixing (`%` + money)
   - Rejects unflagged cross-period summations on `ADD`
   - Rejects statutory article mismatches (asking about Article 999 when citing Article 42)
   - Rejects coarse rounded `亿元` headlines when exact `元` or `千元` table precision was requested
   - Runs double execution to confirm `symbolic.replay_identical == true`
3. **Stage 3 — Zero-Token Batch Replay Audit (`scripts/batch_replay_audit.py`)**: Re-executes archived verification records offline with zero LLM calls to flag `OFFSET_DRIFT`, `HALLUCINATED_QUOTE`, and `ARITHMETIC_MISMATCH`.

### Runtime & security design
Built strictly on Python 3.11+ standard library (`decimal`, `json`, `re`, `pathlib`, `argparse`). Zero third-party packages, zero network calls, zero environment variable reads, zero native C bindings, and read-only stdout JSON output.

### Included references
- `references/dsl-spec.md` — Schema for all 11 DSL operations, optional operand fields, and error retry hints.
- `references/guardrails.md` — 1-to-1 offset preservation, accounting negative parsing, and firewall rules.
- `references/examples.md` — Complete synthetic walkthroughs across financial, clinical, and statutory inputs.

### Known limitations
Operates on extracted Markdown or plain text; does not run OCR on image-only scanned PDFs, fetch live external data, or provide financial or legal advice.

## Requires

- Python

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the Grounded Math & Quote Verification Compiler skill from Agensi" and describe your task.
3. Buy it on the listing or let your agent ask you first; your agent then loads it from Agensi when it needs it. Every paid skill has a money-back guarantee: https://www.agensi.io/docs/money-back-guarantee

## Frequently asked questions

### What specific problems does this skill solve for my AI workflow?

This skill solves the problem of LLMs hallucinating numbers or paraphrasing text during data extraction. It forces the agent to use a neuro-symbolic compiler that verifies every quote against exact character offsets and executes math via a deterministic Decimal runtime instead of error-prone mental arithmetic.

### What files or software do I need to use this skill?

The skill provides three core Python scripts: focus_prompt_tables.py for shrinking large tables, verify_grounded_math.py for checking quotes and executing arithmetic, and batch_replay_audit.py for offline verification. You only need a Python 3.11 plus environment with standard libraries like decimal and json to run these tools.

### Are there any document types or tasks that this skill cannot handle?

This skill cannot perform OCR on images or PDF files, so documents must be converted to Markdown or plain text first. It is also not intended for probabilistic forecasting, external data fetching, or making investment recommendations.

### What kind of outputs and verification results should I expect?

The skill produces structured JSON DSL plans and audit logs that confirm if a claim is valid or rejected. It enforces hard firewalls against currency mixing, unit precision errors, and statutory article mismatches, ensuring that every output is grounded in the source text.

### How should I instruct my agent to interact with this skill?

You can direct your agent to use the scripts to verify specific financial deltas, reconcile GAAP adjustments, or extract verbatim statutory clauses. For example, ask the agent to focus a wide Markdown table first and then emit a JSON plan to verify a net profit calculation against the original document.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
