DEV Community

Cover image for LedgerLeaf: Turn Messy Receipts into Structured Records with Local AI
Pankaj Garg
Pankaj Garg

Posted on

LedgerLeaf: Turn Messy Receipts into Structured Records with Local AI

Hacktoberfest Open-Source AI Challenge Week 2: Side Hustle Submission đź’¸

This is a submission for the Hacktoberfest Open-Source AI Challenge Week 2: Side Hustle

What I Built
LedgerLeaf is a private, local-first financial paperwork assistant designed for freelancers, independent contractors, and small business owners who drown in disorganized receipts and invoices each tax season.

Instead of sending confidential financial records, bank details, and client invoices to third-party cloud extraction APIs or paying recurring monthly subscription fees for SaaS document processors, LedgerLeaf performs end-to-end receipt extraction on your own device. It combines local open-weight vision/language models (via LM Studio or Ollama) with deterministic math verification guards. Every single extracted number visually highlights back to the exact source snippet on the uploaded invoice, and nothing enters your persistent ledger without your explicit human approval.

Demo
LedgerLeaf runs locally on your machine with a leaf-inspired interactive review bench:

Interactive Interface: Dual-pane review workspace with live source-text pinning, field corrections, and duplicate detection.
Review Bench in Action:
Drop in receipts or invoices (.pdf, .png, .jpg, .webp, .txt).
The local open-weight model parses vendor, invoice number, date, currency, subtotal, tax, and total.
Deterministic guards verify subtotal + tax == total. Any mismatch or unverified field is flagged for quick correction.
One click commits verified records to a local SQLite database and exports clean, multi-currency RFC 4180 CSVs.
(To add your video demonstration here: paste your YouTube, Loom, or MP4 link directly below without extra spacing)

GitHub logo Garg-Pankaj29 / LedgerLeaf

LedgerLeaf is a private, local-first financial assistant that turns receipts and invoices into structured records using open-weight AI on your machine. Featuring source provenance, deterministic math guards, and human approval before committing to your SQLite ledger—zero cloud dependencies.

LedgerLeaf — Your finances. Your files. Your AI.

LedgerLeaf is a local-first, privacy-respecting financial document processing application that turns receipts, invoices, and paperwork into structured accounting records on your own machine. Every number points directly back to the line it came from in the original document, and nothing enters your approved ledger until you explicitly review and verify it.


1. Core Principles & Philosophy

  1. Local-First & Private by Default: All text extraction, OCR, database storage, and AI inference run locally on 127.0.0.1. Uploaded files are stored in data/uploads/ outside the web directory. Documents never leave your computer unless you explicitly export CSV data or configure an external integration.
  2. Deterministic Arithmetic Guards: Local models can misread numbers or make arithmetic mistakes. The AI model proposes structured values; deterministic validation rules cross-check math (subtotal + tax == total), dates, and required fields; and a human approves before anything enters…

Code
The entire codebase is open-source under the MIT License:

GitHub logo Garg-Pankaj29 / LedgerLeaf

LedgerLeaf is a private, local-first financial assistant that turns receipts and invoices into structured records using open-weight AI on your machine. Featuring source provenance, deterministic math guards, and human approval before committing to your SQLite ledger—zero cloud dependencies.

LedgerLeaf — Your finances. Your files. Your AI.

LedgerLeaf is a local-first, privacy-respecting financial document processing application that turns receipts, invoices, and paperwork into structured accounting records on your own machine. Every number points directly back to the line it came from in the original document, and nothing enters your approved ledger until you explicitly review and verify it.


1. Core Principles & Philosophy

  1. Local-First & Private by Default: All text extraction, OCR, database storage, and AI inference run locally on 127.0.0.1. Uploaded files are stored in data/uploads/ outside the web directory. Documents never leave your computer unless you explicitly export CSV data or configure an external integration.
  2. Deterministic Arithmetic Guards: Local models can misread numbers or make arithmetic mistakes. The AI model proposes structured values; deterministic validation rules cross-check math (subtotal + tax == total), dates, and required fields; and a human approves before anything enters…

Tech Stack:

Backend: Python, FastAPI, SQLAlchemy, SQLite, Pydantic v2, PyMuPDF, Tesseract OCR.
Frontend: Vanilla modern JavaScript (ES modules), CSS custom property design system, and HTML5 Canvas.
Local AI Runtime: OpenAI-compatible local inference endpoints (LM Studio / Ollama).
How I Built It
LedgerLeaf is engineered around local-first principles to keep financial documents bounded strictly to 127.0.0.1:

Storage & Extraction Pipeline: Uploaded receipts are validated with MIME/magic-byte checks and hashed via SHA-256 for collision prevention. PyMuPDF extracts text streams, falling back to local OCR for scanned imagery.
Local Open-Weight Inference: The extracted raw text is fed to a locally hosted open-weight LLM (e.g., llama-3.2-1b-instruct or gemma-3-4b) through a local LM Studio server. The prompt enforces a strict JSON schema with field-level confidence ratings and character offsets.
Deterministic Math Guardrails: Small open-weight models can occasionally misread grainy receipt photos or hallucinate digits. LedgerLeaf protects against model drift by passing all outputs through deterministic mathematical validators (abs(subtotal + tax - total) < 0.01). If arithmetic fails or fields are missing, the UI raises visual warning chips.
Source Provenance: Every field maps directly back to the character range where it originated, allowing users to click any number and highlight its source on the original invoice.
Why Does Open Innovation Matter?
Financial documents contain sensitive metadata: personal addresses, tax IDs, client names, banking coordinates, and spending patterns. Closed-source, cloud-only AI APIs force solo operators to either risk their privacy or manually enter every single receipt line by line.

Open innovation and open-weight models flip this trade-off:

True Zero-Data-Leakage: Financial data never crosses the network perimeter or trains external foundation models.
Zero Per-Token or Subscription Costs: Freelancers can run high-volume processing without incurring metered API bills or surprise vendor rate hikes.
Longevity & Independence: Because the app, models, database, and inference harness run completely on-device, the tool will continue working indefinitely without depending on external vendor uptime.
Prize Categories
Open-Source AI Challenge Week 2: Side Hustle
Local & Edge AI

Top comments (0)