How I test contract extraction
Real contracts are confidential, so they cannot be used to test a contract-reading tool in the open. I generate fictional contract stacks that come with an answer key, run extractors over them, and score what comes back against the key. This page reports what I measured, the command behind each number, and what the numbers do not show.
The test set
- 25 fictional contract stacks holding 349 documents: a master agreement with its exhibits, amendments, statements of work, assignments, notices and emails, across six agreement types.
- An answer key for each stack, written by the generator from the facts it started with and never by a model. Every fact in the key points to the file and the character span it came from.
- One to four planted problems in each stack, 67 in all: an amendment signed by one side only, a statement of work whose payment days differ from the master's, a later-signed amendment with an earlier effective date, an exhibit that is cited and never attached. The key records the competing readings and which one a stated house rule picks.
- What the key holds for these stacks: 61 parties, 110 people, 458 obligations, 183 amendment links, 246 links from a new section to the section it replaces, 483 links from a party to a document it signs, and 100 cross-references from a master to an attached exhibit.
The answer keys and the document texts are in docs/results/2026-11/corpus-25. The counts above are read from score-qwen-7b-25.json, which the scoring command below writes.
Three extractors, one scorer
- Pattern rules. Regular expressions, no model. This is the floor.
- qwen-7b. Qwen2.5 7B Instruct, 4-bit, run locally. All 25 stacks.
- mistral-24b. Mistral Small 24B Instruct, 4-bit, run locally. 5 of the stacks.
Both models got the same prompt, one document at a time, at temperature 0, and then one more call over a summary of the whole stack to flag the planted problems. An item counts as right only when it matches the key: the same party, the same document, the same section. F1 is the balance of precision (how much of what was produced is in the key) and recall (how much of the key was produced); 1.00 is perfect.
| Item | In the key | Pattern rules | qwen-7b | qwen-7b, 5 stacks | mistral-24b, 5 stacks |
|---|---|---|---|---|---|
| Parties | 61 | 0.77 | 0.95 | 1.00 | 1.00 |
| People | 110 | 0.51 | 0.93 | 0.93 | 1.00 |
| Obligations (who owes what to whom, in which document) | 458 | 0.31 | 0.56 | 0.57 | 0.61 |
| Amendment amends agreement | 183 | 0.76 | 0.99 | 1.00 | 1.00 |
| New section replaces old section | 246 | 0.00 | 0.29 | 0.27 | 0.29 |
| Person signs document | 479 | 0.60 | 0.99 | 1.00 | 1.00 |
| Party is a party to document | 483 | 0.64 | 0.84 | 0.87 | 0.84 |
| Master cites attached exhibit | 100 | 0.43 | 0.04 | 0.11 | 0.62 |
| Pattern rules | qwen-7b | qwen-7b, 5 stacks | mistral-24b, 5 stacks | |
|---|---|---|---|---|
| Planted problems noticed | 11 of 67 | 56 of 67 | 10 of 12 | 12 of 12 |
| Alarms where nothing was planted | 0 | 94 | 17 | 10 |
| Reading chosen matches the house rule | 0 of 67 | 0 of 67 | 0 of 12 | 0 of 12 |
| Links produced that are not in the key | 0 | 371 | 65 | 72 |
| Links in the key that were missed | 933 | 287 | 52 | 44 |
fabric8r score --truth docs/results/2026-11/corpus-25 --extraction docs/results/2026-11/ext/rules --json docs/results/2026-11/score-rules-25.json, the same with ext/qwen-7b for qwen-7b, and the two-model command in the next section for the last two columns.
What I take from the tables:
- The pattern rules produce no link that is not in the key and miss most of what is there: they find 19% of the obligations and 0% of the section replacements.
- qwen-7b finds far more and invents more: 371 links that are not in the key, against 0 for the rules.
- Which section an amendment replaces is the hard case for both models. An amendment that rewrites two or three sections at once is usually read as changing the wrong ones, or too few.
- qwen-7b noticed 56 of the 67 planted problems and raised 94 alarms where nothing was planted. Noticing is cheap when most things get flagged.
What disagreement between two models tells you
A common shortcut is to run two models and send a person only the items they disagree on. I measured what that catches on the 5 stacks both models read (65 documents, 540 items in the key).
| Items | Not in the key | Share wrong | |
|---|---|---|---|
| Both models produced it | 500 | 65 | 13.0% |
| Only one model produced it | 101 | 67 | 66.3% |
fabric8r study --truth docs/results/2026-11/corpus-25 --a docs/results/2026-11/ext/qwen-7b --b docs/results/2026-11/ext/mistral-24b --json docs/results/2026-11/study-qwen-7b-mistral-24b-5.json
- An item only one model produced was about five times as likely to be wrong as one both produced.
- Disagreement cannot see the errors the two models share. 71 of the 540 items in the key were missed by both, and across documents the amount of disagreement barely tracks the number of shared errors (correlation 0.13).
- So a second model is a useful alarm for what one model invents, and no check at all on a mistake that the same prompt leads both into.
Three failures, traced
Reading the wrong items one by one, three causes account for much of what the tables show.
- Parties attached to documents nobody signs. Both models list the main parties as parties to exhibits, notices and emails. Of the 123 party-to-document links that both models produced, 23% were wrong, nearly all in this one way. Same prompt, same mistake, so the two models agreed and disagreement gave no signal.
- A file name where the chosen reading belongs. For each planted problem the model is asked which reading the house rule picks. Both models wrote a file name in that field almost every time, so the score for the chosen reading is 0 of 67. That is a failure of the answer format. It does not yet say whether the models can apply the rule.
- Cross-references not found. qwen-7b produced 2 of the 100 links from a master to its attached exhibits, where the pattern rules, which read file names and titles, found 27.
Fixing the three, and measuring again
I kept the old prompt as version 1 and wrote a version 2 that changes only what the three failures needed, with each change switchable so it could be measured alone. I tuned it on the five stacks above, froze it, and then ran it once on the 20 stacks the tuning never saw. Every figure in this section is from those 20 stacks (284 documents), qwen-7b, one run per version on the same night.
| Version 1 | Version 2 | |
|---|---|---|
| Party-to-document links produced (the key has 388) | 543 | 401 |
| Of those, in the key | 388 | 388 |
| Master linked to attached exhibit, found of 82 | 3 | 34 |
| Planted problems: items the model raised | 121 | 38 |
| Planted problems: raised items that match nothing planted | 77 | 5 |
| Planted problems matched on kind and document, of 55 | 22 | 14 |
| Of those, read the way the house rule reads them | 0 | 13 |
| People named: recall | 0.93 | 0.91 |
| Obligations: F1 | 0.57 | 0.54 |
| Links produced that are not in the key | 305 | 153 |
fabric8r extract docs/results/2026-11/corpus-25 --method local-llm --model qwen-7b --prompt-version 2 --except rel-002,rel-006,rel-008,rel-009,rel-013 --out docs/results/2026-11/b1/held20/qwen-7b/v2, then fabric8r score with the same --except. Version 1 is the same command without --prompt-version 2.
What I take from it:
- Tracing each failure mattered more than rewording the prompt. Reading the model's saved replies, only the first of the three was the prompt asking the wrong question: it asked for the parties a document names when the test wanted the parties that sign it. The second was the answer format. The third was mostly my own code, which lost links the model had found, and partly my own answer key, which expects a link to exhibits the master never cites.
- Parties. Before, 543 links produced, of which 388 were right. After, 401 produced, the same 388 right: the wrong ones went and no true link was lost, on stacks the fix was never tuned on.
- Cross-references. 3 of 82 before, 34 after. Not all 82 can be found from the text: some attached exhibits are never cited in the master, and the key should not ask for a citation that is not there. That is a correction to make to the key, not to the model.
- A score that looked fixed and was not. Once the answer format was right, the old score for planted problems read 11 of 12 on the tuning stacks. It was hollow: the model was now listing every kind of problem for every stack, and my scorer gave credit for naming the kind, whatever documents were named. I added a stricter count (the same kind and at least one of the right documents) and changed the answer so each kind gets an explicit yes or no. On the held-out stacks that cut the items raised from 121 to 38 and the false alarms from 77 to 5.
- What it cost. Asked for a yes or a no, the model says no more often, including when the answer is yes: strict matches fell from 22 to 14 of 55. Obligation precision slipped from 0.57 to 0.52. Which section an amendment replaces did not move at all; nothing here addressed it, and it is the largest error left.
- The same two prompts on a larger model. On the five tuning stacks (so this shows the fix carrying over to a second model, not a held-out result), mistral-24b went from 131 party links to 95, with 95 right both times. On planted problems it matched 12 of 12 strictly before and 10 after, with false alarms down from 10 to 2 and 8 read the way the house rule reads them, where before it gave no usable reading at all. The smaller model's low count is the model's limit more than the format's.
- A fourth failure, found and left alone. About one document reply in twenty is not valid JSON and the whole document is silently dropped; the same thing happening to a stack-level reply is why the planted-problem figures move between identical runs of version 1. I measured it and did not fix it here, so that the before and after of the three would stay a clean comparison.
A review table, scored cell by cell
A review table asks the same questions of every document set and fills a grid, each cell tied to its source. The hard cell is the one whose answer sits in another file: a fee, a term end or a party name that a later amendment changed. I built that test on the same 25 stacks: seven questions per stack (status, term end, current fee, payment days, each party's current legal name, assignee), each with an answer and a verbatim quote, 175 cells in all. The answer key knows which document set each current answer, so every result splits in two: 102 cells whose answer a later document changed, and 73 cells where the master's answer still stands.
The reader is mistral-24b. It was run twice: once shown the whole stack, and once shown only the master agreement, which is what a table gets when each document is read on its own.
| Master only | Whole stack | |
|---|---|---|
| Answers: cells a later document changed | 2% (2 of 102) | 78% (80 of 102) |
| Answers: cells never changed | 95% (69 of 73) | 90% (66 of 73) |
| Wrong answers on changed cells that gave an earlier, replaced value | 63 | 7 |
| Verbatim quotes: cells a later document changed | 0% (0 of 98) | 69% (68 of 98) |
| Verbatim quotes: cells never changed | 93% (51 of 55) | 85% (47 of 55) |
| Quotes given that are exact text from some document in the stack | 134 of 139 | 148 of 152 |
A quote is right only when it is exact text, character for character, from the file that holds the current answer, and overlaps the key's evidence for it. fabric8r grid run docs/results/2026-11/corpus-25 --model mistral-24b --mode stack --out docs/results/2026-11/b2/mistral-24b-stack (and --mode master-only), then fabric8r grid score --truth docs/results/2026-11/corpus-25 --grid docs/results/2026-11/b2/mistral-24b-stack --json docs/results/2026-11/grid-mistral-24b-stack.json.
- Read alone, the master is right about almost nothing that changed. Shown only the master agreement, the model got 2 of 102 changed cells right, and 63 of its wrong answers were the master's own, replaced value: a well-quoted, out-of-date answer. On cells that never changed it got 69 of 73.
- Shown the whole stack, it recovers most of them, not all. 78% on changed cells against 90% on unchanged ones. Same model, same questions, every document in front of it, and it is still about twelve points worse where a later document changed the answer. That gap is the amendment problem, measured.
- The dangerous errors are the stale ones. 7 of the whole-stack errors on changed cells gave a value that an amendment had replaced. Nothing about such a cell looks wrong.
- A quote that exists is not a quote from the right document. The model almost never invented a quote: 148 of 152 were exact text from some document in the stack. But only 69% of quotes on changed cells came from the document in force. A check that a quote appears in the source would pass nearly all of them.
- Some of the errors are the question's. Where an agreement was assigned, "the current legal name of this party" has two defensible answers; the key wants the original party and marks the assignee wrong in five cells. I count those against the test, not the model.
Checking a model judge against the answer key
Teams that use a model to grade output can usually check the grader only against a sample of human grades. Here the answer is known, so the judge itself can be scored. The judge was shown one extracted obligation (who owes what to whom) with the paragraph it cites, and asked: supported, or not supported? Then every obligation the key confirms was turned into a wrong one by swapping who owes whom, and judged again; the right answer to each of those is "not supported". Last, the right claim and its swap were shown side by side, in both orders.
| qwen-7b as judge (the model that did the extraction) | mistral-24b as judge | |
|---|---|---|
| Verdict agrees with the key, on items the key can grade | 85% (211 of 247) | 85% (210 of 247) |
| Right items the judge failed | 5% (10 of 204) | 9% (18 of 204) |
| Swapped claims the judge passed as supported | 31% (63 of 204) | 37% (76 of 204) |
| Side by side: the pick changed when the order changed | 17% (34 of 204) | 31% (63 of 204) |
python -m fabric8r.judge run --truth docs/results/2026-11/corpus-25 --extraction docs/results/2026-11/b1/qwen-7b-v1 --judge-model qwen-7b --out docs/results/2026-11/b3/judge-qwen-7b-on-qwen-7b-v1, then python -m fabric8r.judge score --judged ... --json docs/results/2026-11/judge-qwen-7b-on-qwen-7b-v1.json; the same with --judge-model mistral-24b. Of the 444 obligations extracted, the key could grade 204 as right and 43 as wrong; the rest sit in passages the key lists no obligation for, or quote text that is not in the document, and are left out.
- Agreement looks fine and hides the failure. Both judges agreed with the key on about six items in seven. Most items are right, so a judge that says "supported" to nearly everything scores well. The figure that matters is what it does with an item known to be wrong.
- Each judge passed about a third of claims that were wrong by construction: 31% and 37% of the swapped claims. The judges' own reasons show how: given the claim that the Customer owes the Vendor "Vendor will carry out for Customer the Services", one answered "supported: the text explicitly states that the Vendor will carry out services for the Customer." It checked that the words were in the passage, not who owed whom.
- The larger, different model was not the better judge. It passed at least as many swapped claims and was more affected by order.
- Order changes the verdict. Side by side, the pick changed in 17% and 31% of pairs when the same two claims were shown the other way round, and both judges leaned toward whichever came first (58% and 65% of picks). Neither ever chose the wrong claim in both orders: when a judge was wrong, it was following position.
- What I do with this. I do not report a judge's agreement rate alone. I plant items known to be wrong and report how many it passes; I ask paired questions both ways and treat a flip as no verdict; and I test the judge on the error the extractor actually makes, which here is reversing payer and payee.
Limits
- Fictional stacks. They are shaped on real agreements and they are still generated text: cleaner and more regular than a real file room.
- Two small local models, one run each. A difference of a few points between two columns is noise. Document-level figures repeated exactly when I re-ran them; the planted-problem figures for the first prompt did not, and should not be read to the item.
- No human graders. The answer key is the generator's own record, read under one set of house rules for the contested situations. A different set of rules gives a different key, and the tool can rebuild it.
- Five stacks for the two-model comparison, and five for tuning. The second prompt was tuned on those five and scored once on the other twenty. Five is a small set to tune on; one cost I saw on the five (fewer of the people named in a document found) did not repeat on the twenty.
- Identity, not quality. The scorer checks which party, which document and which section. It does not judge whether a summary of an obligation reads well or is complete.
- The answer key has limits of its own. It links a master to every attached exhibit whether or not the master cites it, and it cannot match some party names in subcontracts. Both showed up as "errors" that were not the model's. A test set needs the same scrutiny as the thing it tests.
- The review table and the judge test each use one prompt, written once and not tuned.
Reproduce
The repository is private; I am glad to walk through it, or to run any of these live.
fabric8r extract docs/results/2026-11/corpus-25 --method rules --out docs/results/2026-11/ext/rules
fabric8r extract docs/results/2026-11/corpus-25 --method local-llm --model qwen-7b --out docs/results/2026-11/ext/qwen-7b
fabric8r score --truth docs/results/2026-11/corpus-25 --extraction docs/results/2026-11/ext/rules --json docs/results/2026-11/score-rules-25.json
fabric8r score --truth docs/results/2026-11/corpus-25 --extraction docs/results/2026-11/ext/qwen-7b --json docs/results/2026-11/score-qwen-7b-25.json
fabric8r study --truth docs/results/2026-11/corpus-25 --a docs/results/2026-11/ext/qwen-7b --b docs/results/2026-11/ext/mistral-24b --json docs/results/2026-11/study-qwen-7b-mistral-24b-5.json
fabric8r extract docs/results/2026-11/corpus-25 --method local-llm --model qwen-7b --prompt-version 2 --except rel-002,rel-006,rel-008,rel-009,rel-013 --out docs/results/2026-11/b1/held20/qwen-7b/v2
fabric8r score --truth docs/results/2026-11/corpus-25 --extraction docs/results/2026-11/b1/held20/qwen-7b/v2 --except rel-002,rel-006,rel-008,rel-009,rel-013 --json docs/results/2026-11/b1-qwen-7b-v2-held20.json
fabric8r grid run docs/results/2026-11/corpus-25 --model mistral-24b --mode stack --out docs/results/2026-11/b2/mistral-24b-stack
fabric8r grid score --truth docs/results/2026-11/corpus-25 --grid docs/results/2026-11/b2/mistral-24b-stack --json docs/results/2026-11/grid-mistral-24b-stack.json
python -m fabric8r.judge run --truth docs/results/2026-11/corpus-25 --extraction docs/results/2026-11/b1/qwen-7b-v1 --judge-model qwen-7b --out docs/results/2026-11/b3/judge-qwen-7b-on-qwen-7b-v1
python -m fabric8r.judge score --judged docs/results/2026-11/b3/judge-qwen-7b-on-qwen-7b-v1 --json docs/results/2026-11/judge-qwen-7b-on-qwen-7b-v1.json
python scripts/build_results_page.py --results docs/results/2026-11 --template docs/results/2026-11/page.template.html --out docs/results/2026-11/index.html
Every figure on this page is read from the result files by the last command; none is typed by hand. The first three sections were measured in September 2026; the last three on 14 and 15 November 2026.