Architecture Note · Operations & RevOps
Field-to-LEM Ticket Reconciliation: Deterministic Rate Cards and Supervisor Sign-Off
Why prompting an LLM to draft field invoices drops overtime multipliers and equipment rates—and how a deterministic MSA rate-card engine with state-machine sign-off stops revenue leakage.
The Operational Problem: Silent Margin Leakage Between Truck Roll and ERP
Commercial trades contractors and industrial field teams lose billable revenue in the gap between the job site and the billing desk. Technicians dictate rough voice memos from the cab or circle part numbers in the margins of carbon-copy work orders. Back-office coordinators key in base hours from memory, omitting site lockout standby, after-hours emergency callout fees, specialty skid rates, and refrigerant or backflow consumables. Across six synthetic Calgary service tickets in the Chinook Commercial Trades benchmark, missed standby time, flat-rate overtime errors, equipment class misclassifications, and omitted parts add up to +CA$4,315.50 in unbilled revenue—including +CA$1,515.00 on a single boiler flush where a hydro-jetter skid (CA$215/hr) was billed at the standard service van rate (CA$45/hr).
Why Naive AI Wrappers Fail on Field Tickets
Dropping raw audio transcripts or receipt photos into a general-purpose cloud prompt creates four operational failures:
- Nondeterministic rate-card math: Unconstrained language models regularly apply 1.0x straight time to
21:00–02:00switchgear callouts instead of the contracted 1.5x Master Service Agreement (MSA) multiplier, or hallucinate unit prices that contradict signed client schedules. - Unanchored line items: When an AI summary invents a combined labour line without tying back to the exact spoken phrase or handwritten margin note, operations supervisors reject the draft and re-listen to the entire recording.
- Uncontrolled ERP writes and data egress: Shipping customer addresses, work-order IDs, and internal MSA pricing to external endpoints leaks commercial terms, while auto-exporting unverified tickets into QuickBooks, Xero, or OpenInvoice triggers client disputes and credit memos.
The Deterministic Architecture That Fixes It
Production field-to-LEM reconciliation separates unstructured media extraction from deterministic commercial pricing and enforces a strict approval state machine before any accounting export occurs.
- Private speech and OCR extraction with offline fallback: In the Tier 2 FastAPI + SQLite architecture (
app/ai_adapter.py), uploaded field audio (.webm,.wav,.m4a), slip images, or text notes run through a provider-agnostic Whisper + structured-JSON extractor with an automatic deterministic offline mode when no external key is configured. Every extracted adjustment retains its source cue link—mapping highlighted transcript phrases or OCR slip margin callouts directly to specific Labour, Equipment, and Materials (L/E/M) rows. - Deterministic MSA rate-card engine: Pricing calculations never rely on LLM arithmetic. The reconciler (
app/reconciler.py) evaluates extracted cues against versioned SQLite rate schedules—such asMSA-CHINOOK-TRADES-2026-AB—to catch unbilled crew and lift standby (MSA §4.3), 1.5x after-hours OT plus dispatch rig fees (MSA §3.2), unit-class downgrades (MSA §2.4), and omitted consumables. - Mandatory supervisor sign-off state machine: Every ticket moves through
draft -> needs_review -> approved -> exported. Editing any quantity, rate, or inclusion toggle automatically invalidates prior approval and resets the ticket toneeds_review. Accounting exports for QuickBooks CSV, Xero CSV (mappingL->200,E->210,M->220with5%GST), and OpenInvoice LEM CSV fail closed with HTTP409 Conflictuntil a named supervisor confirms sign-off. - Scoped invite tokens, inbound-only webhooks, and 1-hour media wipe: Access uses expiring SHA-256 invite tokens with atomic per-token rate limits, WhatsApp Business Cloud API intake enforces HMAC-SHA256 signature verification (failing closed on
503), and a background reaper purges uploaded raw field media and expired session tickets after 3,600 seconds while preserving rate cards.
Operational Takeaway
Field billing accuracy improves when speech-to-text and OCR act purely as cue extractors feeding an explicit MSA rate table. By binding every recovered dollar to a clickable source phrase, gating ERP exports behind supervisor sign-off, and purging raw media after one hour, service teams close billing leaks without surrendering financial control.