Intermediate project
Document AI pipeline
Builds on 1 lessonabout 35 min of reading first
In this project
What you need first
- Completed:Multimodal GenAI and document AIMultimodal and document AI
Skills you will practise
- Document and multimodal AI
Problem
Compare ways of extracting data from PDFs and pick a pipeline using measured accuracy.
Requirements
- 20 PDFs that contain tables.
- A comparison of text extraction, OCR or layout parsing, and a vision-language model.
- Field-level accuracy for each method.
- Page citations.
- Never use a private or confidential document, such as your employer’s files or anyone’s personal records. Use only public, self-made or licensed PDFs and record where each came from and its license.
Prerequisites
Tasks
- To do: Collect 20 PDFs with tables.
- To do: Write the labelled set first: the true value of each field you extract, typed by you from the page, before you run the methods.
- To do: Extract with three methods.
- To do: Measure field accuracy for each.
- To do: Record seconds per page and, for a hosted model, input and output tokens per page for each method.
- To do: Add page citations to the output.
- To do: Choose a pipeline and say why.
- To do: Design first: draw the flow from PDF to accepted record (three methods, confidence routing, human-review lane, page-citation path) before you code the routing.
- To do: Write a number check for each table (line items add up to the stated total, units are consistent) and run it on every extraction.
- To do: Pick a confidence signal and a threshold. Measure how many fields go to review and how many errors you let through at two or three thresholds.
- To do: Check every page citation by opening the cited page and finding the value.
- To do: Stretch: size the review queue. At your measured review rate, say how many fields per day a person must check for your volume, using minutes per field that you time yourself.
- To do: Stretch: compute cost per 1,000 pages for each method from your own measured time and token counts.
- To do: Stretch: add a second document class (for example forms next to tables) and report which method changes.
Evaluation
Record real measurements and never invent numbers. The finished project should give you: parsing-quality insight and table handling.
| Criterion | 0 | 1 | 2 | 3 |
|---|---|---|---|---|
| Field accuracy per method, with sample size | Not measured | One method measured, or no sample size | All three methods on 20 PDFs with tables, exact or normalised match per field against a labelled set written before the runs, with the number of fields | As level 2, split by field type (text, number, table cell) with the errors listed |
| Table handling | Tables flattened and not checked | Tables extracted, not checked | Table structure checked and numbers verified by code | As level 2, with the failures grouped (merged cells, units, spanning rows) and one fix re-measured |
| Citations verified | No citations | Citations present, not checked | Every cited page opened and checked | As level 2, with the wrong or missing citations counted and explained |
| Confidence threshold chosen with a measured trade-off | No threshold | A threshold picked by feel | The routing flow drawn before coding it, and review rate and missed-error rate measured at two or more thresholds | As level 2, with the chosen threshold justified by the measured numbers |
| Decision memo | None | A choice with no evidence | A choice that cites your accuracy and the seconds and tokens per page you measured for each method | A one-page memo that names what you rejected, what would change your mind, and what the review lane costs |
Pass mark: at least 2 on every criterion (so the lowest passing total is 10 of 15).
Architecture
In production you would route each page to one method (cheap first, expensive only for hard pages). In this project you run all three on every page so you can compare them.
| Decision | Alternative rejected | Why |
|---|---|---|
| Compare all three methods on the same labelled pages | Pick the most capable method up front | More capable is not the same as exact; a vision model can read a cell and still produce a plausible wrong number. Only your own labelled pages tell you. |
| Validate numbers in code | Trust the extraction | Line items that do not add to the total are a free, exact signal that something was misread. |
| Route low-confidence fields to a person | Accept everything automatically, or review everything | Auto-accept lets errors through. Reviewing everything costs more than the extraction. The threshold sets the balance, so measure it. |
| Keep the page number with every field | Cite the document only | A page citation can be checked in seconds; a document-level one cannot. |
Deployment
Keep this short. Everything below is a design note you test on your 20 PDFs, and you supply the numbers.
- Batching. Process documents in batches, key each result by document id and page so a re-run replaces rather than duplicates, and retry a failed page without redoing the batch.
- Cost per page. Measure it for each method: seconds per page, and for a hosted model the input and output tokens per page multiplied by the price you look up on the day you run. Prices change, so write the date next to the number.
- OCR failure handling. Decide what counts as a failed read (empty text, very few characters for a full page, garbled output, a number check that fails). A failed page goes to a stronger method or to review. It is never accepted silently.
Interview questions
Provenance: Generated practice. Not reported from any company.
- Users report wrong numbers from tables in PDFs. Where do you look first, and how do you fix it? Practise with question 44 in the Top 100 priority questions.
- How do you build a labelled set and decide a pipeline change helped? Practise with question 51 in the Top 100 priority questions.
- Design ingestion for documents that arrive in large batches and sometimes fail. Practise with P9 in the Product-company bank.
Portfolio checklist
- To do: The README lists each PDF’s source and license, and contains no one’s private documents.
- To do: The labelled set and the accuracy table (per method, with sample size) are in the repository.
- To do: The flow diagram shows confidence routing and the review lane.
- To do: The threshold chart or table and the decision memo are included.