Have you ever tried to extract structured data from hundreds of messy PDF documents? It's a nightmare.

In this post, I want to share a recent project where I built an end-to-end pipeline to extract a (company, period) × 40 fields data panel from 783 real A-share annual report PDFs.

But the real challenge wasn't just extraction—it was verifiability. How do you prove the extracted numbers are actually correct?

Here is how I solved it.

🏗️ The Architecture

The pipeline is designed to be fully reproducible. It goes through several stages:

  1. Cataloging & Page Packing: Handling huge PDF files efficiently.
  2. Extraction: Using PyMuPDF and customized rules to locate tables.
  3. Validation & Quality Gates: The core of the project.
  4. Panel Construction: Merging everything into a tidy dataset.

🛡️ The Core Feature: "Why should anyone trust this table?"

Every data engineer knows that extraction is easy, but data quality is hard. I built three orthogonal validators into the system:

  • Accounting identity checks: Do the numbers add up?
  • Cross-period reconciliation: Measuring the same metric from two independent reports and comparing them.
  • Scope checks: Ensuring the data matches the expected boundaries.

The Quality Gate

I used a quality_rules.yaml file to define pass/fail thresholds. If the pipeline fails a gate, it exits with a non-zero code. This prevents bad data from silently polluting the final dataset.

📊 The Results

To prove the system works, I manually verified 234 measurement points.

The result? The parser achieved 97.12% accuracy (Wilson 95% CI: 93.85%–98.67%).

More importantly, the system knows what it doesn't know. It explicitly rejected 212 abstracts where column counts didn't match, refusing to output bad numbers rather than guessing.

🔗 Open Source

If you are interested in how the pipeline was built, or if you are dealing with similar PDF extraction challenges, the full code and reproducible workflow are available on GitHub.

I'd love to hear your feedback on the cross-period reconciliation design!

👉 GitHub Repo: https://github.com/3254988796aaa-code/annual-report-data-base