Skip to content
Open
Show file tree
Hide file tree
Changes from 59 commits
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
171 changes: 171 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,177 @@ Each release links to full notes on the

## [Unreleased]

### Changed

- **The Stickler-config and JSON Schema importers now resolve an unstated
`threshold` and `clip_under_threshold` as the documented Python path
(`ComparableField`) does.** Both importers filled in their
own defaults (0.5 and `true`) before building the field, so every imported
field read as "the author stated this", and the two defaults that key on that
were skipped. Verdicts move wherever a field relied on that:
- **A threshold named on the comparator reaches the field.**
`"comparator_config": {"threshold": 0.9}` (or
`x-aws-stickler-comparator-config`) with no field `threshold` gated at the
importer's own default instead (0.5 for a string), so a pair scoring 0.78
was a TP there and an FD in Python. It is 0.9 on all
three paths now. The same goes for a threshold a custom comparator's
constructor passes to `super().__init__()`, which
`ComparableField(comparator=...)` already adopted: a field that names that
comparator and no threshold moves from the importer's default, 0.5 or a
schema type default such as 1.0 for an enum, to that value. For a
registered comparator whose constructor passes `threshold=0.95`, a string
pair it scores 0.9 was a TP at 0.5 and is an FD at 0.95 now, as in
Python. No built-in
comparator passes one when built without a threshold, so fields naming
one do not move. A field threshold still wins, and a comparator threshold
outranks an inferred one. This includes a `structured_model` or
`optional_structured_model` field and an object with `properties`, where
`ComparableField(comparator=X(threshold=0.9))` also gates at 0.9; the
config path dropped it there and the schema path did too
([#334](https://github.com/awslabs/stickler/issues/334)). An adopted
comparator threshold is checked as a field threshold is; see the next item.
- **A threshold that is not a number from 0.0 to 1.0 raises `ValueError`

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.

This bullet announces new ValueErrors in the release that line 15 says ships no breaking changes. Once the raises become warnings, reword it as a warning that becomes an error in 1.1.0.

in 1.1.0 when the class is defined or the config or schema is loaded.**
This is a breaking change: some inputs that loaded on 1.0.x now raise
(listed below). It applies to the threshold the field ends up with, and to
`match_threshold`:
- Python: `ComparableField(threshold=...)`, also inside `Annotated[...]`
and on a field whose type is defined further down the module; a
comparator threshold the field adopts, such as
`LevenshteinComparator(threshold=85)`; and the `match_threshold` class
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. 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
`x-aws-stickler-comparator-config` threshold, and
`x-aws-stickler-match-threshold`.

`85`, `1.5`, `-1`, `"0.9"`, `true`, NaN and infinity all raise. These
inputs loaded on 1.0.x and raise in 1.1.0:
- `"threshold": true` in a config and `x-aws-stickler-threshold: true` in
a schema, which loaded as 1. Write `1.0`.
- `match_threshold = True` on a class, `"match_threshold": true` in a
config and `x-aws-stickler-match-threshold: true` in a schema, which
loaded as 1. Write `1.0`.
- An out-of-range value such as `85`, `1.5` or `-1` in
`ComparableField(threshold=...)` or a class `match_threshold`, which the
Python path never checked. The config and schema paths already refused
one in `"threshold"` and `"match_threshold"`. Write a number from 0.0 to
1.0, such as `0.85` for 85.
- A comparator constructor threshold that a field adopts because it sets
no threshold of its own, such as `LevenshteinComparator(threshold=85)`
in Python or `"comparator_config": {"threshold": 85}` in a config or
schema. The importers never read the config's value, so any value
loaded. A field whose type is defined further down the module also
raises on a list of models, where the comparator is never read.
- A custom comparator that reads `threshold` as a distance or a count
rather than a similarity score, such as `"comparator_config":
{"threshold": 5}` for an edit-distance comparator. The field now adopts
5 and raises.

For a comparator threshold, set the field's own `threshold`
(`ComparableField(threshold=...)`, `"threshold"` or
`x-aws-stickler-threshold`). It wins over the comparator's, which is then
neither adopted nor checked, and the comparator keeps the value it was
given. A `Decimal`,
`Fraction`, numpy number or 0-d numpy array from 0.0 to 1.0 now loads on
every path, converted with `float()`; the comparator keeps the value it
was given. A numpy float16 or float32 threshold or `match_threshold` is
then compared as a Python float, not in its own dtype, so a score within
its rounding below the threshold is an FD where it was a TP. Python kept
such a value unconverted, so a `Decimal` raised `TypeError` on a pair
scoring below it. The importers refused it, except a numpy float64, which
is a `float` subclass and loaded unconverted. The `match_threshold`
passed to `evaluate()` or `eval_for()` is outside this rule: for a plain
pydantic model it keeps its own check and message, now on every call, and
for a `StructuredModel` it is not checked. On a plain model it now also
takes any other real number from 0.0 to 1.0, such as a `Decimal`, a
`Fraction` or a numpy `int64` or `float32`, converted with `float()`;
before, one raised unless an equal value had reached the class first.
`True` and `False` still count as 1.0 and 0.0. Every path gives one
message. It quotes the value as written, names the model and the field,
says why the value fails and gives the fix in full; on the Python path it
ends with where the value was set, though a base class that overrides
`__init_subclass__` can make a `match_threshold` point at the line of
that override. The refusal of `ComparableField(threshold=...)`
on a `List[StructuredModel]` field uses the same template, says to remove
it and names the element class, and is headed `Unused threshold` whatever
its value. The warning for a comparator threshold there names the model
and the element class, and points at the class rather than at
`<frozen abc>`, or at a base class's `__init_subclass__` if it overrides
one. On the config path it is no longer prefixed
`Invalid field configuration:` or
`Error converting field configurations:`, and a field inside a
`list_structured_model` is named `items[].sku` there and in warnings, as
on the schema path:

```text
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: one a field
threshold overrides, or one on a list of models, which matches its items
on `match_threshold`. A field whose type is defined further down the
module is read as adopting, since stickler cannot tell yet whether it is a
list of models, so there an invalid comparator threshold raises even on a
list of models. `to_stickler_config()` leaves an out-of-range comparator
threshold off a `list_structured_model` field, so the export reloads.
- **A mapping field keeps its partial credit.** A `dict` field naming a
comparator, or a list of them, defaulted to `clip_under_threshold: true`,
so ANLS\* partial credit below the threshold was zeroed: 0.0 where Python
reports 0.3333 for two of three keys wrong. It now defaults to `false` on
both importers, as it does in Python; an explicit `true` is still honoured
([#348](https://github.com/awslabs/stickler/issues/348)).

Any other field that states neither is unchanged. The schema path's
free-form object default (`ExactComparator` at 1.0, #348 item 1) is unchanged
too, except that its `clip_under_threshold` now reads `false`; Exact scores
0 or 1, so its scores do not move. `explain()` names an adopted comparator
threshold in `why` (`config: comparator_config.threshold=0.9 (overrides
above)`), as it already named a field `threshold`. The schema path named
neither and now names both, along with `-weight` and `-clip-under-threshold`
overrides.

### Fixed

- **A comparator key on a nested model now warns instead of being dropped in
silence or refused.** A nested model is scored field by field, so its
comparator is never called, as on the Python path. `comparator` on a
`structured_model` or `optional_structured_model` field raised, and
`comparator_config` there, or on a `list_structured_model` field, was dropped
in silence; on the schema path `x-aws-stickler-comparator` and
`-comparator-config` on an object with `properties` were dropped, and on an
array of objects the config's `threshold` was reported by `explain()` as the
field's explicit threshold though nothing read it. Every such key that is
written on a field or a property and not read now emits a `UserWarning`
naming it, the model, and where the effective setting goes (`threshold` /
`x-aws-stickler-threshold` on an object, `match_threshold` /
`x-aws-stickler-match-threshold` on a list). The model is named as the
threshold errors name it: by its `model_name`, `x-aws-stickler-model-name`
or `title`, or else as an unnamed model, with the key that names one. On a
`$defs` definition that a property references, they are still ignored
without a warning; beside the `$ref`, they are treated as on any property.
A threshold
the comparator names on a single nested model, in its config or its own
constructor, is read (see Changed), and the warning gives its value. A named
comparator stays on the field, as on the Python path, so `explain()` reports
it rather than a placeholder `LevenshteinComparator`. A threshold that
comparator names on a single nested model is now checked, so one that is
not a number from 0.0 to 1.0 raises in 1.1.0 where the importers dropped it
on 1.0.x (see Changed). `comparator` on a `list_structured_model` field, and
`"auto"` on any nested model, still raise. A property that is a union of
objects (`anyOf` or `oneOf` whose arms declare `properties`) is not covered:
as on the Python path for a `Union` field, a comparator-config threshold
gates it, and a named comparator is installed and never called, with no
nested-model warning
([#348](https://github.com/awslabs/stickler/issues/348))

## [1.0.2] - 2026-11-20

### Changed
Expand Down
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,8 @@ even though the field on the built class ends up a plain `str` — read the choi

**Type:** `number` (0.0 to 1.0, inclusive)
**Required:** No
**Default:** position-dependent, not one number. `0.5` for a plain scalar, an array of plain
**Default:** a threshold named on the comparator, in `x-aws-stickler-comparator-config` or by a
custom comparator's constructor, unless the property is an array of models. Otherwise position-dependent, not one number. `0.5` for a plain scalar, an array of plain
scalars, and an array of models; `0.7` for an object with `properties`; `1.0` for a free-form
`{"type": "object"}` (or an array of them) and for any property or array `items` with `enum`,
`const`, or a string `format` of `date`/`date-time`/`uri`/`uuid`/`time`, whether or not a
Expand All @@ -355,6 +356,14 @@ comparator is declared. See the table in

Minimum similarity score required for binary match classification.

The threshold a property uses, this key or a `threshold` in `x-aws-stickler-comparator-config`,
must be a number from 0.0 to 1.0. Anything else, such as `85`, `"0.9"` or `true`, raises
`ValueError` on import:

```text
ValueError: Invalid threshold for field 'total_amount' of model 'Invoice': the field sets no "x-aws-stickler-threshold", so it adopts its comparator's: "x-aws-stickler-comparator-config": {"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 "x-aws-stickler-comparator-config": {"threshold": 0.85}, or "x-aws-stickler-threshold": 0.85 on the property, which wins over the comparator's.
```

**How Threshold Works:**
- Similarity score **≥ threshold** → Classified as **MATCH** (True Positive or True Negative)
- Similarity score **< threshold** → Classified as **NO MATCH** (False Positive or False Negative)
Expand Down Expand Up @@ -470,9 +479,9 @@ Relative importance of this field in aggregate scoring and weighted averages.

**Type:** `boolean`
**Required:** No
**Default:** `true`
**Default:** `true`, except `false` for a free-form `{"type": "object"}` or an array of them

Controls whether similarity scores below threshold are clipped to 0.0. Clipping is **on** unless you turn it off, so a field scoring just under its threshold reports `0.0` rather than its raw similarity.
Controls whether similarity scores below threshold are clipped to 0.0. Clipping is **on** for a scalar unless you turn it off, so a field scoring just under its threshold reports `0.0` rather than its raw similarity. A free-form object keeps the partial credit its comparator gives, such as `ANLSStarComparator`'s, unless you set `true`. The default `ExactComparator` scores it `0.0` or `1.0`, so clipping does not change it.

**How Clipping Works:**
- `true`: Scores below threshold are **set to 0.0** (hard cutoff)
Expand Down
Loading