Part of the PolicyTrace series

Documents System note

The right words. The wrong driver.

A highlight can quote the right words from the wrong person. A text-match score can't tell the difference; the matcher has to know whose row it is.

Teja Sagiraju · Updated · 5 min read
The short version
• PolicyTrace highlighted the third driver's licence type on the policyholder's row. The words matched; the person didn't.
• A text-match score measures similar words, not the right source. Short labels and repeated values scored as well as the real row.
• I changed how candidates are ranked, not the model. Driver fields now land on their own rows, and five tests keep it that way.

The third driver's licence type was "Full UK". PolicyTrace found those words in the PDF and highlighted them.

But the highlight pointed to the policyholder's row.

The extracted value and the highlighted text agreed. The person did not. A reviewer could see what looked like supporting evidence and approve one driver's details using another driver's row.

This time the value happened to be right: the third driver and the policyholder both hold a full licence, so the wrong row looked like confirmation. The second driver holds a provisional licence. The same mistake on that field would have shown a reviewer a full licence as the evidence for a provisional one.

PolicyTrace reads a UK car insurance policy pack and links every value in its record to the line in the PDF it came from. That link, called provenance, is what's meant to make the record checkable. This failure happened in the code that finds those lines.

For the third driver's relationship, Named Driver, three page items scored 91, 90 and 90. The header was already used, and the Name label on page 1 won the tie over the driver's own row.
Several pieces of text looked like good matches. The matcher needed the right driver, not just similar words.

What the review found

On 17 October I checked every highlight from one run on the synthetic demo pack by hand. The run extracted 59 fields and located 47. That number measures how many fields got a highlight, not how many highlights were right.

Most dates, amounts and identifiers pointed at the expected text, usually the exact words ("15/04/2026 at 00:00 hours", "GBP 395.00"). The driver table was different:

  • The third driver's licence type landed on the policyholder's row. Right words, wrong person.
  • The relationship fields ("Policyholder", "Named Driver") landed on a section heading, a column header or a "Name" label, not on the value.
  • The occupation "Product Manager" landed on a text fragment that just said "Product".

Names got no highlight at all. They're replaced with tokens like MASKED_PERSON_2 before the model sees them, and a token never appears on the page.

Why a good text match wasn't enough

The matcher compares a quote supplied by the model, or the extracted value if there's no quote, with every text item on the page. It uses two fuzzy scorers from the rapidfuzz library, and both rate a short item that sits inside the search text very highly. "Name" is inside "Named Driver"; "Policyholder" is inside "Policyholder details". So a label could score within a point of the real row.

Two rules then picked the winner. On a tie, the earlier item in reading order won, and headings and labels come before table rows. And to stop two fields sharing one box, the matcher preferred positions no other field had used, which pushed a later driver's field onto an unrelated label.

Repeated values made it worse. "Full UK" appears in two driver rows, and "GBP 200.00" four times on one page. Finding the words didn't say whose licence they described.

The review screen also showed the score as a percentage next to each field. That looks like confidence in the answer. It only measures how similar the text is.

What changed

I changed how the candidates above the threshold are ranked, in this order, before the fuzzy score decides:

  1. Does the text contain the value? "Driver name" doesn't contain "Named Driver". The driver's row does.
  2. Is it ordinary text? Items Docling labels as section headings lose.
  3. Is it this driver's row? For driver fields, the item that also holds that driver's other values wins.
  4. Can fields share it? Several fields share one driver row, so a used row no longer loses to an unused heading nearby.

The model stayed the same. On the verification run that evening (17 Oct, after deploying the fix), every driver field landed on its own row. Five tests in tests/test_provenance.py rebuild the demo's driver table and fail on the old code. A field with no good match still says "no source location · check manually" rather than showing a weak guess, and yes/no fields get no highlight at all, because "Yes" matches half the page.

The rule I started from still holds: the model never gives coordinates. Asking a language model for "page 1, x 42, y 18" invites it to make up something plausible. So the work is split three ways:

  • Docling, the PDF parser, owns position. Before any masking, every text element on every page goes into a ProvenanceCorpus with its page and bounding box. Docling measures from the bottom-left in points and the browser draws from the top-left in percent, so _add_prov_item() flips the y axis as it converts.
  • The model owns a quote. Alongside each value, the extraction prompt asks for field_citations: the exact phrase from the document.
  • Code joins them. build_provenance() matches each field's quote, or its value, against every text item in the Schedule, Certificate and Statement of Fact, and ranks the candidates as above.

What reaches the screen is a small FieldProvenance object: the field, the value, the matched text, a match score, the file, the page and a box.

Limits

  • Located still isn't correct. 47 of 59 fields had a highlight on the 17 Oct run (46 on 18 Oct). Neither number says how many highlights point at the value. Counting that properly is on the list.
  • One synthetic pack, one driver-table layout. A table with drivers in a different order on each document would test the row rule properly. Nothing here shows it works on other insurers' layouts.
  • The percentage badge is still on the review screen. Its tooltip says "Citation match score", but it still reads like confidence. Replacing it with what the match actually found (contains the value, same row) is next.
  • The review that follows is thin. Each verify, override or flag is saved in review_state.json keyed by field, so a second action replaces the first, and every reviewer is recorded as "anonymous". That shows the workflow; it isn't an audit trail.

The lesson: a source link has to keep the relationship between a value and whoever it belongs to. Matching the words alone isn't enough.

The decision behind it

  • Decision: the model quotes; code finds the quote on the page, and ranks candidates by whether they contain the value, are ordinary text and sit in the right row before trusting a fuzzy score.
  • Alternative rejected: asking the model for coordinates directly. Plausible-looking numbers with nothing behind them.
  • What it cost: the matcher needs layout-aware rules (headings, rows), and those rules are tuned on one document design.
  • When to revisit: when PolicyTrace meets a second layout, or a scanned pack where positions come from OCR.
Go further
Code: src/provenance.py and its tests on GitHub
Demo: the live demo: click through the driver table yourself
Related: What happens to a PDF inside PolicyTrace · Nothing found isn't the same as nothing checked

How do you check that an AI system's "source" for a value really belongs to that value, and not just to the same words?

First published 17 Oct 2026. Updated 25 Oct 2026: retold around the wrong-driver highlight, with the review-screen badge added to the limits.

Written by Teja Sagiraju

AI engineer with 14 years across machine learning and applied AI: prompt design, document AI, LLM workflows and the review loops that make them safe to ship. I build real systems and write up what breaks along the way.

Connect

Get the next note by email

One short email when something ships or breaks. Free.