Engine Architecture · Multimodal OCR + Integer-Cent TypeScript

How WaiverAudit Audits Skewed Jobsite Scans Without AI Math Hallucinations

Construction accounting tolerates zero rounding drift. WaiverAudit separates optical reading from legal and mathematical judgment: zero-temperature multimodal vision extracts fields and confidence scores, raw AI verdicts are deleted on the server, and a deterministic TypeScript rules engine computes every G702/G703, COI, and 12-state statutory lien waiver check to ±$0.01.

AES-256 Cloudflare R2 storage · Zero model training · SHA-256 tamper-evident audit certificates

4-Stage Verification Pipeline

AI Reads the Pixels. Deterministic TypeScript Computes the Law & Math.

Pure LLMs hallucinate arithmetic; legacy OCR templates shatter when a subcontractor scans a tilted page. WaiverAudit isolates optical extraction from financial and statutory verification.

STAGE 01 · pdfValidation.ts · packetCutterHTTP 422 FAIL-SAFE · 0 CREDITS

Pre-Flight Gate & Combined Binder Splitting

Files stream directly to AES-256 Cloudflare R2 up to 50 MB / 200 pages (PDF, JPEG, PNG, WebP, or ZIP). Before touching an AI model, structural PDF validation rejects password-locked or corrupted files, and the Combined Packet Cutter separates multi-document subcontractor binders into discrete audit slots.

  • Rejects encrypted PDFs (PDF_PASSWORD_PROTECTED) and truncated byte streams (PDF_CORRUPTED) upfront with 0 credits deducted.
  • Auto-classifies merged subcontractor PDFs into Current Waiver, Invoice, AIA G702/G703, Prior Unconditional Waiver, and ACORD 25 COI.
  • Durable Inngest worker leases prevent duplicate charges on network retries or browser disconnects.
STAGE 02 · model.ts · auditResponseSchemaTEMP 0.0 · SCHEMA LOCKED

Zero-Temperature Multimodal Vision Extraction

Rather than brittle x/y bounding-box templates, WaiverAudit runs multimodal vision at temperature 0.0 under a strict JSON schema. The extractor reads skewed smartphone photos, rotated continuation sheets, wet signatures, and embossed notary seals—and emits a 0–100 confidence score per field.

  • Maps non-standard G703 headers ('Total Work to Date', 'Completed & Stored') semantically to Column G.
  • Inspects physical ink signatures, dates, and mandatory MS/WY notary jurats directly from rasterized page imagery.
  • 50-second bounded timeout; upstream 503/504 model timeouts never deduct workspace or pack credits.
STAGE 03 · engine.ts · reconcile.ts±$0.01 DETERMINISTIC MATH

Verdict Stripping & Integer-Cent TypeScript Engine

LLMs never decide pass/fail or compute construction math. Immediately after extraction, engine.ts strips any model-suggested verdicts and passes raw numbers into nine deterministic TypeScript reconciliation modules operating in integer cents.

  • Deletes verified_fields, review_required_fields, and verification_status from raw model output before rule execution.
  • Asserts G702 Line 6 - Line 7 == Line 8, G703 Terminal Col G == Line 4 (±$0.01), and Line 4 - Col G == Line 2 unitemized change-order diagnostics.
  • Enforces 12-state statutory waiver text, Two-Waiver Rule Line 7 parity, ACORD 25 ISO endorsements, and >$5,000 sub-tier supplier holds.
STAGE 04 · applyReview.ts · certificateHUMAN-IN-THE-LOOP OVERRIDE

<90 Confidence Gate & SHA-256 Audit Certificate

Any critical dollar figure, date, or statutory field extracted below 90/100 confidence automatically pauses green clearance and opens the side-by-side manual review drawer. Editing a field re-runs the deterministic TypeScript math in milliseconds with zero AI re-inference.

  • Highlights low-confidence (<90) smudges, handwritten edits, or faint seals in amber directly beside the source document.
  • Instant deterministic recalculation on auditor overrides—no second credit charge and no 14-day re-audit penalty.
  • Generates a tamper-evident PDF Draw Compliance Certificate stamped with a server-side SHA-256 payload hash.
VERDICT STRIPPING BOUNDARY (src/lib/audit/engine.ts)

Before reconciliation runs, the server explicitly strips verified_fields, review_required_fields, and verification_status from raw model output—then executes reconcileAudit() → [applyBilling, applyDates, applyAia, applyInsurance, applyPrior, applyNotary, applySuppliers, applyReview, applyVerdict] in integer cents (Math.round(amount * 100)).

Real-World Document Resilience

How the Engine Behaves Against Messy Jobsite Photos & Scans

Subcontractors rarely submit pristine vector PDFs. Every degraded document triggers either cross-checked extraction, an amber human-review hold, or a zero-cost pre-flight rejection—never a silent guess.

Document ConditionField RealityEngine BehaviorCredit Impact
Skewed smartphone photo on a truck tailgateJPEG/PNG shot at a 15° angle under uneven jobsite lightingMultimodal vision normalizes perspective distortion without fixed OCR crop boxes; extracts figures and flags blurred digits scoring <90 confidence in amber.1 audit credit (free instant manual override if needed)
150-DPI crooked copier scan or faxed PDFRasterized black-and-white scan with speckled toner noiseReads full-page visual context rather than legacy Tesseract character strips; deterministic G702 cross-checks catch single-digit OCR misreads immediately.1 audit credit (cross-validated by Line 6 - Line 7 == Line 8)
Handwritten markups, crossed-out retainage, or coffee stainsPM ink redlines over typed AIA G702 Line 5 or waiver considerationDrops field confidence below 90 and triggers REVIEW_REQUIRED so project accountants confirm the intended figure side-by-side before release.1 audit credit + 2 free re-audits within 14 days if rejected
Rotated landscape 30-page G703 continuation sheetsPortrait G702 cover followed by 90°-rotated landscape SOV tablesIgnores intermediate page footers, isolates the terminal cumulative Column G Grand Total, and reconciles against G702 Line 4 within ±$0.01.Included in single draw packet up to 200 pages / 50 MB
Faint embossed notary seal or missing jurat (MS / WY / TX)Lightly shaded rubber stamp on Mississippi waiver or post-2022 Texas waiverChecks visual stamp/commission presence in MS and WY (flagging faint seals for review) while honoring Texas HB 2237's statutory notary repeal.Included in statutory check
Password-protected, encrypted, or corrupted PDF exportLocked bank PDF or zero-byte email attachmentBlocked at Stage 01 (pdfValidation.ts) with an explicit HTTP 422 diagnostic before any model call executes.0 credits deducted

Architectural Comparison

Why Split Vision + Deterministic Rules Beats Pure AI & Legacy OCR

Audit RequirementGeneric Chat / Pure LLMLegacy Template OCRWaiverAudit Hybrid Engine
Construction Arithmetic (G702 / G703)Probabilistic token prediction; prone to rounding drift and silent math hallucinations.Brittle regex math that breaks whenever columns shift or change orders sit on Line 2.100% deterministic TypeScript in integer cents (±$0.01) after stripping AI verdicts.
Skewed Smartphone Photos & Low-DPI ScansGuesses obscured digits silently without warning the controller.Fails completely when page rotation or table borders deviate from rigid templates.Multimodal vision extraction + <90 per-field confidence gate forcing amber human review.
12-State Statutory Lien Waiver ComplianceSummarizes legal text loosely; misses repealed statutes like TX HB 2237.Keyword matching only; cannot distinguish conditional vs. unconditional phrasing context.Codified state rule modules (CA, TX, FL, GA, AZ, NV, MI, MS, MO, MA, UT, WY).
Corrupted or Password-Locked FilesConsumes API tokens on garbled bytes or hallucinates empty pass results.Throws opaque parser crashes mid-batch.Pre-flight byte validation returns HTTP 422 immediately with 0 credits deducted.

Technical Architecture FAQ

Does Artificial Intelligence decide whether a pay application passes or fails?

No. WaiverAudit uses AI strictly as a zero-temperature (0.0) optical extractor to turn messy PDFs and jobsite photos into structured JSON fields with 0–100 confidence scores. Immediately after extraction, engine.ts deletes any model-generated status fields and runs deterministic TypeScript modules in integer cents (±$0.01) to compute every math, date, COI, and statutory lien waiver verdict.

How does WaiverAudit handle crooked smartphone photos, low-DPI scans, or handwritten edits?

Multimodal vision reads skewed angles, rotated landscape G703 continuation sheets, and non-standard column headers without brittle x/y templates. If a coffee stain, glare, or handwritten strike-through drops a critical field's confidence below 90, the engine withholds green clearance and highlights that exact field in amber inside the side-by-side review drawer. Confirming or typing an override recalculates all deterministic rules instantaneously.

What happens if a subcontractor uploads a password-protected or corrupted PDF?

Pre-flight byte inspection (pdfValidation.ts) catches encrypted or unreadable PDFs before any AI extraction runs, returning an actionable HTTP 422 error (PDF_PASSWORD_PROTECTED or PDF_CORRUPTED) and deducting zero audit credits.

Are uploaded subcontractor billing packets used to train AI models?

Never. Files upload via TLS 1.3 directly to AES-256 encrypted Cloudflare R2 storage and process over zero-data-retention API routes where model training is contractually and technically disabled.

Drop a skewed pay app or subcontractor binder into the studio.

Includes 3 free full-packet audits on signup — zero credit card required.

Launch Audit Studio