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): one message per path, int or float only, match_thre…
…shold too

- A threshold is an int or float from 0.0 to 1.0. Decimal, Fraction and
  numpy.float32 are not (pass float(value)); numpy.float64 is a float. The
  rule covers match_threshold on every path, and an Annotated[...] field.
- Every example error is the real text for its input: it quotes the value
  as written (ComparableField(threshold=85), "threshold": 85,
  "comparator_config": {"threshold": 85}), says why it fails, gives the
  likely fix, and on the Python path ends with the ComparableField line.
- Config path: an invalid threshold is no longer prefixed "Invalid field
  configuration:", and a field inside a list_structured_model is named
  items[].sku. The troubleshooting table says so and adds match_threshold.
- Evaluation guide: an out-of-range x-aws-stickler-threshold on an array of
  objects raises, naming x-aws-stickler-match-threshold; only an in-range
  one warns.
- CHANGELOG: names the inputs that now raise on each path, in the same
  Changed entry, with the new example. Section and labels unchanged.
  • Loading branch information
sromoam committed Nov 17, 2026
commit 4f0fb4ab0ee6dd88f587b191f1a7dd2e94a3bb90
46 changes: 29 additions & 17 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,41 @@ Each release links to full notes on 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`
when the class is defined or the config or schema is loaded, on every
path.** It applies to the threshold the field ends up with:
- Python: `ComparableField(threshold=...)`, and a comparator threshold the
field adopts, such as `LevenshteinComparator(threshold=85)`. Neither was
checked, so at 85 an identical pair scored 0.0 FD.
- Stickler config: `threshold`, and an adopted `comparator_config.threshold`.
- JSON Schema: `x-aws-stickler-threshold`, and an adopted
`x-aws-stickler-comparator-config` threshold.
- **A threshold that is not an `int` or `float` from 0.0 to 1.0 raises
`ValueError` when the class is defined or the config or schema is loaded,
on every path, never during evaluation.** It applies to the threshold the
field ends up with, and to `match_threshold`:
- Python: `ComparableField(threshold=...)`, also inside `Annotated[...]`; a
comparator threshold the field adopts, such as
`LevenshteinComparator(threshold=85)`; and the `match_threshold` class
attribute. None was checked, so at 85 an identical pair scored 0.0 FD. A
`Decimal`, `Fraction` or `numpy.float32` threshold, which loaded, now
raises and asks for a float (`numpy.float64` is a float and loads).
- 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. Before, the
config and schema paths already refused a field threshold out of range but
accepted `true` as 1, and a comparator-config threshold loaded whatever its
value, because it was not read. The message names the model, the field,
where the value came from, and the likely fix:
config and schema paths already refused a threshold out of range but
accepted `true` as 1, also as a `match_threshold`, and a comparator-config
threshold loaded whatever its value, because it was not read. 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 likely
fix; on the Python path it ends with the line of the `ComparableField` call.
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': LevenshteinComparator(threshold=85) gives 85, but a threshold is a number from 0.0 to 1.0, the fraction of similarity a match needs. For 85%, use 0.85. Or set ComparableField(threshold=...) to override the comparator's value.
Invalid threshold for field 'vendor' of model 'Invoice': the field sets no threshold, so it uses 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 no pair would match. If 85 is a percentage, write LevenshteinComparator(threshold=0.85), or set ComparableField(threshold=0.85), which takes precedence. (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 pairs on
`match_threshold`.
`match_threshold`. `to_stickler_config()` leaves such an out-of-range value
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
Expand Down Expand Up @@ -94,8 +106,8 @@ Each release links to full notes on the
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`. Nothing that loaded
before raises, except a comparator threshold that is not a number from 0.0
to 1.0 (see Changed). `comparator` on a `list_structured_model` field, and `"auto"`
before raises, except a comparator threshold that is not an `int` or `float`
from 0.0 to 1.0 (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` with object arms) is not covered: as on the Python path
for a `Union` field, a comparator-config threshold gates it, and a named
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,11 @@ 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:
must be an `int` or `float` 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': x-aws-stickler-comparator-config threshold gives 85, but a threshold is a number from 0.0 to 1.0, the fraction of similarity a match needs. For 85%, use 0.85. Or set x-aws-stickler-threshold to override the comparator's value.
ValueError: Invalid threshold for field 'total_amount' of model 'Invoice': the field sets no "x-aws-stickler-threshold", so it uses "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 no pair would match. If 85 is a percentage, write 0.85 there, or set "x-aws-stickler-threshold": 0.85 on the property, which takes precedence.
```

**How Threshold Works:**
Expand Down
19 changes: 11 additions & 8 deletions docs/docs/Advanced/dynamic-models.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ The `x-aws-stickler-*` extensions control comparison behavior on each property:
| Extension | Purpose | Example |
|-----------|---------|---------|
| `x-aws-stickler-comparator` | Comparison algorithm. On an object with `properties`, which is scored field by field, it has no effect except for a threshold it names, and warns; set it on the properties inside | `"LevenshteinComparator"` |
| `x-aws-stickler-comparator-config` | Keyword arguments for the comparator. On an object with `properties` only its `threshold` is read; on an array of models nothing is. Every key not read warns. A `threshold` the field adopts must be a number from 0.0 to 1.0, or the import raises | `{"threshold": 0.9}` |
| `x-aws-stickler-comparator-config` | Keyword arguments for the comparator. On an object with `properties` only its `threshold` is read; on an array of models nothing is. Every key not read warns. A `threshold` the field adopts must be an `int` or `float` from 0.0 to 1.0, or the import raises | `{"threshold": 0.9}` |
| `x-aws-stickler-threshold` | Match threshold (0.0--1.0). Read on a scalar, an object, and an array of scalars; **ignored on an array of models** -- an array whose `items` declare `properties` -- where the element class's `x-aws-stickler-match-threshold` is the gate. Read, not ignored, on an array of free-form `{"type": "object"}` items, which become `List[dict]` | `0.8` |
| `x-aws-stickler-weight` | Field importance weight | `2.0` |
| `x-aws-stickler-clip-under-threshold` | Zero out scores below threshold. Defaults to `false` on a free-form object or an array of them, so a comparator such as `ANLSStarComparator` keeps its partial credit; the default `ExactComparator` scores each object `0.0` or `1.0`, so clipping does not change them | `true` |
Expand Down Expand Up @@ -254,14 +254,16 @@ A key the field leaves out resolves as it does on the Python path: a `threshold`
defaults to `clip_under_threshold: false`, so partial credit from a comparator
such as `ANLSStarComparator` survives.

The threshold the field uses, `threshold` or an adopted `comparator_config.threshold`,
must be a number from 0.0 to 1.0. Anything else raises `ValueError` on load:
The threshold the field uses, `threshold` or an adopted `comparator_config` threshold,
must be an `int` or `float` from 0.0 to 1.0, and so must `match_threshold`. Anything
else raises `ValueError` on load, with no prefix:

```text
Invalid threshold for field 'total' of model 'Invoice': comparator_config.threshold gives 85, but a threshold is a number from 0.0 to 1.0, the fraction of similarity a match needs. For 85%, use 0.85. Or set the field's threshold to override the comparator's value.
ValueError: Invalid threshold for field 'total' of model 'Invoice': the field sets no "threshold", so it uses "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 no pair would match. If 85 is a percentage, write 0.85 there, or set "threshold": 0.85 on the field, which takes precedence.
```

When `threshold` is set, `comparator_config.threshold` is not read and not checked.
When `threshold` is set, the `comparator_config` threshold is not read and not checked.
A field inside a `list_structured_model` is named `items[].sku`, as in a schema.
`x-aws-stickler-threshold` and `x-aws-stickler-comparator-config` follow the same
rule. See [Valid Threshold Values](../Getting-Started/thresholds-and-metrics.md#valid-threshold-values).

Expand Down Expand Up @@ -579,16 +581,17 @@ Model = StructuredModel.model_from_json(config)

## Troubleshooting

Every `model_from_json()` failure raises `ValueError`, and all but one are prefixed `Invalid field configuration:` or `Error converting field configurations:`. The message names the offending field and lists the valid values.
Every `model_from_json()` failure raises `ValueError`. Most are prefixed `Invalid field configuration:` or `Error converting field configurations:`; an invalid threshold is not, since its message names the field and the model itself. The message names the offending field and lists the valid values.

| Message | Cause | Fix |
|-------|-------|-----|
| `Configuration must contain 'fields' key` | Top-level `fields` missing | Wrap the field definitions in `{"fields": {...}}` |
| `Field 'x' missing required 'type' parameter` | Field definition has no `type` | Add a `"type"` key |
| `Unknown type: 'x'. Available types: [...]` | Unsupported type string | Use a listed type; the message enumerates them |
| `Field 'x' with primitive type 'str' requires a 'comparator'` | Primitive field without a comparator | Add a `"comparator"` key, or set `"infer_unspecified_fields": true` (see [Inferring unspecified fields](#inferring-unspecified-fields)) |
| `Invalid threshold for field 'x' of model 'Invoice': threshold gives 5.0, but a threshold is a number from 0.0 to 1.0` | A field threshold that is not a number from 0.0 to 1.0 | Use a value in 0.0--1.0; the message gives the likely fix |
| `Invalid threshold for field 'x' of model 'Invoice': comparator_config.threshold gives 85, ...` | The same, for a `comparator_config` threshold the field adopts. `from_json_schema()` raises the same way for `x-aws-stickler-threshold` and `x-aws-stickler-comparator-config` | Use a value in 0.0--1.0, or set the field's `threshold` |
| `Invalid threshold for field 'x' of model 'Invoice': "threshold": 5.0 is out of range. ...` | A field threshold that is not an `int` or `float` from 0.0 to 1.0 | Use a value in 0.0--1.0; the message gives the likely fix |
| `Invalid threshold for field 'x' of model 'Invoice': the field sets no "threshold", so it uses "comparator_config": {"threshold": 85}. ...` | The same, for a `comparator_config` threshold the field adopts. `from_json_schema()` raises the same way for `x-aws-stickler-threshold` and `x-aws-stickler-comparator-config` | Use a value in 0.0--1.0, or set the field's `threshold` |
| `Invalid match threshold for model 'Invoice': "match_threshold": 85 is out of range. ...` | A `match_threshold`, on the model or a nested-model field, that is not an `int` or `float` from 0.0 to 1.0 | Use a value in 0.0--1.0 |
| `Unknown comparator: 'x'. Available: [...]` | Comparator name not registered | Use a class name from the list; `BERTComparator` and `LLMComparator` appear only when the `[bert]` and `[llm]` extras are installed |
| `Field 'x' with type 'structured_model' requires a 'fields' configuration` | Nested model without its own `fields` | Add the nested `fields` block |
| `Field 'x' configuration must be a mapping, got int` | A field's value is not a config object | Wrap it: `{"x": {"type": "str", ...}}` |
Expand Down
22 changes: 12 additions & 10 deletions docs/docs/Getting-Started/thresholds-and-metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Invoice(StructuredModel):

**Default:** `0.5`

**Valid values:** a number from 0.0 to 1.0. See [Valid Threshold Values](#valid-threshold-values).
**Valid values:** an `int` or `float` from 0.0 to 1.0. See [Valid Threshold Values](#valid-threshold-values).

### 3. Model Match Threshold

Expand All @@ -66,6 +66,8 @@ class LineItem(StructuredModel):

**Default:** `0.7`

**Valid values:** an `int` or `float` from 0.0 to 1.0, checked when the class is defined. See [Valid Threshold Values](#valid-threshold-values).

### 4. Runtime Match Threshold

**What it is:** The `match_threshold` parameter passed to `evaluate()` or `EvalSpec`.
Expand Down Expand Up @@ -135,21 +137,21 @@ A comparator's *default* threshold is not part of that chain. `LevenshteinCompar

## Valid Threshold Values

A field's threshold is a number from 0.0 to 1.0: the fraction of similarity a match needs. The rule applies to the threshold the field ends up with, whether you set it on the field or the field adopts it from the comparator, on every path:
A threshold is an `int` or `float` from 0.0 to 1.0, inclusive: the minimum similarity score for a match. `bool`, strings, NaN and infinity are not valid, and neither are other number types such as `Decimal`, `Fraction` or `numpy.float32` (pass `float(value)`; `numpy.float64` is a `float`). The rule applies on every path to the threshold the field ends up with, whether you set it on the field or the field adopts it from the comparator, and to `match_threshold`:

| Path | Field threshold | Adopted comparator threshold |
|---|---|---|
| Python | `ComparableField(threshold=...)` | `LevenshteinComparator(threshold=...)` |
| Stickler config | `threshold` | `comparator_config.threshold` |
| JSON Schema | `x-aws-stickler-threshold` | `x-aws-stickler-comparator-config` threshold |
| Path | Field threshold | Adopted comparator threshold | Match threshold |
|---|---|---|---|
| Python | `ComparableField(threshold=...)`, also inside `Annotated[...]` | `LevenshteinComparator(threshold=...)` | `match_threshold = ...` |
| Stickler config | `"threshold"` | `"comparator_config": {"threshold": ...}` | `"match_threshold"` |
| JSON Schema | `"x-aws-stickler-threshold"` | `"x-aws-stickler-comparator-config": {"threshold": ...}` | `"x-aws-stickler-match-threshold"` |

Anything else, such as `85`, `1.5`, `-1`, `"0.9"`, `True`, NaN or infinity, raises `ValueError` when the class is defined or the config or schema is loaded, never during evaluation. The message names the model, the field, where the value came from, and the likely fix:
Anything else, such as `85`, `1.5`, `-1`, `"0.9"`, `true`, NaN or infinity, raises `ValueError` when the class is defined or the config or schema is loaded, never during evaluation. Each path gives the same message, quoting the value as you wrote it. It names the model, the field, why the value fails, and the likely fix, and on the Python path the line of the `ComparableField` call:

```text
ValueError: Invalid threshold for field 'vendor' of model 'Invoice': LevenshteinComparator(threshold=85) gives 85, but a threshold is a number from 0.0 to 1.0, the fraction of similarity a match needs. For 85%, use 0.85. Or set ComparableField(threshold=...) to override the comparator's value.
ValueError: Invalid threshold for field 'vendor' of model 'Invoice': the field sets no threshold, so it uses 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 no pair would match. If 85 is a percentage, write LevenshteinComparator(threshold=0.85), or set ComparableField(threshold=0.85), which takes precedence. (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 it is not consulted (pairing uses `match_threshold`) and warns instead. A comparator's constructor never checks it, since a custom comparator may use `threshold` for something else.
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 not consulted, since pairing uses `match_threshold`, and warns instead. A field threshold written on a list of models is still checked, and its message points at `match_threshold`. A comparator's constructor never checks its threshold, since a custom comparator may use `threshold` for something else.

## Meeting a Threshold

Expand Down
4 changes: 2 additions & 2 deletions docs/docs/Guides/Comparators/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ 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`:
Whichever threshold the field uses must be an `int` or `float` from 0.0 to 1.0, or defining the class raises `ValueError`, also for a field declared as `Annotated[str, ComparableField(...)]`:

```text
ValueError: Invalid threshold for field 'vendor' of model 'Invoice': LevenshteinComparator(threshold=85) gives 85, but a threshold is a number from 0.0 to 1.0, the fraction of similarity a match needs. For 85%, use 0.85. Or set ComparableField(threshold=...) to override the comparator's value.
ValueError: Invalid threshold for field 'vendor' of model 'Invoice': the field sets no threshold, so it uses 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 no pair would match. If 85 is a percentage, write LevenshteinComparator(threshold=0.85), or set ComparableField(threshold=0.85), which takes precedence. (Set at invoice_models.py:6.)
```

A comparator threshold the field overrides is not checked. See [Valid Threshold Values](../../Getting-Started/thresholds-and-metrics.md#valid-threshold-values).
Expand Down
Loading