Number trace: check AI text against your tables
A free script that runs on your own computer. It reads a piece of text and the source tables behind it, then lists every number in the text that it cannot find in the tables.
What it does
When an AI assistant drafts results text, the most common error to catch is a number that is not in your tables: a transposed digit, a rounded value that was never printed, a percent that was invented. This script checks each number in the draft against the source you give it and reports:
- numbers in the text that are not in the source;
- numbers that matched only after rounding, or only after converting a percent to a proportion (so you can look at them);
- strong or interpretive phrases in the text that the source does not contain, such as "statistically significant", "clinically meaningful", "well tolerated" or "no new safety signals".
It allows for the usual differences in how a number is written: a leading zero left off (.05 and 0.05), thousands commas, a minus sign typed as a dash, rounding to fewer decimals, and 75.6% against 0.756.
Your data stays with you
The script makes no network calls and needs no extra packages. Use R (base R only) or Python (standard library only). Nothing is uploaded and nothing is sent to this site. You can run it with the network switched off.
Run it in 3 steps
1. Save your source tables as a plain text or CSV file, and the text to check as another plain text file. 2. Download number_trace.R or number_trace.py (links below). 3. Run one of these commands in a terminal, with your own file names:
Rscript number_trace.R --source tables.txt --text draft.txt
python number_trace.py --source tables.txt --text draft.txt
The report prints to the screen. Add --out report.txt to save it. A worked example with public CDISC pilot data is included so you can see the output before using your own files.
What a result looks like
On the included example, a copy of a correct results passage had 174 numbers, and 173 were found in the source. The one not found was a threshold the writer had added (0.05). A copy with errors planted by hand had 5 of 9 number errors reported as not found, for example 243 where the table says 234. The 4 it did not report were a swapped arm, a value taken from the wrong row, a wrong rounded value that exists elsewhere in the tables, and a dropped minus sign that matched a different number after rounding.
What it cannot do
- It shows that a number appears somewhere in your source. It does not show that the number is the right one, or that it sits in the right row, column, arm or table, or that the sentence around it is correct.
- A wrong number that also appears elsewhere in your tables will pass.
- Single-digit numbers match by chance, so the report counts them as weak support.
- It does not calculate anything. A percent or difference that you derived yourself is reported as not found unless the table prints it.
- The phrase check is a fixed word list. It does not understand negation, so a sentence saying "no statement of improvement is made" is flagged. Expect false alarms there.
- It reads plain text and CSV only, not PDF or Word files, and it does not check source values that the text leaves out.
- A clean report is not a pass. Use it as a first filter before a person reads the text against the tables. It is not validated software and does not replace your QC process.
The tested counts, including false positives and false negatives, are in the README.
Downloads
- number_trace.R (base R)
- number_trace.py (Python standard library)
- README.md, with the full test results
- example input and expected output
Licence
The code is released under the MIT licence: free to use, copy, modify and share, with no warranty. The example tables are a condensed, re-typed excerpt of the public CDISC pilot study clinical study report: the numbers are copied from the CSR tables, but table titles are shortened and footnotes abridged, so it is not the original wording. It is used with attribution to CDISC and not for sale. CDISC's terms for the pilot materials ask for unmodified use, so if you reuse the example, go back to the original report and check those terms.
- number_trace.R
- number_trace.py
- README.md
- example/source_tables.txt, and the other example texts and expected reports in the same folder structure
Get one workflow a week
Unsubscribe anytime. Privacy.