Back to Projects
QA Engineering / Test Automation

Automated PDF Compliance Test Harness

A two-check validation harness that tests generated PDF letters against layout and content rules, with per-file failure reasons and a colour-coded Excel report.

TEST HARNESS - FINAL ACCURACY REPORT
GROUND TRUTH    Known-good: 210    Known-defective: 90    Total: 300
VALID → PASS   210 / 210   (good → PASS)
DEFECTIVE → FAIL90 / 90    (bad → FAIL)
DEFECTIVE → PASS0        (bad → PASS)
VALID → FAIL   0        (good → FAIL)
OVERALL         300 / 300 AGREE WITH GROUND TRUTH (SYNTHETIC)
Type
Test Automation / QA Engineering
Domain
Document Compliance
Methods
PDF parsing, regex validation, ground-truth testing
Test Corpus
300 synthetic letters - 210 valid, 90 with one seeded defect

The Challenge

The harness's pass/fail verdicts matched the known answer for all 300 letters in a synthetic test corpus, with a specific reason logged for every failure.

Automated document generation can drift from its specification without raising an error: a missing field, a broken layout, a lost bold line. The question is not whether documents were generated, but whether they are compliant, and that needs a harness that defines compliance precisely, runs deterministically and reports at file level.

Why this matters in regulated settings: in financial services, insurance and legal work, document compliance is an audit obligation, and manual spot checks do not scale.

Why this matters for regulated environments: In financial services, insurance, and legal contexts, document compliance is not a cosmetic concern - it is an audit and regulatory obligation. Manual spot-checking at volume is statistically insufficient. Automated harnesses with quantified false-positive and false-negative rates are the only defensible approach.

Approach

01
Ground-truth corpus
Generated 300 synthetic letters: 210 valid and 90 with one seeded defect each (missing salutation, wrong weather lines, missing bold line, missing company line or missing date). A known answer for every file is what makes accuracy measurable.
02
Layout check
PyMuPDF extracts text-line positions and asserts ten lines at the specified 10.8 pt spacing, logging the exact reason when a letter fails.
03
Content check
Ordered regex rules for company, address, phone, website, date, order number, property line, salutation, two weather lines and bold formatting.
04
Reporting
Colour-coded Excel workbook (green PASS, red FAIL), per-file text reports, an executive summary and an accuracy report against ground truth.

Results

300 / 300
Overall verdicts matching ground truth, reproduced in three runs
210
Valid letters passed
90
Defective letters failed, each with a logged reason

Every letter failed by the layout check was also failed by the content check: the layout check only fires when a defect removes a line, so it acts as a secondary safeguard rather than an independent detector.

Read with care: the corpus and the rules come from the same specification and only five defect types are seeded, so full agreement is expected by construction. It shows the harness works as designed, not how it would perform on real-world drift. An early version reported every later field as missing once one field was absent; this was fixed so that per-file reasons point to the actual defect.

Relevance to Production Contexts

The same pattern, parse, assert and report, applies to any document type whose rules can be written down: regulated notices, certificates, contracts or automated correspondence. Moving to production would mean testing against real generated output, adding defect types seen in practice and tracking false-alarm rates over time.

How it was tested

TEST REPORTTEST REPORTPDF HARNESSPDF HARNESS
Checked
  • 300 synthetic letters with a known answer for each: 210 valid, 90 with one seeded defect.
  • Verdicts matched ground truth for all 300, reproduced in three runs.
Found and fixed
  • An early version reported every later field as missing once one field was absent. It was fixed so that per-file reasons point to the actual defect.
  • The layout check only fires when a defect removes a line, so it acts as a secondary safeguard rather than an independent detector.
Limits
  • The corpus and the rules come from the same specification and only five defect types are seeded, so full agreement is expected by construction.
  • Not yet tested against real generated output or real-world drift.

Technology Stack

Python ReportLab PyMuPDF (fitz) regex pandas openpyxl Graphviz logging
Need document compliance testing or QA automation?