Compare Two Articles' Claims in a Table and Check the Quotes
Get two articles' claims as a match / conflict / one-sided table from claude -p, then check with grep -F that each evidence cell is quoted from its own article.
Two articles on the same event give different numbers. Instead of matching them by eye, ask the model for an item-by-item table, then let a script check that each evidence sentence really appears in the article it is attributed to. For getting a URL and quote per claim from one answer, see the claim-evidence URL table post; this one compares two texts you already have.
[1] Save the two articles as files. They are invented for practice, with three facts deliberately different: bike count, duration, operator.
Starlake City launched its bike-share pilot on March 1. The fleet totals 500 bikes across 40 docking stations. A ride costs 1,000 won per 30 minutes. The pilot runs for six months, and the city handed operations to a private company. The first month recorded 12,000 rides.The Starlake City bike-share pilot opened on March 1. The city deployed 300 bikes and 40 stations. The fare is set at 1,000 won per 30 minutes. The pilot lasts one year, and the parks department runs it directly. In a resident survey, 62% of respondents asked for helmets at the stations.[2] Write the prompt. Limit the verdict to four values and require evidence to be copied verbatim; step 4 depends on that. Items missing from an article get NONE instead of a blank.
<a> and <b> below are two articles about the same event. Compare their claims item by item and answer only with a tab-separated table. No text outside the table.Columns: item<TAB>verdict<TAB>A evidence<TAB>B evidenceRules:- verdict is one of: match, conflict, A only, B only.- A evidence and B evidence must be copied from that article character for character. If the article does not contain the item (B evidence for "A only"), write NONE.- The first line is the header row.[3] Wrap the articles in <a> and <b> and run. --tools "" turns tools off; the table goes to a file.
$ (cat head.txt; echo "<a>"; cat a.txt; echo "</a>"; echo "<b>"; cat b.txt; echo "</b>") > prompt.txt$ claude -p --model claude-sonnet-5-5 --max-turns 1 --tools "" < prompt.txt > table.tsv$ cat table.tsvitem verdict A evidence B evidenceLaunch date March 1 match Starlake City launched its bike-share pilot on March 1. The Starlake City bike-share pilot opened on March 1.Number of bikes conflict The fleet totals 500 bikes across 40 docking stations. The city deployed 300 bikes and 40 stations.Number of stations match The fleet totals 500 bikes across 40 docking stations. The city deployed 300 bikes and 40 stations.Fare match A ride costs 1,000 won per 30 minutes. The fare is set at 1,000 won per 30 minutes.Pilot duration conflict The pilot runs for six months The pilot lasts one yearOperator conflict the city handed operations to a private company the parks department runs it directlyFirst month rides A only The first month recorded 12,000 rides. NONEResident survey on helmets B only NONE In a resident survey, 62% of respondents asked for helmets at the stations.Bike count (500 vs 300), duration (six months vs one year) and operator (private company vs parks department) came back as conflict, and the two one-sided items were split into A only and B only. A second run with the same prompt gave the same verdict for all 8 items (item labels differed slightly, e.g. "Launch date" and "Launch date March 1").
[4] Write the checker. It collapses whitespace in each article, then looks up the A evidence in article A only and the B evidence in article B only, with grep -F. -F treats . and ( in the sentence as literal characters, not regex.
#!/bin/bash# usage: ./check-matrix.sh a.txt b.txt table.tsv (columns: item verdict A-quote B-quote, tab-separated, first line is the header)a=$(tr -s '[:space:]' ' ' < "$1"); b=$(tr -s '[:space:]' ' ' < "$2")tail -n +2 "$3" | while IFS=$'\t' read -r item verdict qa qb; do ra=-; rb=- [ "$qa" != NONE ] && { if printf '%s' "$a" | grep -qF -- "$qa"; then ra=found; else ra=missing; fi; } [ "$qb" != NONE ] && { if printf '%s' "$b" | grep -qF -- "$qb"; then rb=found; else rb=missing; fi; } echo -e "$item\t$verdict\tA:$ra\tB:$rb"done[5] Run it. Every evidence cell in the step 3 table exists in its article. - means the cell was NONE and was not searched.
$ chmod +x check-matrix.sh$ ./check-matrix.sh a.txt b.txt table.tsvLaunch date March 1 match A:found B:foundNumber of bikes conflict A:found B:foundNumber of stations match A:found B:foundFare match A:found B:foundPilot duration conflict A:found B:foundOperator conflict A:found B:foundFirst month rides A only A:found B:-Resident survey on helmets B only A:- B:foundAn all-pass run does not show that the script can fail, so break the table on purpose. In bad.tsv, the A evidence of the bike row is edited by hand to "600 bikes" and the B evidence of the duration row to "two years" (the model did not make these errors).
$ ./check-matrix.sh a.txt b.txt bad.tsv | grep -v 'A:found B:found'Number of bikes conflict A:missing B:foundPilot duration conflict A:found B:missingFirst month rides A only A:found B:-Resident survey on helmets B only A:- B:found[6] Check the verdict column against the evidence columns. The script only asks whether a sentence exists in the article, so look separately for rows whose verdict and NONE cells disagree.
$ awk -F'\t' 'NR>1 && (($2=="A only" && $4!="NONE") || ($2=="B only" && $3!="NONE")) {print "verdict and NONE disagree:", $1}' table.tsvNothing was printed for the step 3 table.
[7] A person still has to read the rest.
| What the script knows | What to check by hand |
|---|---|
| The evidence sentence is in the article | Whether the sentence is about that item. In the table above, the "Number of bikes" and "Number of stations" rows cite the same sentence (500 bikes across 40 docking stations) |
The evidence cell is NONE | Whether the article really lacks the item. It may state it in different words and the model missed it |
The match / conflict verdict | Not checked. See how the model treats "1,000 won" versus "one thousand won" on your own data |