Sub topic 11
Checking numbers and claims before publishing
This chapter assumes you can read basic Python and JSON. It also assumes you know the metrics from earlier chapters: impressions, clicks, conversions, spend, and the ratios computed from them. Here you add a verification step between the drafted report and the reader.
Why verification is a separate step
A language model writes fluent text, and fluent text is not evidence. A draft can contain a figure the model rounded, mixed up between two campaigns, or invented. Grounding and deterministic tools reduce these errors but do not remove them. Verification is the last automated check before a person reads the draft.
The main rule is simple. Every number in a published report must trace back to a tool result. If a number has no source, it is flagged and not published.
Where the check sits
The check runs after the report is drafted and before human review.
A crude number check
The function below collects every number in the report and every number in the evidence. It returns the numbers that appear only in the report.
import re
NUMBER = re.compile(r"\d+(?:\.\d+)?")
def unsupported_numbers(report, evidence):
"""Return numbers in the report that do not appear in the evidence text."""
used = set(NUMBER.findall(report))
allowed = set(NUMBER.findall(evidence))
return sorted(used - allowed)
evidence = '{"ctr": 0.0167, "cpc": 0.84, "cpa": 17.5}'
report = "CPC was 0.84 and CPA was 21.0 this month."
print(unsupported_numbers(report, evidence))This prints ['21.0']. The CPC of 0.84 matches the evidence. The CPA of 21.0 does not, because the tool returned 17.5.
Limits of the check
The check is deliberately crude. Know what it misses before you rely on it.
- Right number, wrong meaning. If the report says "CTR was 0.84", the number exists in the evidence, so it passes, but it belongs to CPC.
- Reformatted numbers. "1.67%" does not match 0.0167. Either ask the model for the same format as the tool output, or convert before comparing.
- Coincidental matches. Small numbers such as 1 or 10 often appear in both texts by chance.
- Claims without numbers. "Email outperformed search" contains no figure, so this check cannot test it.
| Error type | Caught by number check? | Better defense |
|---|---|---|
| Invented figure | Yes | Flag and redraft |
| Right figure, wrong metric | No | Structured output with metric names |
| Percent versus fraction | Sometimes | Agree one format |
| Unsupported comparison | No | Recompute with code, or human review |
Making the check stronger
Three changes help without much extra code.
- Ask the model for structured output, such as a list of claims, each with a metric name, a value and the tool call it came from. Then compare each value to the named metric, not to the whole evidence text.
- Recompute any comparison the report makes, such as "CPA rose 20%", using the same deterministic code as before.
- When the check fails, return the flagged numbers to the model and let it redraft. Limit the retries, as you limit steps in the agent loop, and send the report to a person if it still fails.
Exercise
A draft says "CTR was 1.67% and CPC was 0.84." The evidence is {"ctr": 0.0167, "cpc": 0.84}. Does unsupported_numbers flag anything, and what is the likely problem?
Show answer
Yes. It flags '1.67', because the evidence contains 0.0167 and not 1.67. The value is correct but written as a percentage. Fix it by agreeing on one format, or by converting the tool values before comparing.
Exercise
Name one error that the number check cannot catch, and say how you would catch it.
Show answer
A correct number attached to the wrong metric, such as describing the CPC value as the CTR. Catch it with structured output that pairs each value with a metric name, and compare each value against that named metric.