Skip to content

docs(comparators): say which path compares postal codes exactly - #586

Merged
digalaviz merged 2 commits into
awslabs:devfrom
WilliamK112:docs/492-postal-code-exact-scope
Nov 18, 2026
Merged

digalaviz merged 2 commits into
awslabs:devfrom
WilliamK112:docs/492-postal-code-exact-scope

Conversation

@WilliamK112

@WilliamK112 WilliamK112 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Issue #, if available: Fixes #492

Description of changes:

Guides/Comparators/postal-codes.md opened with "Stickler compares postal codes exactly". That holds only on the inference path. With ComparableField(), a bare annotation or a JSON Schema string, a postal code is Levenshtein, so a different code can match. This PR:

  • replaces the opening paragraph: stickler.evaluate on a plain Pydantic BaseModel compares zip, zip_code, postal_code, postcode and postal exactly; a StructuredModel (even one passed to stickler.evaluate) without a comparator, or a JSON Schema string, uses edit distance; name a comparator either way. The wording is the reviewers' suggestion, and the next paragraph is rewrapped to fit;
  • adds DEFAULT_THRESHOLD = 1.0 to USZipComparator, UKPostcodeComparator and ZipLookupComparator, as the Comparators guide asks;
  • adds a ### Fixed bullet under [Unreleased] in CHANGELOG.md.

Checked on dev at 8c56dfa, with stickler imported from that checkout's src/: "98101-1234" vs "98102-1234" scores {'zip_code': 0.9} for ComparableField(), a bare str annotation and from_json_schema, and matched=False (0.0) through stickler.evaluate. The two edited examples still run: both thresholds read 1.0, USZipComparator scores 98101-1234/98101 1234 as 1.0 and 98101-1234/98102-1234 as 0.0, UKPostcodeComparator scores sw1a1aa/SW1A 1AA as 1.0, and the page's Address model scores 1.0. docs/check_links.py passes. Docs only, so no test changes.

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

The Postal Codes guide opened with "Stickler compares postal codes exactly".
That holds only for stickler.evaluate and from_pydantic, whose inference picks
ExactComparator for zip, zip_code, postal_code, postcode and postal. A
hand-authored StructuredModel field or a JSON Schema string uses Levenshtein,
so 98101-1234 vs 98102-1234 scores 0.9 and matches. Name the path the claim
holds for and what the others do, and give both example comparators
DEFAULT_THRESHOLD = 1.0 as the Comparators guide asks.

Fixes awslabs#492

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@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 taking this on, and for checking each path before writing it down! The JSON Schema and hand-authored StructuredModel claims hold, and both example comparators now set DEFAULT_THRESHOLD as the Comparators guide asks; I reran your numbers on this branch and got the same results.

Must fix

The first sentence is wrong for a StructuredModel passed to stickler.evaluate (docs/docs/Guides/Comparators/postal-codes.md:7-12). stickler.evaluate uses a StructuredModel as configured and infers nothing (src/stickler/auto/facade.py:292), so passing instances of

class Address(StructuredModel):
    zip_code: str

scores "98101-1234" vs "98102-1234" as 0.9 and matched=True (measured against this branch). A from_json_schema model passed to evaluate does the same. That is the trap this page warns about, and the "Anywhere else" sentence overlaps with the first, so a reader on this path gets two answers. This gap was already in the wording proposed on the issue, so it is not something you introduced. I left suggestions inline that say "plain Pydantic BaseModel" and name the StructuredModel case, for the page and for the CHANGELOG line (CHANGELOG.md:24-26), which has the same gap.

Smaller

  • Optional: the name rule matches whole words in the field name, not just the five names (src/stickler/auto/inference.py:232). billing_zip, zipCode and ShippingPostalCode are exact too, while single-word zipcode and postalcode fall back to edit distance (0.9 on 98101-1234 vs 98102-1234, measured against this branch). Worth a clause if you want the list to read as the rule.
  • Optional: ZipLookupComparator (postal-codes.md:132) returns 0 or 1 like the other two, so it could take DEFAULT_THRESHOLD = 1.0 for consistency. It changes no score.

Happy to approve once the first sentence is qualified; the two optional ones are up to you.

Also:

  • docs/docs/Guides/Comparators/postal-codes.md:132: Same shape as the two above (returns 0 or 1), so this one could take DEFAULT_THRESHOLD = 1.0 too. No score changes; it just matches the guide's advice.

Comment on lines +7 to +12
With `stickler.evaluate`, a field named `zip`, `zip_code`, `postal_code`,
`postcode` or `postal` is compared **exactly**: `"98101-1234"` does not match
`"98101 1234"`, and `"98101"` does not match `"98101-1234"`. Anywhere else (a
`StructuredModel` field without a comparator, or a JSON Schema `string`) it is
compared by edit distance, so `"98101-1234"` matches `"98102-1234"`, a
different code. Either way, name a comparator for your country.

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.

stickler.evaluate keeps a StructuredModel's own configuration, so this sentence is only true for a plain Pydantic BaseModel. Suggest:

Suggested change
With `stickler.evaluate`, a field named `zip`, `zip_code`, `postal_code`,
`postcode` or `postal` is compared **exactly**: `"98101-1234"` does not match
`"98101 1234"`, and `"98101"` does not match `"98101-1234"`. Anywhere else (a
`StructuredModel` field without a comparator, or a JSON Schema `string`) it is
compared by edit distance, so `"98101-1234"` matches `"98102-1234"`, a
different code. Either way, name a comparator for your country.
With `stickler.evaluate` on a plain Pydantic `BaseModel`, a field named `zip`,
`zip_code`, `postal_code`, `postcode` or `postal` is compared **exactly**:
`"98101-1234"` does not match `"98101 1234"`, and `"98101"` does not match
`"98101-1234"`. On a `StructuredModel`, even one passed to `stickler.evaluate`,
a field without a comparator is compared by edit distance, and so is a JSON
Schema `string`: `"98101-1234"` matches `"98102-1234"`, a different code.
Either way, name a comparator for your country.

Comment thread CHANGELOG.md Outdated
Comment on lines +24 to +26
- The Postal Codes guide now says postal codes are compared exactly only with
`stickler.evaluate`, and by edit distance on a hand-authored `StructuredModel`
or a JSON Schema `string` ([#492](https://github.com/awslabs/stickler/issues/492)).

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.

Same qualifier here, since a hand-authored StructuredModel passed to stickler.evaluate is compared by edit distance:

Suggested change
- The Postal Codes guide now says postal codes are compared exactly only with
`stickler.evaluate`, and by edit distance on a hand-authored `StructuredModel`
or a JSON Schema `string` ([#492](https://github.com/awslabs/stickler/issues/492)).
- The Postal Codes guide now says postal codes are compared exactly only when
`stickler.evaluate` gets a plain Pydantic `BaseModel`, and by edit distance on
a `StructuredModel` field without a comparator (even one passed to
`stickler.evaluate`) or a JSON Schema `string`
([#492](https://github.com/awslabs/stickler/issues/492)).

@vawsgit vawsgit 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.

needs changes

There is one blocker: the new opening sentence says when postal codes are compared exactly, and it gets that wrong. I reproduced the gap that @sromoam raised, and I agree with his suggested rewording.

Needs changes

  1. docs/docs/Guides/Comparators/postal-codes.md:7-12. The page says stickler.evaluate compares zip, zip_code, postal_code, postcode and postal exactly. That holds only for a plain Pydantic BaseModel. When evaluate gets a StructuredModel, it uses the model's own configuration and infers nothing (facade.py:292). "Anywhere else … edit distance" is also wrong for eval_for and from_pydantic on a plain BaseModel, because both of those compare exactly. Apply the inline suggestion on line 12.
  2. CHANGELOG.md:24-26. The bullet says the same thing ("exactly only with stickler.evaluate"). Apply the inline suggestion on line 26.

Measured on this branch (97cc765), with stickler imported from the PR worktree's src/, comparing "98101-1234" with "98102-1234" (overall_score, matched):

evaluate, plain BaseModel:                    0.0 False
evaluate, StructuredModel, bare str:          0.9 True
evaluate, StructuredModel, ComparableField(): 0.9 True
evaluate, from_json_schema model:             0.9 True
eval_for, plain BaseModel:                    0.0 False
from_pydantic, compare_with:                  {'zip_code': 0.0}

Verified

  • The PR body's numbers reproduce. ComparableField(), a bare str and from_json_schema each give {'zip_code': 0.9}. evaluate on a plain BaseModel gives 0.0 with matched=False. "98101-1234" vs "98101 1234" and "98101" vs "98101-1234" both give 0.0 on that path.
  • DEFAULT_THRESHOLD = 1.0 on USZipComparator and UKPostcodeComparator is the class attribute that BaseComparator.__init__ reads, and both instances report threshold 1.0. USZipComparator gives 1.0, 0.0 and 0.0 on the page's three pairs. UKPostcodeComparator gives 1.0 on sw1a1aa vs SW1A 1AA. The page's Address model scores 1.0 on a formatting-only difference and 0.0 on a different code. ComparableField(comparator=USZipComparator()) raises no warning under -W error::UserWarning.
  • The CHANGELOG bullet is under [Unreleased] / ### Fixed, next to the #478 docs fix.
  • The branch merges cleanly into current dev (git merge-tree).
  • uv run python docs/check_links.py exits 0.
  • pytest -k "comparator or auto or inference or postal or doc" gives 1391 passed, 9 skipped and 1 xfailed.
  • Fixes #492 is the right keyword once the first sentence is qualified, because the issue then has nothing left.

Optional, and not blocking: the name rule matches whole words. billing_zip, zipCode and ShippingPostalCode compare exactly. zipcode and postalcode fall back to edit distance (0.9, matched=True). ZipLookupComparator could also take DEFAULT_THRESHOLD = 1.0. Both points are in sromoam's review.

Comment on lines +7 to +12
With `stickler.evaluate`, a field named `zip`, `zip_code`, `postal_code`,
`postcode` or `postal` is compared **exactly**: `"98101-1234"` does not match
`"98101 1234"`, and `"98101"` does not match `"98101-1234"`. Anywhere else (a
`StructuredModel` field without a comparator, or a JSON Schema `string`) it is
compared by edit distance, so `"98101-1234"` matches `"98102-1234"`, a
different code. Either way, name a comparator for your country.

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.

needs changes: stickler.evaluate on a StructuredModel (hand-written or from_json_schema) uses edit distance. On this branch, "98101-1234" vs "98102-1234" scores 0.9 with matched=True. eval_for and from_pydantic on a plain BaseModel compare exactly, so "Anywhere else … edit distance" is wrong too. Apply sromoam's suggestion on this line. It limits the exact claim to a plain Pydantic BaseModel and names the StructuredModel case.

Comment thread CHANGELOG.md Outdated
Comment on lines +24 to +26
- The Postal Codes guide now says postal codes are compared exactly only with
`stickler.evaluate`, and by edit distance on a hand-authored `StructuredModel`
or a JSON Schema `string` ([#492](https://github.com/awslabs/stickler/issues/492)).

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.

needs changes: this bullet repeats the claim from postal-codes.md:7-12. A hand-authored StructuredModel passed to stickler.evaluate is compared by edit distance (0.9, matched=True). Apply sromoam's suggestion on this line.

…odel

Merge dev (keep its LLMComparator Fixed bullet first) and apply the
review wording: stickler.evaluate compares the five postal field names
exactly only on a plain Pydantic BaseModel. A StructuredModel, even one
passed to stickler.evaluate, keeps edit distance for a field without a
comparator, as does a JSON Schema string. Say the same in the CHANGELOG
bullet, and give ZipLookupComparator DEFAULT_THRESHOLD = 1.0 like the
other two examples.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@WilliamK112

Copy link
Copy Markdown
Contributor Author

Thanks @sromoam and @vawsgit. Pushed 95d6698:

I left the whole-word name rule out to keep the page short; happy to add a clause if you'd like it.

@vawsgit vawsgit 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.

✅ LGTM!

Both findings from my previous review are fixed at 95d6698. I found no new medium or high issues.

Previous findings

  1. Fixed: the opening sentence of postal-codes.md. Lines 7-13 now say postal codes are compared exactly only when stickler.evaluate gets a plain Pydantic BaseModel. They say that a StructuredModel field without a comparator, even one passed to evaluate, is compared by edit distance, and so is a JSON Schema string. This matches facade.py:292. The wrong sentence "anywhere else … edit distance" is gone, so the page no longer contradicts eval_for or from_pydantic.
  2. Fixed: the CHANGELOG.md bullet. Lines 34-38 use sromoam's suggested wording.

Verified

Measured at 95d6698, with stickler imported from the PR worktree's src/. The pair is "98101-1234" vs "98102-1234" (overall_score, matched). The numbers are the same as in my previous round. The page now describes them correctly.

evaluate, plain BaseModel:                    0.0 False
evaluate, StructuredModel, bare str:          0.9 True
evaluate, StructuredModel, ComparableField(): 0.9 True
evaluate, from_json_schema model:             0.9 True
eval_for, plain BaseModel:                    0.0 False
from_pydantic, compare_with:                  {'zip_code': 0.0}
  • Each of the five names (zip, zip_code, postal_code, postcode, postal) scores 0.0 on a plain BaseModel through evaluate, for the formatting pair, the 5-digit vs ZIP+4 pair and the different-code pair. explain() reports ExactComparator for each. On a StructuredModel with no comparator, the different-code pair scores 0.9 with matched=True.
  • LevenshteinComparator scores 0.9 on both the formatting pair and the different-code pair, as the page's example says.
  • USZipComparator, UKPostcodeComparator and ZipLookupComparator each report threshold 1.0. The page's Address model scores 1.0 on a formatting difference and 0.0 on a different code. No UserWarning is raised.
  • uv run python docs/check_links.py exits 0.
  • uv run --extra dev pytest -k "comparator or auto or inference or postal or doc": 1779 passed, 9 skipped, 1 xfailed.
  • The diff against dev touches only CHANGELOG.md and postal-codes.md. git merge-tree against current origin/dev (c70ca6e) merges cleanly. After the merge, the bullet sits under [Unreleased] / ### Fixed.
  • Fixes #492 is the right keyword: the guide now covers everything the issue asks for.

Optional, not blocking

  • The CHANGELOG bullet says "exactly only when stickler.evaluate gets a plain Pydantic BaseModel". eval_for and from_pydantic on a plain BaseModel also compare exactly. The guide page is correct, so this is not a blocker.
  • dev now has a ### Documentation subsection under [Unreleased]. This bullet could move there, but the #478 docs bullet under ### Fixed follows the same pattern.

@github-actions

Copy link
Copy Markdown

Security Scan Results

ASH Security Scan Report

  • Report generated: 2026-11-18T23:47:16+00:00
  • Time since scan: 3 minutes

Scan Metadata

  • Project: ASH
  • Scan executed: 2026-11-18T23:44:02+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-18T23:47:17+00:00

@digalaviz
digalaviz merged commit 9fc70de into awslabs:dev Nov 18, 2026
11 checks passed
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.

Qualify "Stickler compares postal codes exactly": it holds only for stickler.evaluate

4 participants