OcrAI
On-premise document extraction: OCR plus a locally hosted LLM turn scanned purchase orders and medical reports into structured data a human confirms.

Purpose
Give an existing enterprise application a self-contained module that reads purchase orders and medical reports and returns structured JSON, with no paid LLM API and no document leaving the customer's infrastructure.
The problem
Scans, photos and digital PDFs of purchase orders and medical reports are typed in by hand. They contain personal data, so sending them to a cloud LLM is not acceptable. Extraction has to run locally, and a person must see which values to doubt.
What I built
- A six-step pipeline: upload, text extraction, field mapping, confidence scoring, human review and JSON export, with explicit document statuses.
- Text extraction that reads digital PDFs directly and runs scanned PDFs and images through Tesseract OCR.
- A local-LLM extraction service: the OCR text goes to an Ollama-hosted model with a prompt per document type (purchase order, medical report) and comes back as JSON.
- A confidence scorer that checks each extracted value against the raw OCR text instead of asking the model how sure it is.
- Field schemas defined once on the server and served by an endpoint, so the Angular review form, with colour-coded confidence and an exceptions page for doubtful fields, is generated from them.
- JWT authentication with a fail-closed default: every endpoint needs a token unless explicitly marked anonymous.
- A single-origin Docker Compose stack (PostgreSQL, Ollama, API, nginx front end) and a native Windows Server deployment guide.
Features
- Upload a PDF or image.
- Digital PDFs are read directly; scanned ones go through OCR.
- Two document types: purchase order (header fields plus line items) and medical report.
- Automatic type detection when no type is given.
- A review page that renders a form with colour-coded confidence.
- An exceptions queue of unconfirmed, low-confidence fields.
- Edit fields and confirm; the document becomes Reviewed once every field is confirmed.
- Export the confirmed data as JSON.
- A documents list, a dashboard, delete, and JWT sign-in.
- Sample purchase-order templates for demos.
Stack
- .NET
- ASP.NET Core
- EF Core
- C#
- PostgreSQL
- Angular
- TypeScript
- Ollama
- Docker
- GitHub Actions
AI in this project
In the product
- A local language model (Ollama, llama3 by default) maps raw OCR text to the field schema as JSON, with a prompt per document type and the instruction not to invent values. No cloud model is used, so document content never leaves the infrastructure and OCR text is never logged.
- When the type is unknown, a second model call returns a single label; an answer that matches no known type becomes Unknown.
- The model's answer is parsed against the schema, numbers are coerced, and an exception marks the document as failed.
- Confidence is not asked from the model: a deterministic check looks for the value in the raw text (exact match, fuzzy match or absent). OCR itself is Tesseract and PdfPig, not an AI service.
- A person always has the last word: every field starts unconfirmed, and edits are marked as manual. Tests replace the model with a stubbed HTTP response.
In how it was built
- 58 of 64 commits carry a Claude co-author trailer.
- A 163-line rule file with a "do not" list steers the assistant (never ask the model for confidence, never log OCR text), and gate scripts check each change.
Key flows
Steps
Review a purchase order
Step 1 of 5: Upload
A user signs in, drops a purchase-order PDF or image and picks the document type.
Step 2 of 5: Extract
The text is read or OCR'd, and the local model returns the fields as JSON.
Step 3 of 5: Score
Every field gets a confidence value by matching it against the OCR text; weak ones are flagged.
Step 4 of 5: Review
The generated form colours the fields by confidence; the reviewer fixes the doubtful ones and confirms.
Step 5 of 5: Export
The confirmed data is downloaded as JSON for the host application.
Limitations
- An MVP: the backend has no automated test project yet, so coverage is not measured.
- Processing is synchronous, so very large documents can hit the proxy timeout; a queue is the planned fix.
- No accuracy benchmark exists, so none is claimed. Quality depends on the chosen local model and the OCR language data.
- Authorisation is coarse (a single role) and upload validation still needs review.
Want something like this?
Tell me about your project — I reply within two working days.
Start a project