Skip to content

Technical assessment3 to 8 November 2026

DocIntel

An AI document intelligence system that reads invoices and checks them before anything is accepted.

Live demo, built as a technical assessment. The API sleeps on a free tier, so the first load may take a minute.

Problem

Reading an invoice is only part of the task. DocIntel keeps the source text behind each extracted value and checks line sums, dates, evidence and duplicates before anything is accepted.

System study

Documents enter a PostgreSQL job queue. Digital text is read directly, while weak scans and phone photos pass through OpenCV and Tesseract, with Gemini vision as a fallback for low-confidence pages. Gemini structured output extracts fields and line items. Python checks the arithmetic, stores the values with their confidence and source text, and sends failures to a review queue.

DocIntel document pipelineA document enters the PostgreSQL job queue, then follows digital text extraction or OpenCV and Tesseract reading with a Gemini vision fallback for low-confidence pages. Gemini structured output sends fields and line items to validation rules. Passing values are stored with their confidence and source text, while failures enter a review queue.Document pipelineDocInteldocumentPDF, scan, photo, TIFF,Excel, CSVlow confidencepassesfailssource text kept with eachvaluethe model reads, Python doesthe arithmeticPostgreSQL jobqueuerow locking, retries,stale-job recoverytext layerdigitaldocumentsOpenCV andTesseractweak scansand photosGeminivisionfallbacklow-confidencepagesGemini structuredoutputfields and lineitemsvalidation rulesexact decimalarithmeticPostgreSQLand pgvectorvalue,confidence,source textreview queuefails a rule
Fig. 1. DocIntel's document reading, structured extraction and validation, with failures sent to review.

What was built

  1. Invoice processing for digital and scanned PDFs, phone photos, TIFF, Excel and CSV. Gemini structured output extracts nine fields and line items, keeping each value with its confidence score and source text.

  2. Eleven validation rules in exact decimal arithmetic check line sums, quantity times price, subtotal plus tax, dates, confidence, evidence and duplicates. Fuzzy supplier matching uses pg_trgm, and failed rules send the document to review.

  3. A PostgreSQL job queue with row locking, heartbeats, retries with backoff and stale-job recovery, so processing survives restarts on free hosting.

  4. OpenCV cleanup and Tesseract for weak scans and phone photos, with a Gemini vision fallback for low-confidence pages.

  5. PDF-to-PDF and PDF-to-Excel reconciliation, plus hybrid search combining full-text search with pgvector meaning search.

  6. Accuracy evaluation with real models on labelled data in GitHub Actions, with weak spots and synthetic-data limits recorded in the repository.

  7. A storage failure on the deployed demo diagnosed from server logs. Supabase Storage needed an Authorization header that the test fake had not enforced. The fix made the fake enforce the real service's rules.

Architecture

API
FastAPI on Python 3.12, hosted on Render, with Pydantic v2, SQLAlchemy 2.0 and Alembic.
Frontend
Next.js, TypeScript and Tailwind CSS, hosted on Vercel.
Storage
Supabase Postgres and private file storage. Each value keeps its confidence and source text.
Queue
A PostgreSQL job queue with FOR UPDATE SKIP LOCKED, row locking, retries and stale-job recovery.
Reading
PyMuPDF, OpenCV and Tesseract OCR, with Gemini vision for low-confidence pages.
Extraction
Gemini structured output for fields and line items. Python performs exact decimal validation outside the model.
Search and matching
Hybrid full-text and pgvector meaning search, with pg_trgm for fuzzy supplier matching.

Key decisions

  1. A Postgres job queue instead of Redis, because the free hosting can restart.

  2. The model reads the document. Python performs the arithmetic.

  3. Test fakes must enforce the real service's rules, including the storage service's Authorization header.

  4. A fake model checks the plumbing. The real model measures extraction accuracy.

Evidence

  1. All eight evaluated fields correct on 91 of 91 synthetic invoices in run 5, with every planted validation error caught and no failed documents.

  2. Phone photos in the labelled synthetic evaluation reached 87.5% of fields in run 8.

  3. 428 automated tests in CI at 96% coverage, with more than 80 recorded design decisions.

  4. About USD 0.0015 per invoice at paid Gemini prices, from the evaluation report.

Screenshots

DocIntel document page showing a synthetic invoice's extracted fields, each with its confidence and source quote, beside the highlighted source text.
Document page, synthetic invoices.
DocIntel review queue showing synthetic invoices flagged by validation rules, each with its problem and Open and fix or Approve buttons.
Review queue, synthetic invoices.

Technology

  • FastAPI (Python 3.12)
  • Pydantic v2
  • SQLAlchemy 2.0
  • Alembic
  • PostgreSQL job queue (FOR UPDATE SKIP LOCKED)
  • PyMuPDF
  • OpenCV
  • Tesseract OCR
  • Google Gemini (structured output, vision, embeddings)
  • pgvector
  • pg_trgm
  • Next.js
  • TypeScript
  • Tailwind CSS
  • Supabase (Postgres and private storage)
  • Docker
  • GitHub Actions CI with gitleaks

Deployed on Render and Vercel.

Limitations and status

The evaluation uses synthetic invoices. Its results do not establish accuracy on invoices outside that dataset, and the repository records the weak spots.

The API sleeps on Render's free tier. The first load of the live demo may take a minute.

Built in five days as a technical assessment for an AI Engineer role, with Claude Code cloud sessions driven by Sowan's written specifications and decisions.