DEV Community

Cover image for PDF invoice extraction: keep real zeros and review missing fields
Derek
Derek

Posted on Fully Autonomous

PDF invoice extraction: keep real zeros and review missing fields

An invoice has a date and a total, but no due date comes back from your extractor. Adding 30 days to the invoice date would invent a payment term. Before any reminder or payment is scheduled, the workflow needs to know what the invoice actually says.

Give the reviewer a reason to look

Save the raw value, the normalized value if you have one, and the reason for review. A missing field, an empty string, and a real zero should stay distinct throughout the workflow.

What you know What to do
Nobody has checked the source Leave the field unverified and send it for a source check.
The source gives no due date Record it as unspecified; leave the payment date unset.
The date is visible but the extractor missed it Ask the reviewer to confirm the value against the source.
The invoice gives two conflicting dates Keep both dates and their locations for review.

Inspect the value and the source together

In ComPDF Intelligent Document Extraction, request the fields your workflow needs. If you're building a payment review queue, start with the invoice number, amount due, and due date. Request source grounding where supported, and attach the page reference when the response includes one. Without a location, give the reviewer the original PDF to check.

On one synthetic invoice, a layout extraction request returned INV-711 and USD 0.00, both located on page 1. The invoice didn't give a purchase order number; that field returned an empty string and an empty bboxes array. The response structure guide explains the value and grounding fields.

Layout response excerpt: USD 0.00 on page 1; empty purchase order has no bounding boxes

Values and source references from one layout extraction result. An empty field on a different invoice still needs a source check.

Avoid a truthiness check on the normalized amount. Once parsed, 0 is a legitimate number; a JavaScript expression such as amount || null would erase it. The review reasons in the table are decisions made by the application or a reviewer; they don't come back as statuses from the extraction API.

Test the review queue with four short invoices

Use fictional data. Put each sample on a separate one-page PDF. For B, first omit the due date from a mocked response so you can reproduce the missed-field case on demand. Run a separate pass against real PDFs to see what your extractor actually returns.

Sample Source text Check in your application
A Due: 2027-03-15 · Amount due: USD 0.00 Keep the date and the zero.
B Due: 2027-03-18 · Amount due: USD 120.00 If the response omits the date, leave it unverified until someone checks the source.
C Amount due: USD 120.00 After checking the source, record that no due date was specified.
D Due: 2027-03-20 · Payment note: due 2027-03-27 Preserve both candidates and ask for a decision.

Before letting the workflow schedule anything, open the review queue. For each unresolved item, check whether the reviewer can see why it was flagged and where to look. If they can't tell the difference between a blank, a missed value, and two conflicting dates, keep that item out of automatic scheduling.

Top comments (4)

Collapse
 
kamalmosadegh profile image
Kamal Mosadegh •

This is the exact failure mode that made me build my own extractor the way I did. The distinction you draw — a missing field, an empty string, and a real zero are three different facts — is the one most tools collapse, and the amount || null example is perfect: a falsy check quietly turns a legitimate $0.00 into "no amount found".

In the PDF tool I built (pdf-slice), I landed on the same design from the other side: when a page comes back thin after both the native-text and OCR routes, it is not returned as an empty result — it is labelled low-confidence with a warning, and cached results are only served after verifying the file hash, so a changed file can never be answered from a stale extract. The reviewer-facing version of that is your table: keep the raw value, the reason for review, and both candidates when two dates conflict, instead of picking one silently.

Your four-invoice test set is a nice touch too — sample D, with the payment note giving a second date, is the case most extractors get wrong by "resolving" the conflict themselves. Do you also keep the bounding boxes with the conflicting dates in the review queue, so the reviewer can see which date came from where without opening the PDF? That grounding is what made the difference for me between a queue people actually trust and one they just click through.

Collapse
 
derek-compdf profile image
Derek •

Thanks, Kamal! I agree with your point about flagging low-confidence results. A reviewer should be able to tell the difference between a field that’s missing from the document and one the extractor couldn’t read reliably.

I tried the synthetic invoice from sample D in the ComPDF demo. With a single due-date field, I got March 20. When I asked for the date on the “Due” line and the date in the payment note as separate fields, I got March 20 and March 27, each with its own bounding box. Clicking each result highlighted the matching line in the PDF.

I’ve only tested this in the demo. In a review queue, I’d show the two source lines side by side so the reviewer can see where each date came from and decide which one to use.

If you’d like to try it yourself: compdf.com/demo/idp/document-extra...

Collapse
 
kamalmosadegh profile image
Kamal Mosadegh •

That demo result is the cleanest demonstration of the point, and it generalises: the schema is where the conflict gets resolved or preserved. Ask for one 'due date' and the extractor is forced to decide for you — it returned March 20 and March 27 silently stopped existing. Ask for the two labelled fields and the same document hands you both, each with its own bounding box. Nothing about the PDF changed; the question did.

Your side-by-side plan for the queue is right. One addition from the reviewer side: keep the value the single-field version would have chosen (March 20) marked as the proposed default, with the second candidate next to it. Reviewers are faster and more accurate confirming or rejecting a proposal than choosing from a blank — and if you log how often they override the default, that override rate becomes the metric that tells you whether the single-field answer can be trusted on the invoices nobody reviews. The one part I'd verify outside the demo is that both boxes survive the trip from API response into the actual queue UI — in my experience that's where grounding usually gets dropped, not in the extraction itself.

Collapse
 
kamalmosadegh profile image
Kamal Mosadegh •

That March 20 / March 27 result is the perfect illustration: the extractor was not wrong, the schema was ambiguous — 'due date' was one field name pointing at two different facts in the document. Splitting the field forced each value to carry its own bounding box and its own confidence, which is what makes review possible. The rule I use: if two values in a document could both answer a field name, the field name is wrong, not the model. One practical addition: when a split field comes back with two different values, flag the pair for review even if both confidences are high. Agreement between related fields is cheap to check, and a silent disagreement is exactly the error that survives into the spreadsheet. Glad the zeros point landed too — a real 0 and a missing field look identical in most CSV exports, and they should not.