Document AI for invoices: schema-first extraction that auditors can trust

Pranjul Rathour
Pranjul Rathour

Originally published at https://pranjulrathour.scult.in/blog/document-ai-invoices-extraction-schema. That copy is the canonical version and gets updates first.

DocuLens AI extracts, compares and checks compliance on invoices and contracts, and every one of those verbs comes with a constraint: the output must be something an auditor can defend. "The AI said so" is not a defence. Schema-first extraction with deterministic scoring is.

Start from the schema, not the prompt

Define the fields you need — vendor, invoice number, dates, line items, totals, tax — with types and rules. The extraction prompt asks for exactly that structure, the response is parsed against it, and anything that fails validation is flagged rather than guessed. The schema is the contract between the model and the rest of the system.

Presenting Annapurna on stage
Presenting Annapurna on stage

Validate with arithmetic, not vibes

  • Line items must sum to the subtotal; subtotal plus tax must equal the total.
  • Dates must parse and be in a plausible order — issue before due.
  • Identifiers must match the format the vendor actually uses.
  • Any field that fails gets a confidence of zero and a visible flag, whatever the model claimed.

Deterministic scoring

Compliance checks — does this contract clause exist, does this invoice match the purchase order — are scored by rules applied to extracted fields, not by asking the model for a verdict. The same document produces the same score every time, which is the property auditors care about most. I made this argument at length in deterministic document extraction.

Compare against the source

Show each extracted value beside the region of the document it came from. Reviewers verify in seconds, corrections become training signal, and trust builds because the system never asks to be believed. This is the document equivalent of citations in RAG answers.

Presenting to a room
Presenting to a room

Architecture notes

DocuLens runs as a single Next.js application with no database and no separate backend — intentionally minimal infrastructure with enterprise-grade code. For a document tool handling sensitive files, fewer moving parts is a security feature. A fast LLM provider does the reading; rules do the judging.

From my carousels
5 Production AI Apps, All Open Source
5 Production AI Apps, All Open Source, slide 15 Production AI Apps, All Open Source, slide 2
5 Production AI Apps, All Open Source, slide 35 Production AI Apps, All Open Source, slide 4
Full carousel on Instagram and LinkedIn.
Pranjul Rathour
Pranjul Rathour
GenAI engineer, Kanpur · 3x first-prize hackathon winner · campus mentor
I ship production RAG pipelines, fine-tune LLMs and build agentic AI products end to end. I lead engineering at SCULT INDIA for a 14-member team and have mentored 200+ students through TechVerse Enclave.
Open to: GenAI roles, hackathon judging, mentorship sessions and guest talks at colleges.
On stage, at hackathons and on campus
Requirements gathering and user flows, on stage
Requirements gathering and user flows, on stage
Presenting KrishGyan, farming advice in your voice and language
Presenting KrishGyan, farming advice in your voice and language
Taking questions during a session
Taking questions during a session

Comments

Popular posts from this blog

Forming a hackathon team: roles, skills and the mistake most teams make

Hello from Kanpur: what I build, and what I'll write about here

I built 15 free tools, 1,211 prompts and a 50,000-skill library — here's what's inside tools.scult.in