Document intelligence · Open source

Document-Parser

Turning a scanned judgment into structured, citable sections — and keeping the parts that must be correct deterministic.

Role
Architecture, implementation, benchmark
Client
Open source · Fenvolt
Status
Completed · 2026
Delivery
Repository + API
Fig. 03 — parsing pipelineSeven phases
  1. 01

    Triage

    File type, text layer and language are read before a parser is chosen.

  2. 02

    Layout

    DocLayout-YOLO separates headings, body, tables and footnotes.

  3. 03

    OCR routing

    Local OCR first; cloud or vision model only where quality demands it.

  4. 04

    Section tagging

    A model assigns semantic sections; every block keeps its page number.

  5. 05

    Metadata

    Case number, parties, dates and citations extracted to a typed schema.

  6. 06

    Citation graph

    Deterministic regex extraction. No model in the loop for citations.

  7. 07

    Correction

    Five detectors re-check structure, anchors and citation validity.

Failed check returns to 03Deterministic citation graph

01Context

Legal parsing is a structure problem.

Most PDF libraries return a stream of text. That is enough to search a document and not enough to know that a paragraph belongs to a section, that a footnote is not body text, or that a citation appeared inside a heading.

For legal work, those distinctions are the document. A parser that loses them forces every downstream stage to guess.

02Problem

Why a generic parser fails here.

  • Layout

    Tables, footnotes, numbering and bilingual pages in one file.

  • OCR variance

    A local engine is cheap but uneven; cloud models are better and slower. Neither is right for every page.

  • Citations

    They must be extracted deterministically. A hallucinated citation is worse than a missing one.

  • Benchmarks

    Most parser comparisons are informal. A claim about accuracy needs a diff.

03Architecture

Seven phases, one correction loop.

Each phase is a module with its own tests. Triage decides what the document is; layout extraction separates blocks; OCR routing chooses local or cloud per page; section tagging and metadata extraction use a model. The citation graph does not.

Fig. 03 — parsing pipelineSeven phases
  1. 01

    Triage

    File type, text layer and language are read before a parser is chosen.

  2. 02

    Layout

    DocLayout-YOLO separates headings, body, tables and footnotes.

  3. 03

    OCR routing

    Local OCR first; cloud or vision model only where quality demands it.

  4. 04

    Section tagging

    A model assigns semantic sections; every block keeps its page number.

  5. 05

    Metadata

    Case number, parties, dates and citations extracted to a typed schema.

  6. 06

    Citation graph

    Deterministic regex extraction. No model in the loop for citations.

  7. 07

    Correction

    Five detectors re-check structure, anchors and citation validity.

Failed check returns to 03Deterministic citation graph

04Determinism

Regex, not a model.

The citation graph is built with deterministic pattern matching. That is a deliberate constraint: a citation is the one thing in a legal document that must never be invented.

A model may propose a section boundary. It does not get to propose a case citation.

05Correction

Five detectors, one return path.

A self-correction pass re-checks structure, page anchors and citation validity. If a check fails, the document returns to OCR routing instead of being accepted with a warning attached.

This is the difference between a pipeline that fails loudly and one that produces plausible output from a broken page.

06Benchmark

Read the diff, not the claim.

The parser was benchmarked against LlamaParse and Reducto on a real court judgment, with the structural diff published alongside the code. The comparison is included so the result can be inspected rather than taken on trust.

It ships with offline tests, an async FastAPI job API and signed webhooks for job completion, so it can run as a service rather than a notebook.

07Delivery

Shipped open source, with the evidence.

The pipeline, the benchmark and the tests are in the public repository, alongside the structural diff against LlamaParse and Reducto. If you are evaluating parsers for legal or bilingual documents, you can re-run the comparison rather than trust a summary.

Stack

  • Python
  • PyMuPDF
  • DocLayout-YOLO
  • Tesseract
  • FastAPI
  • PostgreSQL
  • Docker
github.com/FaizanCyber007/Document-Parser

Role — Architecture, implementation, benchmark design

Next study

OpsNexus

Agent systems · Operations

Have a corpus that
refuses to behave?

Describe the documents, the volume and what a correct answer looks like. We will tell you whether retrieval is the right tool before proposing a build.

Start a project