Repository navigation
docs(479): set a tolerance, not a threshold, in NumericComparator amount examples - #582
Conversation
…unt examples NumericComparator scores 1.0 or 0.0, so threshold=0.95 never tolerated rounding: 100 vs 100.01 scored 0.0 in all eight documented amount examples. They now set absolute_tolerance=0.01 and score 1.0. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Security Scan ResultsASH Security Scan Report
Scan Metadata
SummaryScanner ResultsThe table below shows findings by scanner, with status based on severity thresholds and dependencies:
Report generated by Automated Security Helper (ASH) at 2026-11-18T12:49:10+00:00 |
harrycav
left a comment
There was a problem hiding this comment.
Thanks, clean fix. I ran every changed example (all five JSON schemas, including the unit_price line item, plus both Python fields) against this branch's src/: each scores 100 vs 100.01 as 1.0 and 100.02 as 0.0, as the PR says. The README and docs-build tests and check_links.py pass, and CI is green. Agree with leaving the four inference/export spots alone, since none of them uses the threshold as a tolerance.
One older line makes the same mistake and isn't in #479's list, so I've opened a follow-up (#585) rather than grow this PR: the "Tolerates small numeric differences" rows for number/integer in README.md:310-311 and Guides/Comparators/README.md:530-531, which describe what is an exact match by default.
sromoam
left a comment
There was a problem hiding this comment.
Thanks for picking this up, and for the clear before/after evidence! Measured against this branch, every amended example (README static model, the README schemas, the Evaluation class and schema, the IDP schema) scores 100 vs 100.01 as 1.0 and 100 vs 100.02 as 0.0, where the old form scores 0.0, and the schemas build with no warnings.
Smaller
docs/docs/Advanced/bbox-map-metrics.md:72anddocs/docs/Advanced/dynamic-models.md:40-44(outside this diff, optional): I agree with your notes that neither presents the threshold as a tolerance, so the issue's done-when is met.dynamic-models.md:40-44is the hand-written Basic Example schema, not the inferred tables your notes mention. If you would like to cover both here, each still pairsNumericComparatorwith 0.95 and no tolerance (measured against this branch: 1500.00 vs 1500.01 scores 0.0 on the bbox model, 999.99 vs 1000.0 scores 0.0 on the dynamic-models schema). For bbox, usecomparator=NumericComparator(absolute_tolerance=0.01)and dropthreshold=0.95; the page's mAP output stays the same (measured). For dynamic-models, swap"x-aws-stickler-threshold": 0.95for"x-aws-stickler-comparator-config": {"absolute_tolerance": 0.01}. Agreed on leavingmodel-export.md:76, since its printed export depends on the no-argument comparator. Fine here or as a follow-up.README.md:372(optional nit): see the inline suggestion.
Approving.
…erance # Conflicts: # CHANGELOG.md
Issue Reference
Fixes #479.
Description of Changes
NumericComparatorreturns only 1.0 or 0.0, so the field threshold never decides how close two amounts must be. Eight documented amount examples paired it withthreshold=0.95(or used no comparator at all) and read as if that tolerated rounding. Each one scored100vs100.01as 0.0. They now set the tolerance on the comparator and score 1.0.flowchart TD A[Documented amount example scores 100 vs 100.01] --> B{What the example sets} B -->|Before threshold 0.95| C[Tolerance stays 0 so score is 0.0] B -->|After absolute_tolerance 0.01| D[Within tolerance so score is 1.0]Changes Made
:26: monetary amounts useNumericComparator(absolute_tolerance=0.01)(orrelative_tolerance), with the 1.0-or-0.0 sentence from the issue.:20: "amounts" dropped from the 0.8-0.9 row.absolute_tolerance=0.01, dropsthreshold=0.95, comment is now# Equal within 0.01. The JSON example swapsx-aws-stickler-threshold: 0.95forx-aws-stickler-comparator-config: {"absolute_tolerance": 0.01}.total_amountx3,unit_price) get the same swap.total: float = ComparableField(threshold=0.95)named no comparator, so it was Levenshtein on the string form; it now namesNumericComparator(absolute_tolerance=0.01)and the import is added. "Amounts" moved out of the Threshold Selection Guide into one sentence under it.CHANGELOG.mdentry under[Unreleased]→ Documentation.Testing
Narrated and captioned recording, before then after:
evidence.mp4
The recording shows these commands, run from the repo root of this branch. The change is docs-only, so the library is the same on
devand here; what differs is the field definition the docs print.Before (the field as documented on
dev)After (the field as documented on this branch)
All eight documented amount examples (README, Evaluation guide, IDP Accelerator; Python and JSON schema forms) were checked the same way: each scores
100vs100.01as 0.0 as written ondev(f74e5e9) and 1.0 as written on this branch.uv run pytest tests/test_readme_examples.py tests/test_docs_build.py: 88 passed.uv run python docs/check_links.pybuilds clean;uv run ruff check .passes.Additional Notes
grep -rn "NumericComparator" docs/docs README.mdreviewed. Four places still show a fractional threshold next toNumericComparatorand I left them, because none presents the threshold as the tolerance and none is listed in the issue:Advanced/bbox-map-metrics.md:72andAdvanced/model-export.md:76(the second has its exported schema printed below it, so changing it means changing that output too), and the inferred-comparator tables inultra-quick-start.mdanddynamic-models.md, which report what inference assigns. Happy to fold the first two in if you want them covered here.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
🤖 Generated with Claude Code