Three things that lie
A title-research application I run for an abstractor keeps a document database of scanned county records: deeds, leases, wills, land books. Each is a PDF with OCR text, filed under a county, a book type, a book and a page. Documents come in from a courthouse capture workflow, and an hourly import adds them.
Every serious data bug this database has had shared one shape: confidently wrong, invisibly. A held deed reported as not held. A counter of 508 "unparsed" files that turned out to hold 112 real documents the filename parser did not know how to read. And about forty percent of the rows under doubt about their county, because the hourly import labelled everything with one default county. None of it looked broken. Each one was found by luck.
The common cause is that the import trusts three things that are only claims: the filename, the batch label, and the county default. The OCR text is the document. Where they disagree, the text should win. Where the text is silent, nothing should change. That sentence is the whole design.
A daily job instead of a cleaner import
I could have fixed the import and moved on. The next batch would
have carried a new kind of mislabel, and I would have found it the
same way, by luck, months later. So I wrote a reconcile job that
reads the whole table against its evidence every morning at 06:45,
reports what it finds, and applies only the corrections that are
safe without a person. It is report-only by default. The daemon
passes --apply. Four checks.
Check one: the filed county against the text
The job counts county names in the first 20,000 characters of each document's text. Full documents run to exhibits that recite other counties' deeds; the operative clauses and the clerk's stamps live early. Only counties on a fixed list for the abstractor's working area count at all, so OCR noise cannot invent a county. Then a verdict:
- keep: the filed county appears at least once.
- flip: the filed county appears nowhere, and exactly one other county appears, at least twice.
- review: anything weaker. Reported, never touched.
- unknown: no county name at all. Nothing changes.
def county_verdict(filed: str, text: str) -> Tuple[str, Optional[str]]:
counts = county_mentions((text or "")[:_COUNTY_SCAN_CHARS])
if not counts:
return ("unknown", None)
filed = (filed or "").upper()
if counts.get(filed):
return ("keep", None)
others = {c: n for c, n in counts.items() if c != filed}
strong = [c for c, n in others.items() if n >= 2]
if len(strong) == 1 and len(others) == 1:
return ("flip", strong[0])
return ("review", max(others, key=others.get) if others else None)
The bar for a flip is deliberately high. A single stray mention, an adjoining-lands recital or an exhibit, can never move a row. A flip is still not automatic. First the job asks whether a row for the same book and page already exists under the proposed county. If it does, the pair goes on a collision list for a human to merge; two rows for one instrument is a worse state than one row in the wrong county. If not, the document's folder in the image library moves with the row, so the page images stay reachable. If that folder is already occupied, that is a collision too. Only then does the row change, and the full-text index is resynced for it.
Check two: page spans
A document's page range matters because a citation to page 412 has to resolve to the instrument that starts on 412, not the one that happens to be indexed there. Some spans were recorded from capture filenames, which is a claim. When the text names the start page, the span is promoted to OCR-confirmed. When the text contradicts it, the span is cleared and the row falls back to matching on its key alone, which is the safe floor. A wrong span resolves a citation to the wrong instrument; no span resolves it loosely.
Check three: coverage
The capture directory on disk is compared against the table. A file whose name is shaped like a citation but fails to parse means the parser is missing a document series again. A file that parses but has no row means an import gap. Both are lists in the morning report, by filename.
Check four: counters with deltas
Total documents, rows in the full-text index, rows with text, rows a human has verified, spans by source, and a per-county breakdown. Each is logged with its change since the previous run, from a small state file the job writes at the end. A stall or a jump is visible in one line, which is the point. A counter that only shows a total hides the day it stopped moving.
The first morning
I took a database backup, then ran it with --apply. It
corrected 319 counties. The per-county distribution before and
after:
| County | Before | After |
|---|---|---|
| The import's default county | 1,130 | 811 |
| Second county | 82 | 250 |
| Third county | 145 | 274 |
| Three counties with no rows before | 0 | 20, 1 and 1 |
I spot-checked the evidence behind a sample of the flips. The proposed county was named between three and twelve times in each document; the filed county was named zero times. Every row in the sample had come in through the same bulk-import path, which is the one that applies the default.
It also produced two worklists it did not act on. About 123 rows are flagged for review, where the text leans toward another county but not strongly enough. And 97 collisions: the same citation exists under both counties, because the bulk import had created a default-county duplicate of a row that a case had already filed correctly. Those need a human to merge, and they are the largest remaining data-quality item. The coverage check found two document series the filename parser had never heard of, a report of sale and a surety bond, plus a variant of the page-range syntax with a single trailing number. The parser was missing a series again, exactly the failure the check was written for.
What I would tell someone building one
- Decide what the evidence is. Here it is the document's own text. Labels, filenames and defaults are claims about it.
- Set the auto-fix bar high enough that you would defend every change without looking. Filed county absent, one alternative, named at least twice. Everything weaker goes to a list.
- Check for a collision before you move anything. Two rows for one record is worse than one wrong row.
- Move the attachments with the row, and treat an occupied destination as a collision too.
- Report-only by default. The daemon opts in to applying.
- Log counters with deltas. The absence of movement is the signal you will otherwise miss.
- Back up before the first apply. Mine moved 319 rows in one pass; a wrong rule would have moved 319 rows the wrong way just as quietly.