Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
e364b7a
fix(importers): resolve unstated threshold and clip as the Python pat…
sromoam Oct 15, 2026
adbda67
fix(importers): credit a zero threshold to the comparator only when i…
sromoam Oct 16, 2026
3637981
Merge origin/dev into fix/334-348-importer-defaults
sromoam Oct 28, 2026
530e77f
test: pin the free-form clip default from #334 in the extension refer…
sromoam Oct 28, 2026
ede3216
Merge remote-tracking branch 'origin/dev' into m408
sromoam Oct 29, 2026
60703e0
fix(334): name an adopted comparator threshold in the explain() trail
sromoam Oct 29, 2026
626f6dd
fix(348): resolve comparator keys on a nested model as the Python pat…
sromoam Oct 29, 2026
7dfab62
docs(348): document the nested-model comparator warning and the new d…
sromoam Oct 29, 2026
83f1556
docs(348): say the nested-object default threshold is fixed, not the …
sromoam Oct 30, 2026
6e51532
fix(348): plural warning verbs, keep ValueError for a list comparator…
sromoam Oct 30, 2026
fe8b830
Merge origin/dev into fix/334-348-importer-defaults
sromoam Nov 17, 2026
c6878eb
fix(importers): check an adopted comparator threshold and resolve nes…
sromoam Nov 17, 2026
2934248
docs(importers): state the threshold and clip defaults the importers …
sromoam Nov 17, 2026
dad0ca9
fix(importers): load a comparator that requires threshold on an array…
sromoam Nov 17, 2026
f7a4640
test(importers): pin the union, nested-warning and explain() behaviou…
sromoam Nov 17, 2026
1caa1cb
docs(importers): correct the free-form clip, nested comparator and wa…
sromoam Nov 17, 2026
ff19b01
docs(importers): scope the free-form clip claim to each object, and n…
sromoam Nov 17, 2026
a7ab802
docs(thresholds): state that an invalid field threshold raises, on ev…
sromoam Nov 17, 2026
09dcedd
fix(thresholds): raise on a field threshold that is not a number from…
sromoam Nov 17, 2026
a17802c
test(thresholds): pin the raise for an invalid field threshold on eve…
sromoam Nov 17, 2026
4f0fb4a
docs(thresholds): one message per path, int or float only, match_thre…
sromoam Nov 17, 2026
f5ad746
fix(thresholds): check Annotated fields, quote values as written, no …
sromoam Nov 17, 2026
3991537
test(thresholds): pin the per-path messages, Annotated, postponed ann…
sromoam Nov 17, 2026
be9b0b0
fix(thresholds): load an in-range Decimal, Fraction or numpy threshol…
sromoam Nov 17, 2026
d78cb3c
fix(thresholds): give every threshold message a fix, and the list ref…
sromoam Nov 17, 2026
526061b
fix(thresholds): check a forward-referenced field when the class is d…
sromoam Nov 17, 2026
7aa8375
docs(thresholds): a number from 0.0 to 1.0, on the class, config and …
sromoam Nov 17, 2026
55e4023
fix(thresholds): keep the runtime match_threshold check of evaluate()…
sromoam Nov 17, 2026
1654b58
fix(thresholds): check forward-referenced lists, keep numpy verdicts,…
sromoam Nov 17, 2026
32febb2
fix(importers): name a titled schema's model in its warnings, and say…
sromoam Nov 17, 2026
89b7e07
docs(thresholds): scope the runtime check, forward-referenced lists, …
sromoam Nov 17, 2026
9794614
docs(thresholds): a bare alias name for a list is ignored once resolv…
sromoam Nov 17, 2026
9d4a8a5
chore: merge origin/dev into fix/334-348-importer-defaults
sromoam Nov 17, 2026
0cad533
fix(thresholds): check an Annotated field whose type is defined furth…
sromoam Nov 17, 2026
4e59553
docs(thresholds): numpy float16 and float32 compare as Python floats,…
sromoam Nov 17, 2026
f7c7782
fix(auto): a runtime match_threshold=False does not warn that the thr…
sromoam Nov 17, 2026
60cc3a2
fix(thresholds): correct the threshold messages whose advice was wron…
sromoam Nov 17, 2026
d77fb56
docs(thresholds): scope the numpy, runtime, class match_threshold and…
sromoam Nov 17, 2026
e9228d7
fix(thresholds): evaluate Annotated metadata as pydantic does, once p…
sromoam Nov 17, 2026
44d21f9
fix(thresholds): a list-of-models message no longer tells an element …
sromoam Nov 17, 2026
96f5567
fix(thresholds): an unresolved dict or tuple gets the usual fix, and …
sromoam Nov 17, 2026
c4612ba
docs(thresholds): scope the Python list warning, name match_threshold…
sromoam Nov 17, 2026
9b2b5a9
docs(changelog): rewrap the threshold-rule paragraph
sromoam Nov 17, 2026
3a18858
test(thresholds): pin that a numpy float16 or float32 match_threshold…
sromoam Nov 17, 2026
cb26400
test(thresholds): drop the postponed Annotated case from the dict-or-…
sromoam Nov 17, 2026
8ce3b28
Revert "fix(thresholds): evaluate Annotated metadata as pydantic does…
sromoam Nov 17, 2026
5d85b9b
Revert "fix(thresholds): check an Annotated field whose type is defin…
sromoam Nov 17, 2026
605ea32
docs(thresholds): an Annotated field written as a string that names s…
sromoam Nov 17, 2026
a5230d5
fix(thresholds): a class loads when the working directory no longer e…
sromoam Nov 18, 2026
d86e94e
docs(importers): a threshold a custom comparator's constructor sets i…
sromoam Nov 18, 2026
43579b1
docs(thresholds): scope the Annotated, numpy float64 and array-sentin…
sromoam Nov 18, 2026
2b8d1b0
fix(evaluate): a runtime match_threshold of any real type in range is…
sromoam Nov 18, 2026
f7149a4
docs(thresholds): scope the Set at, None and unread-key claims
sromoam Nov 18, 2026
a93086a
docs(changelog): give the TP-to-FD example for a comparator's constru…
sromoam Nov 18, 2026
726726f
ci(thresholds): mark the test's exec calls reviewed, and skip the mad…
sromoam Nov 18, 2026
f0800a4
Merge origin/dev into fix/334-348-importer-defaults
sromoam Nov 23, 2026
b78859f
test(thresholds): patch in the NaN threshold the report test needs
sromoam Nov 23, 2026
e7ccbdc
test(thresholds): name the bool match_threshold test for the refusal …
sromoam Nov 23, 2026
619b714
fix(importers): name the model in the nested-model warnings as the er…
sromoam Nov 23, 2026
006f558
Merge dev into fix/334-348-importer-defaults
sromoam Nov 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
docs(thresholds): an Annotated field written as a string that names s…
…omething defined later is not yet checked

With 0cad533 and e9228d7 reverted, an Annotated annotation pydantic
holds as one string (quoted whole, or under `from __future__ import
annotations`) because its type or a value in its ComparableField(...) is
defined further down loads unchecked at class definition, as on dev.

- CHANGELOG Python bullet, Comparators guide and thresholds-and-metrics:
  say so where they say an Annotated field and a field whose type is
  defined further down are checked. This replaces the "`Annotated` fields
  included" of d77fb56.
- thresholds-and-metrics: the list-of-models comparator warning needs an
  annotation that is already a list when the class is defined, written
  out or through an assigned alias.
- Module README and the _check_field_thresholds docstring: drop the
  description of the reverted metadata evaluation (4e59553, c4612ba) and
  say such a field is not yet checked.
  • Loading branch information
sromoam committed Nov 17, 2026
commit 605ea329352aea0842b5ef441f4283d6b2939dd0
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ Each release links to full notes on the
attribute, also as `ModelFactory.create_model_from_fields(match_threshold=...)`.
None was checked: a field threshold of 85 scored an identical pair 0.0
FD, and a class `match_threshold` of 85 made every list pair of that
class an FD.
class an FD. An `Annotated` field that names something defined further
down, its type or a value in its `ComparableField(...)`, is not yet
checked at class definition when its annotation is a string, as every
annotation is under `from __future__ import annotations`.
- Stickler config: `"threshold"`, an adopted `"comparator_config"`
threshold, and `"match_threshold"` on the model or a nested-model field.
- JSON Schema: `x-aws-stickler-threshold`, an adopted
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/Getting-Started/thresholds-and-metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ Anything else, such as `85`, `1.5`, `-1`, `"0.9"`, `true`, NaN or infinity, rais
ValueError: Invalid threshold for field 'vendor' of model 'Invoice': ComparableField sets no threshold, so the field adopts its comparator's: LevenshteinComparator(threshold=85). A threshold is the minimum similarity score for a match, from 0.0 to 1.0. 85 is above 1.0, so even identical values would not match. If 85 is a percentage, write LevenshteinComparator(threshold=0.85), or ComparableField(threshold=0.85), which wins over the comparator's. (Set at invoice_models.py:6.)
```

A comparator threshold the field does not adopt is not checked: when the field sets its own, the comparator's is not read, and on a `List[StructuredModel]` field (an array of objects in a schema) it is never used, since its items are matched up using `match_threshold`, so it warns instead. On the Python path the warning needs the list written out, as in `items: List[Item] = ComparableField(...)`: inside `Annotated[...]`, through a `type` alias, or as a string, which includes every annotation under `from __future__ import annotations`, the field loads with no warning. A field threshold on a list of models that breaks the rule raises, and the message says to remove it and use `match_threshold`. A comparator's constructor never checks its threshold, since a custom comparator may use `threshold` for something else, and the comparator keeps the value you passed. The runtime `match_threshold` of `evaluate()` and `eval_for()` is outside this rule; see [Runtime Match Threshold](#4-runtime-match-threshold).
A comparator threshold the field does not adopt is not checked: when the field sets its own, the comparator's is not read, and on a `List[StructuredModel]` field (an array of objects in a schema) it is never used, since its items are matched up using `match_threshold`, so it warns instead. On the Python path the warning needs an annotation that is already a list when the class is defined, written out (`items: List[Item] = ComparableField(...)`) or through an assigned alias (`ItemList = List[Item]`): inside `Annotated[...]`, through a `type` alias, or as a string, which includes every annotation under `from __future__ import annotations`, the field loads with no warning. A field threshold on a list of models that breaks the rule raises, and the message says to remove it and use `match_threshold`. A comparator's constructor never checks its threshold, since a custom comparator may use `threshold` for something else, and the comparator keeps the value you passed. The runtime `match_threshold` of `evaluate()` and `eval_for()` is outside this rule; see [Runtime Match Threshold](#4-runtime-match-threshold).

A field whose type is defined further down the module, `Annotated` fields included, is checked when the class is defined, before that type exists, so stickler reads the field as adopting its comparator's threshold. Only a list of models does not, so there, and on a bare name for a list of models (`items: "ItemList"`, with `ItemList = List[Item]` below), an invalid comparator threshold raises, though the field would ignore it once resolved. When the annotation is visibly a list (`List["Item"]`), the message says to remove the comparator if the element is a model. An invalid field threshold on such a field, or on a bare name, gets a fix for each case: a list of models, and anything else.
A field whose type is defined further down the module is checked when the class is defined, before that type exists, so stickler reads the field as adopting its comparator's threshold. Only a list of models does not, so there, and on a bare name for a list of models (`items: "ItemList"`, with `ItemList = List[Item]` below), an invalid comparator threshold raises, though the field would ignore it once resolved. When the annotation is visibly a list (`List["Item"]`), the message says to remove the comparator if the element is a model. An invalid field threshold on such a field, or on a bare name, gets a fix for each case: a list of models, and anything else. An `Annotated` field that names something defined further down, its type or a value in its `ComparableField(...)`, is not yet checked at class definition when its annotation is a string, as every annotation is under `from __future__ import annotations`: pydantic builds its `ComparableField` only on `model_rebuild()`, so an invalid threshold there loads.

## Meeting a Threshold

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/Guides/Comparators/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Precedence is field, then comparator, then `0.5`:

The third row is the one to know: a comparator's *default* threshold is never adopted. Those defaults were chosen for `binary_compare()`, not as classification cutoffs, and at least one is actively wrong for the job. `DateComparator` defaults to `1.0` while awarding `0.7` partial credit for a match with no year, so adopting it would clip that feature to zero. If you want a comparator's default to act as the cutoff, name it.

Whichever threshold the field uses must be a number from 0.0 to 1.0, or defining the class raises `ValueError`, also for a field declared as `Annotated[str, ComparableField(...)]` or one whose type is defined further down the module:
Whichever threshold the field uses must be a number from 0.0 to 1.0, or defining the class raises `ValueError`, also for a field declared as `Annotated[str, ComparableField(...)]` or one whose type is defined further down the module. An `Annotated` field that names something defined further down, its type or a value in its `ComparableField(...)`, is not yet checked at class definition when its annotation is a string, as every annotation is under `from __future__ import annotations`. The message reads:

```text
ValueError: Invalid threshold for field 'vendor' of model 'Invoice': ComparableField sets no threshold, so the field adopts its comparator's: LevenshteinComparator(threshold=85). A threshold is the minimum similarity score for a match, from 0.0 to 1.0. 85 is above 1.0, so even identical values would not match. If 85 is a percentage, write LevenshteinComparator(threshold=0.85), or ComparableField(threshold=0.85), which wins over the comparator's. (Set at invoice_models.py:6.)
Expand Down
11 changes: 5 additions & 6 deletions src/stickler/structured_object_evaluator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,12 +328,11 @@ annotations` are covered; `ComparableField` does not know the model or the field
records its call site for the message. A field whose annotation is still a forward reference then
is checked as adopting its comparator's threshold, even when it is visibly a list (`List["Item"]`),
since stickler cannot tell yet whether the element is a model and nothing re-checks it once it
resolves. pydantic holds an `Annotated` annotation it cannot resolve as one string, so only its
metadata is evaluated to find the `ComparableField` (`_string_annotated_extra`), as pydantic
evaluates the class's own annotations: the class body, then the `class` statement's namespace and
module (`_class_namespace`). A subclass does not evaluate an inherited field again. That message
gives the `class` line. A PEP 695 alias is read as the
type it names once the type it names is defined; before that, it is checked as adopting.
resolves. An `Annotated` annotation that names something defined further down, its type or a value
in its metadata, is not yet checked at class definition when it is a string (quoted whole, or under
`from __future__ import annotations`): pydantic holds it as one string until `model_rebuild()`, so
its `ComparableField` does not exist yet. A PEP 695 alias is read as the type it names once the
type it names is defined; before that, it is checked as adopting.
The importers check the same rule on load, with the shared message from `threshold_rule`. A
comparator threshold the field overrides, or one on a resolved `List[StructuredModel]` field, is not
checked. The runtime `match_threshold` is outside the rule: for a plain pydantic model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,13 @@ def _check_field_thresholds(cls) -> None:
only the fix for a field that adopts. A PEP 695 alias is
read as the type it names once the type it names is defined; before
that, it is checked as adopting.

An ``Annotated`` annotation that names something defined further down,
its type or a value in its metadata, is not yet checked when it is a
string (quoted whole, or under ``from __future__ import annotations``):
pydantic holds it as one string until ``model_rebuild()``, so its
``ComparableField`` does not exist yet and ``json_schema_extra`` is
empty here.
"""
for field_name, field_info in cls.model_fields.items():
if field_name == _EXTRA_FIELDS_KEY:
Expand Down