Mathi.
← All work

Own project

BillCheck

Invoice extraction where a cheap model goes first and a second model is called only when a deterministic check says the answer is weak.

Next.js 15React 19FastAPISupabaseOpenAIClaudeDocker

The problem

Bills arrive as PDFs, phone photos and Word files with no shared layout. Template-based OCR breaks on every new vendor, and sending every bill to the most capable model is slow and expensive. Indian bills add GST rules that a generic extractor knows nothing about.

My role

Solo build: architecture, extraction pipeline, validation scoring, database security, review UI, tests and CI.

How it works

  1. 01UploadPDF, photo or Word (converted via LibreOffice/Poppler); a content hash blocks duplicates
  2. 02ExtractOpenAI vision model returns structured bill JSON
  3. 03ValidateMoney totals, date sanity and GST rules → a score from 0 to 1
  4. 04FallbackScore below 0.5 → Claude re-extracts; the higher score wins
  5. 05ReviewFlagged fields highlighted; every edit is re-validated and audited

Screens

Bill detail: the original sample invoice on the left, extracted vendor, line items, GST and totals on the right, confidence 90% and a flag on the vendor tax ID
A sample bill beside its extracted data. The validator scored it 90% and flagged the made-up GSTIN, whose check character doesn’t match.
Dashboard showing total spend in INR with a USD toggle, total bills and top vendor
Dashboard: total spend (INR or USD), bill count and top vendor.
Three phone screens: dashboard, bills list with CSV and Excel export, and the upload sheet that accepts photos from the camera
On mobile: dashboard, bills list with export, and camera-friendly upload. Customer names and invoice numbers are redacted.

Key decisions

Validate with code, not with another LLM

The score starts at 1.0. Each hard error (line items don’t sum to the subtotal, the total doesn’t match subtotal + tax − discount + round-off, a missing invoice number, a future date) costs 0.3; each soft flag costs 0.05. Below 0.5, Claude is called. It is cheap, explainable and cannot hallucinate.

GST rules that catch OCR misreads

GSTINs are checked against their built-in check character (a mod-36 Luhn variant), which catches most single-character misreads. CGST must equal SGST, and IGST vs CGST + SGST must match whether vendor and buyer are in the same state. These raise flags rather than errors, so a misread ID never triggers a paid fallback on its own.

Not locked to one AI provider

The primary extractor speaks the OpenAI API, so it can point at Gemini, Groq, OpenRouter or a local Ollama model, and Claude is optional. Every attempt’s model, latency and token counts are stored, so cost and quality can be compared per provider.

Row-level security and an audit trail

Postgres RLS and private storage keep each user’s bills unreachable from another session. When a user corrects a field, the original AI output is kept and the change is written to an audit log.

Outcome