Skip to content

docs(479): set a tolerance, not a threshold, in NumericComparator amount examples - #582

Merged
harrycav merged 3 commits into
awslabs:devfrom
burrows99:docs/479-numeric-tolerance
Nov 18, 2026
Merged

harrycav merged 3 commits into
awslabs:devfrom
burrows99:docs/479-numeric-tolerance

Conversation

@burrows99

@burrows99 burrows99 commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Issue Reference

Fixes #479.

Description of Changes

NumericComparator returns only 1.0 or 0.0, so the field threshold never decides how close two amounts must be. Eight documented amount examples paired it with threshold=0.95 (or used no comparator at all) and read as if that tolerated rounding. Each one scored 100 vs 100.01 as 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]
Loading

Changes Made

  • Best Practices :26: monetary amounts use NumericComparator(absolute_tolerance=0.01) (or relative_tolerance), with the 1.0-or-0.0 sentence from the issue. :20: "amounts" dropped from the 0.8-0.9 row.
  • Evaluation guide: the Python example sets absolute_tolerance=0.01, drops threshold=0.95, comment is now # Equal within 0.01. The JSON example swaps x-aws-stickler-threshold: 0.95 for x-aws-stickler-comparator-config: {"absolute_tolerance": 0.01}.
  • IDP Accelerator JSON example: same swap.
  • README: the four schema fields (total_amount x3, 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 names NumericComparator(absolute_tolerance=0.01) and the import is added. "Amounts" moved out of the Threshold Selection Guide into one sentence under it.
  • CHANGELOG.md entry 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 dev and here; what differs is the field definition the docs print.

$ git diff upstream/dev --stat
 CHANGELOG.md                                  |  9 +++++++++
 README.md                                     | 16 +++++++++-------
 docs/docs/Guides/Best-Practices/README.md     |  4 ++--
 docs/docs/Guides/Evaluation/README.md         |  5 ++---
 docs/docs/Guides/Use-Cases/idp-accelerator.md |  2 +-
 5 files changed, 23 insertions(+), 13 deletions(-)
$ uv run python -c "import stickler, os; print(os.path.relpath(stickler.__file__))"
src/stickler/__init__.py

Before (the field as documented on dev)

$ uv run python -c "from stickler import *
class Inv(StructuredModel): total: float = ComparableField(comparator=NumericComparator(), threshold=0.95)
print(Inv(total=100).compare_with(Inv(total=100.01))['field_scores'])"
{'total': 0.0}

After (the field as documented on this branch)

$ uv run python -c "from stickler import *
class Inv(StructuredModel): total: float = ComparableField(comparator=NumericComparator(absolute_tolerance=0.01))
print(Inv(total=100).compare_with(Inv(total=100.01))['field_scores'])"
{'total': 1.0}
$ uv run pytest tests/test_readme_examples.py -qq
...........                                                              [100%]
11 passed in 0.17s

All eight documented amount examples (README, Evaluation guide, IDP Accelerator; Python and JSON schema forms) were checked the same way: each scores 100 vs 100.01 as 0.0 as written on dev (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.py builds clean; uv run ruff check . passes.

Additional Notes

  • grep -rn "NumericComparator" docs/docs README.md reviewed. Four places still show a fractional threshold next to NumericComparator and I left them, because none presents the threshold as the tolerance and none is listed in the issue: Advanced/bbox-map-metrics.md:72 and Advanced/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 in ultra-quick-start.md and dynamic-models.md, which report what inference assigns. Happy to fold the first two in if you want them covered here.
  • No overlap with the lines docs: state the list contract in one place, and correct the claims that disagree with it #419 and fix(importers): resolve an unstated threshold and clip as the Python path does (#334, #348) #408 edit beyond a rebase.
  • AI assistance (Claude Code) was used to draft the edits and record the evidence; the commands above were run locally from this checkout.

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

…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>
@harrycav harrycav self-assigned this Nov 17, 2026
@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Security Scan Results

ASH Security Scan Report

  • Report generated: 2026-11-18T12:49:09+00:00
  • Time since scan: 3 minutes

Scan Metadata

  • Project: ASH
  • Scan executed: 2026-11-18T12:45:54+00:00
  • ASH version: 3.1.2

Summary

Scanner Results

The table below shows findings by scanner, with status based on severity thresholds and dependencies:

  • Severity levels:
    • Suppressed (S): Findings that have been explicitly suppressed and don't affect scanner status
    • Critical (C): Highest severity findings that require immediate attention
    • High (H): Serious findings that should be addressed soon
    • Medium (M): Moderate risk findings
    • Low (L): Lower risk findings
    • Info (I): Informational findings with minimal risk
  • Duration (Time): Time taken by the scanner to complete its execution
  • Actionable: Number of findings at or above the threshold severity level that require attention
  • Result:
    • PASSED = No findings at or above threshold
    • FAILED = Findings at or above threshold
    • MISSING = Required dependencies not available
    • SKIPPED = Scanner explicitly disabled
    • ERROR = Scanner execution error
  • Threshold: The minimum severity level that will cause a scanner to fail
    • Thresholds: ALL, LOW, MEDIUM, HIGH, CRITICAL
    • Source: Values in parentheses indicate where the threshold is set:
      • global (global_settings section in the ASH_CONFIG used)
      • config (scanner config section in the ASH_CONFIG used)
      • scanner (default configuration in the plugin, if explicitly set)
  • Statistics calculation:
    • All statistics are calculated from the final aggregated SARIF report
    • Suppressed findings are counted separately and do not contribute to actionable findings
    • Scanner status is determined by comparing actionable findings to the threshold
Scanner Suppressed Critical High Medium Low Info Actionable Result Threshold
bandit 0 0 0 0 6826 0 0 PASSED MEDIUM (global)
cdk-nag 0 0 0 0 0 0 0 PASSED MEDIUM (global)
cfn-nag 0 0 0 0 0 0 0 MISSING MEDIUM (global)
checkov 0 0 0 0 0 0 0 PASSED MEDIUM (global)
detect-secrets 0 0 0 0 0 0 0 PASSED MEDIUM (global)
grype 0 0 0 0 0 0 0 MISSING MEDIUM (global)
npm-audit 0 0 0 0 0 0 0 PASSED MEDIUM (global)
opengrep 0 0 0 0 0 0 0 MISSING MEDIUM (global)
semgrep 3 0 0 0 0 0 0 PASSED MEDIUM (global)
syft 0 0 0 0 0 0 0 MISSING MEDIUM (global)

Report generated by Automated Security Helper (ASH) at 2026-11-18T12:49:10+00:00

@harrycav harrycav left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 sromoam left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:72 and docs/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-44 is the hand-written Basic Example schema, not the inferred tables your notes mention. If you would like to cover both here, each still pairs NumericComparator with 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, use comparator=NumericComparator(absolute_tolerance=0.01) and drop threshold=0.95; the page's mAP output stays the same (measured). For dynamic-models, swap "x-aws-stickler-threshold": 0.95 for "x-aws-stickler-comparator-config": {"absolute_tolerance": 0.01}. Agreed on leaving model-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.

Comment thread README.md Resolved
@harrycav
harrycav merged commit 626dd6e into awslabs:dev Nov 18, 2026
11 checks passed
@burrows99
burrows99 deleted the docs/479-numeric-tolerance branch November 18, 2026 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stop presenting a field threshold as rounding tolerance for NumericComparator

3 participants