Repository navigation
docs(comparators): say which path compares postal codes exactly - #586
Conversation
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
left a comment
There was a problem hiding this comment.
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: strscores "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,zipCodeandShippingPostalCodeare exact too, while single-wordzipcodeandpostalcodefall back to edit distance (0.9 on98101-1234vs98102-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 takeDEFAULT_THRESHOLD = 1.0for 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.0too. No score changes; it just matches the guide's advice.
| 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. |
There was a problem hiding this comment.
stickler.evaluate keeps a StructuredModel's own configuration, so this sentence is only true for a plain Pydantic BaseModel. Suggest:
| 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. |
| - 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)). |
There was a problem hiding this comment.
Same qualifier here, since a hand-authored StructuredModel passed to stickler.evaluate is compared by edit distance:
| - 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
left a comment
There was a problem hiding this comment.
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
docs/docs/Guides/Comparators/postal-codes.md:7-12. The page saysstickler.evaluatecompareszip,zip_code,postal_code,postcodeandpostalexactly. That holds only for a plain PydanticBaseModel. Whenevaluategets aStructuredModel, it uses the model's own configuration and infers nothing (facade.py:292). "Anywhere else … edit distance" is also wrong foreval_forandfrom_pydanticon a plainBaseModel, because both of those compare exactly. Apply the inline suggestion on line 12.CHANGELOG.md:24-26. The bullet says the same thing ("exactly only withstickler.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 barestrandfrom_json_schemaeach give{'zip_code': 0.9}.evaluateon a plainBaseModelgives 0.0 withmatched=False."98101-1234"vs"98101 1234"and"98101"vs"98101-1234"both give 0.0 on that path. DEFAULT_THRESHOLD = 1.0onUSZipComparatorandUKPostcodeComparatoris the class attribute thatBaseComparator.__init__reads, and both instances reportthreshold1.0.USZipComparatorgives 1.0, 0.0 and 0.0 on the page's three pairs.UKPostcodeComparatorgives 1.0 onsw1a1aavsSW1A 1AA. The page'sAddressmodel 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.pyexits 0.pytest -k "comparator or auto or inference or postal or doc"gives 1391 passed, 9 skipped and 1 xfailed.Fixes #492is 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.
| 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. |
There was a problem hiding this comment.
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.
| - 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)). |
There was a problem hiding this comment.
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>
|
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
left a comment
There was a problem hiding this comment.
✅ LGTM!
Both findings from my previous review are fixed at 95d6698. I found no new medium or high issues.
Previous findings
- Fixed: the opening sentence of
postal-codes.md. Lines 7-13 now say postal codes are compared exactly only whenstickler.evaluategets a plain PydanticBaseModel. They say that aStructuredModelfield without a comparator, even one passed toevaluate, is compared by edit distance, and so is a JSON Schemastring. This matchesfacade.py:292. The wrong sentence "anywhere else … edit distance" is gone, so the page no longer contradictseval_fororfrom_pydantic. - Fixed: the
CHANGELOG.mdbullet. 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 plainBaseModelthroughevaluate, for the formatting pair, the 5-digit vs ZIP+4 pair and the different-code pair.explain()reportsExactComparatorfor each. On aStructuredModelwith no comparator, the different-code pair scores 0.9 withmatched=True. LevenshteinComparatorscores 0.9 on both the formatting pair and the different-code pair, as the page's example says.USZipComparator,UKPostcodeComparatorandZipLookupComparatoreach report threshold 1.0. The page'sAddressmodel scores 1.0 on a formatting difference and 0.0 on a different code. NoUserWarningis raised.uv run python docs/check_links.pyexits 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
devtouches onlyCHANGELOG.mdandpostal-codes.md.git merge-treeagainst currentorigin/dev(c70ca6e) merges cleanly. After the merge, the bullet sits under[Unreleased]/### Fixed. Fixes #492is the right keyword: the guide now covers everything the issue asks for.
Optional, not blocking
- The CHANGELOG bullet says "exactly only when
stickler.evaluategets a plain PydanticBaseModel".eval_forandfrom_pydanticon a plainBaseModelalso compare exactly. The guide page is correct, so this is not a blocker. devnow has a### Documentationsubsection under[Unreleased]. This bullet could move there, but the #478 docs bullet under### Fixedfollows the same pattern.
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-18T23:47:17+00:00 |
Issue #, if available: Fixes #492
Description of changes:
Guides/Comparators/postal-codes.mdopened with "Stickler compares postal codes exactly". That holds only on the inference path. WithComparableField(), a bare annotation or a JSON Schemastring, a postal code is Levenshtein, so a different code can match. This PR:stickler.evaluateon a plain PydanticBaseModelcompareszip,zip_code,postal_code,postcodeandpostalexactly; aStructuredModel(even one passed tostickler.evaluate) without a comparator, or a JSON Schemastring, uses edit distance; name a comparator either way. The wording is the reviewers' suggestion, and the next paragraph is rewrapped to fit;DEFAULT_THRESHOLD = 1.0toUSZipComparator,UKPostcodeComparatorandZipLookupComparator, as the Comparators guide asks;### Fixedbullet under[Unreleased]inCHANGELOG.md.Checked on
devat 8c56dfa, withsticklerimported from that checkout'ssrc/:"98101-1234"vs"98102-1234"scores{'zip_code': 0.9}forComparableField(), a barestrannotation andfrom_json_schema, andmatched=False(0.0) throughstickler.evaluate. The two edited examples still run: both thresholds read 1.0,USZipComparatorscores98101-1234/98101 1234as 1.0 and98101-1234/98102-1234as 0.0,UKPostcodeComparatorscoressw1a1aa/SW1A 1AAas 1.0, and the page'sAddressmodel scores 1.0.docs/check_links.pypasses. 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