extract_numbers.py: 'FY2023 to' parses as 2,023,000,000,000,000 — a lone letter is accepted as a magnitude suffix
Summary
skills/ib-check-deck/scripts/extract_numbers.py reads a four-digit year plus
the first letter of the following word as a magnitude-suffixed number.
The sentence "Revenue grew from $100.0 million in FY2023 to $120.0 million in
FY2024." yields a third figure: 2023t → 2,023,000,000,000,000, i.e. two
quadrillion dollars, categorised as revenue.
The t comes from the word "to".
Cause
# lines 118–125
r'(?P<number>[\d,]+(?:\.\d+)?)'
r'\s*'
r'(?P<unit>%|bps|x|'
r'[Tt]rillion|[Bb]illion|[Mm]illion|[Tt]housand|'
r'[TBMKtbmk]n?|mm|MM)?' # a LONE letter counts as a magnitude
r'(?!\d)' # stops a following DIGIT, but not a following LETTER\s* lets the unit sit across the space, [TBMKtbmk] accepts the bare t, and
(?!\d) only rules out a following digit — so ... 2023 to ... matches with
number=2023, unit=t.
Reproduce
from extract_numbers import extract_numbers
for n in extract_numbers("Revenue grew from $100.0 million in FY2023 to $120.0 million in FY2024."):
print(n.value, n.unit, n.normalized, n.category)$100.0million USD_million 100000000 revenue
2023t t 2023000000000000000 revenue <-- 2.023e15
$120.0million USD_million 120000000 revenueAny "from FY20XX to FY20YY" sentence — routine in a deck — injects one. The
figure then dominates find_inconsistencies, since it is compared against real
revenue in the same category.
Suggested fix
Two changes, either of which kills this case; both together are safer:
- Require a non-letter after the unit, not just a non-digit:
r'(?![A-Za-z0-9])' - Reject a bare four-digit year carrying neither a currency symbol nor a
unit —
1900–2099with no$/€/£and no suffix is a date:if re.fullmatch(r'(?:19|20)\d{2}', raw) and not currency and not unit: continue
Keep the genuine suffixes working: $1.2bn, $300m, 45k must still parse.
Scope
Two copies on main:
plugins/vertical-plugins/financial-analysis/skills/ib-check-deck/scripts/extract_numbers.pyplugins/agent-plugins/pitch-agent/skills/ib-check-deck/scripts/extract_numbers.py
Related but separate defect filed alongside this one (period-blind grouping). Happy to open a PR.
Source: anthropics/financial-services