Intermediate project

Document AI pipeline

Builds on 1 lessonabout 35 min of reading first

In this project

What you need first

Skills you will practise

  • Document and multimodal AI
Skip to the tasks

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.

Criterion0123
Field accuracy per method, with sample sizeNot measuredOne method measured, or no sample sizeAll 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 fieldsAs level 2, split by field type (text, number, table cell) with the errors listed
Table handlingTables flattened and not checkedTables extracted, not checkedTable structure checked and numbers verified by codeAs level 2, with the failures grouped (merged cells, units, spanning rows) and one fix re-measured
Citations verifiedNo citationsCitations present, not checkedEvery cited page opened and checkedAs level 2, with the wrong or missing citations counted and explained
Confidence threshold chosen with a measured trade-offNo thresholdA threshold picked by feelThe routing flow drawn before coding it, and review rate and missed-error rate measured at two or more thresholdsAs level 2, with the chosen threshold justified by the measured numbers
Decision memoNoneA choice with no evidenceA choice that cites your accuracy and the seconds and tokens per page you measured for each methodA 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

Diagram: Each page is read by the three methods you are comparing, and every result is normalised to fields that carry a page number.

passes and above threshold

fails or below threshold

PDF page

Text-layer extraction

OCR and layout analysis

Vision-language model

Normalise to fields with page number

Number checks and confidence signal

Accepted record with page citation

Human review queue

Diagram summary: Each page is read by the three methods you are comparing, and every result is normalised to fields that carry a page number. Number checks and a confidence signal then route each field: accepted with its page citation, or sent to a human review queue whose corrected value joins the accepted records.

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.

DecisionAlternative rejectedWhy
Compare all three methods on the same labelled pagesPick the most capable method up frontMore 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 codeTrust the extractionLine items that do not add to the total are a free, exact signal that something was misread.
Route low-confidence fields to a personAccept everything automatically, or review everythingAuto-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 fieldCite the document onlyA 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.