A Razorpay merchant ends the month with two lists. What they sold, and what actually landed in the bank. Someone has to check every line. By hand, in a spreadsheet, about half the lines match at first glance.
I built Ledger Sentinel to do that check. It reconciles orders against settlements automatically. On the synthetic demo data, 80.3% of lines auto-match. The rest go to a human with a note attached.
The design rule I stuck to: deterministic first, AI last.
Matching is exact math. For each order I compute net_expected = amount - MDR - GST, then compare it to amount_settled with a tolerance of Rs 0.01. That tolerance matters. Three planted rounding cases auto-match because of it, where a plain == would have flagged them as exceptions. Floating point noise is not a business problem, so I do not treat it like one.
What does not match becomes an exception with a reason: expected_tds_withholding, late_authorization_flip, missing_settlement, missing_order. Only the exceptions reach the AI, and all it does is write a one-line note. "This looks like a tax cut, likely okay." "Payment shows as failed but money still came, late update." The AI never reconciles anything and never touches money. A fixed policy decides what happens next: approve, step up, review, block.
The webhook side is the part I am proudest of, because it is the part nobody sees. Every incoming webhook gets its HMAC-SHA256 signature verified on the raw body, with a constant-time compare. event_id is the primary key, so a duplicate delivery is skipped instead of double-counted. And the order state machine only moves forward. A captured order can never slide back to authorized because a late webhook arrived out of order.
Every outcome gets an audit_log row. 61 reconciled rows in the demo produced 240 audit rows, because applied, duplicate_skipped, rejected, matched and exception all get logged. If a number is ever questioned, the trail is there.
The defense layer sits on top. A rolling-window spike detector flags fraud_rate jumps above mean + 2 sigma, weighted 25x against false negatives, because missing a real spike costs more than a false alarm. The chargeback responder compiles an evidence pack, orders plus settlement plus webhook log plus UTR, but only as a draft. A human files it.
43 tests, all passing. The number I actually care about is 80.3%. That is the share of lines nobody has to look at. The AI explanations are nice. The boring deterministic part is what does the work.
Repo: https://github.com/abiralpokhrel-learns/ledger-sentinel
