Sub topic 11
Checking numbers and claims before publishing
This chapter assumes you can read basic Python and regular expressions, and that you know the tool-calling and report-generation material from earlier chapters. You should also know why language models sometimes state wrong numbers with confidence.
A drafted report can read well and still be wrong. The model may have rounded a figure, copied a number from the wrong row, or invented a trend. Verification is the step between drafting and publishing that catches these errors. This chapter builds it as layers of checks, from cheap automatic ones to a human decision.
What can go wrong in a draft
Most report errors fall into a few types. Name them, because each needs a different check.
| Error type | Example | Typical cause |
|---|---|---|
| Unsupported number | "CPA was 21.0" when no tool returned 21.0 | The model made up or mis-recalled a figure |
| Wrong attribution | Campaign A's CTR reported as Campaign B's | Similar rows in the context window |
| Bad arithmetic | "Spend rose 12%" when it rose 8% | The model computed in its head |
| Unsupported claim | "Because of the new creative, conversions rose" | A causal story with no evidence |
| Stale or wrong period | Last month's data described as this month's | Missing date filters or cached results |
The first three are numeric, so code can check them. The last two are claims, which are harder to check automatically and usually end up with a reviewer.
The layers of verification
No single check catches everything. Stack several, ordered from cheapest to most expensive.
Run the layers in this order because each one filters out errors before the next, more costly layer sees them.
Layer 1: structure checks
If your report generator returns structured output (see the earlier chapter on prompts), validate it first. Check that every required section exists, that each metric field is present, and that dates and campaign names match the request. A missing section is a cheap failure. The model can retry it immediately with no human involved.
Layer 2: is every number supported?
The simplest numeric check asks one question: does each number in the report appear in the evidence the tools returned? Here is the crude version from the plan:
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 report claims a CPA of 21.0, but the tool returned 17.5, so a reviewer should look at that sentence before it ships.
This check compares strings, so it has weak spots:
- Format differences. The evidence says
2and the report says2.0. The evidence says1000and the report says1,000. Both are the same number and both would be flagged. - Derived values. The evidence says
0.0167and the report says1.67%. A correct conversion looks like an error. - Coincidental matches. A wrong number that happens to appear elsewhere in the evidence passes. The check cannot tell that 200 clicks was attached to the wrong campaign.
- Dates and labels. Digits in "Q3" or "2026-11-26" count as numbers and can add noise.
Reduce the noise by normalizing numbers to floats and allowing a small tolerance:
import re
NUMBER = re.compile(r"\d[\d,]*(?:\.\d+)?")
def to_numbers(text):
return {float(m.replace(",", "")) for m in NUMBER.findall(text)}
def unsupported(report, evidence, rel_tol=0.005):
allowed = to_numbers(evidence)
flagged = []
for value in sorted(to_numbers(report)):
if not any(abs(value - a) <= rel_tol * max(abs(a), 1e-9) for a in allowed):
flagged.append(value)
return flagged
evidence = '{"clicks": 2000, "ctr": 0.0167, "cpa": 17.5}'
report = "There were 2,000.0 clicks and CPA was 21.0."
print(unsupported(report, evidence))This prints [21.0]. The value 2,000.0 now matches 2000. A relative tolerance of 0.5% absorbs rounding but still catches real differences.
To avoid the percentage problem, have the tool return display-ready fields such as ctr_pct: 1.67. Then every figure the model might quote already exists in the evidence. Do not loosen the checker to guess at conversions.
Layer 3: recompute, don't just compare
Layer 2 asks whether a number is in the evidence. Layer 3 asks whether it is correct. When the report states a derived figure, such as "spend rose 8%", recompute it with code from the raw tool results and compare.
def check_change(claimed_pct, previous, current, tolerance=0.5):
"""Compare a claimed percent change with one computed from raw values."""
if previous == 0:
return False, None
actual = (current - previous) / previous * 100
return abs(actual - claimed_pct) <= tolerance, round(actual, 1)
print(check_change(12.0, previous=1000.0, current=1080.0))This prints (False, 8.0). The claim of 12% fails against the actual 8.0%. The best design avoids the problem in the first place. Compute every change in the metrics tool and let the model only quote it. Recomputation is the safety net for when the model quotes it wrongly or computes its own.
Zero denominators need a deliberate decision. The metrics tool returns None for a CTR with zero impressions. The report should say "not available", not "0%". A check should flag any sentence that gives a number for a field whose value is None.
Layer 4: checking claims
Claims such as "the new landing page drove the increase" go beyond arithmetic. Three practical techniques help:
- Require a citation per claim. In the structured output, have each finding carry a
sourcefield that points to a tool call or document. A finding with no source is rejected automatically. - Separate observation from interpretation. Ask the model to label statements as
observed(directly in the data) orhypothesis(a possible explanation). Reviewers then know which statements need judgement. - Use a second model pass as a critic. Give a different prompt the report and the evidence, and ask it to list any statement the evidence does not support. This finds more than regex checks do, but it can also be wrong, so treat its output as a prompt for review, not as proof.
Deciding what happens on failure
A check is only useful if the failure path is defined. A reasonable policy has three outcomes:
- Auto-retry. Structural failures and unsupported numbers go back to the model along with the list of flagged items. Cap retries, as you do with the agent loop's step limit, so a stubborn failure cannot run forever.
- Hold for review. If retries fail, or a claim has no source, stop and send the draft to a person with the flagged items highlighted.
- Block. Some failures should never publish, such as a number for a client that was not in the request. Treat these as errors, not warnings.
Log every check result with the report version. Over time the log shows which error types occur most often, and that tells you which prompt or tool to fix.
Limits to keep in mind
- Verification shows that a report is consistent with the evidence. It cannot show that the evidence is right. If the ad platform export is wrong or filtered to the wrong dates, a perfectly verified report is still wrong.
- Passing every check lowers risk but does not remove it. The next chapter covers the human approval step that remains.
- Checks need maintenance. When you add a new metric or report format, add a matching check, or the new content goes unverified.
Summary
Treat the draft as untrusted. Validate its structure, confirm every number is supported by tool output, recompute derived figures with code, and send unsupported claims to a person. Define what happens when a check fails, and log the outcomes so you can see where the pipeline is weak.
Exercise
A draft report says "CTR was 1.67%". The metrics tool returned {"ctr": 0.0167}. The string-based unsupported_numbers function flags 1.67. Give two ways to fix this and say which you prefer.
Show answer
One fix is to make the checker convert fractions to percentages before comparing, which means it guesses at conversions and can let wrong numbers through. The other is to have the metrics tool also return a display-ready field such as "ctr_pct": 1.67, so the figure the model quotes already exists in the evidence. The second is better because the tool stays the single source of every number and the checker stays simple and strict.
Exercise
Using the check_change function, a report claims spend rose 5% from 2000.0 to 2100.0. Does the claim pass with the default tolerance, and what does the function return?
Show answer
It passes. The actual change is (2100.0 - 2000.0) / 2000.0 * 100 = 5.0, which equals the claim, so the function returns (True, 5.0).
Exercise
Why can a report pass the number-support check and still contain a wrong number? Give one example.
Show answer
The check only tests whether the number appears somewhere in the evidence, not whether it is attached to the right item. If Campaign A had 200 clicks and Campaign B had 50, a report that says Campaign B had 200 clicks passes, because 200 is in the evidence. Catching this needs a per-field comparison or a human review.