Skip to content
Prev Previous commit
Merge branch 'dev' into fix/231-hungarian-fd-contract
# Conflicts:
#	CHANGELOG.md
  • Loading branch information
sromoam committed Sep 3, 2026
commit 381ff52926b0ae275fd5d8f5bc0fde16baecdbe0
146 changes: 146 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,152 @@ Each release links to full notes on the
`TP=2, FD=1, FA=1, FN=0`. The `FP` total was right, which is why the error went
unnoticed.

- `can_score_mapping` is a denylist, not an allowlist. It gated on a new
`handles_mappings` attribute, which no comparator outside this repo could carry,
so a user who wrote a mapping comparator and asked for it by name had their
score silently replaced with `0.0`. An explicit `comparator=` is consent by
definition. Only `LevenshteinComparator` (raises on a dict) and
`FuzzyComparator` (scores a changed value `0.944`, above a mere key reordering
at `0.667`) are refused, both on measured evidence. `handles_mappings` is
removed entirely rather than documented, since nothing reads it now.

- `List[Dict[...]]` is routed on the explicit path too, keyed on the element type.
The element kept `LevenshteinComparator`, whose canonical-JSON fallback compared
edit distance over a serialised blob: one path scored `0.7667` and cleared a
`0.7` threshold while the zero-config path scored the same annotation `0.0`. Both
now compute the same raw score.

- Documented that ANLS* compares every leaf as text, and pinned it with tests.
This is canonical ANLS* and is deliberate: the metric generalises the
*structure* of a comparison (key alignment, union normalisation, Hungarian
pairing of list elements), not the leaf metric, which came from scene-text VQA
where every answer is a string.

The consequence is stated rather than patched. Incidental character overlap on
a long numeric or identifier value scores high, and scores above a genuine text
near-miss: a one-character error in a 22-character account number is `0.9545`
and a 2x-wrong amount
`0.8571`, where `"Acme Corporation"` against `"Acme Corp"` is `0.5625`. No
`leaf_threshold` separates those, so a field whose values matter should be
declared, where it gets a comparator chosen for its type.

An earlier revision of this branch made leaves type-aware. That was reverted:
it amounted to a second inference table contradicting the zero-config one
(`amount: float` gets `NumericComparator@0.95` with tolerance when declared, and
would have got exact equality as a dict leaf), which is the divergence
[#239](https://github.com/awslabs/stickler/issues/239) exists to remove. A
future `infer_types=True` must delegate to `stickler.auto.inference` instead,
and needs [#49](https://github.com/awslabs/stickler/issues/49) settled first
because the two sides of a comparison can disagree about their type.

- The `Mapping` family is routed on the zero-config path. `Mapping[str, str]`,
`MutableMapping`, `OrderedDict`, `DefaultDict` and `Counter` fell through to
the exotic branch and were canonicalised to a JSON string, so the auto path
disagreed with the explicit path about the same annotation, and with the
CHANGELOG, `auto/README.md` and the comparators guide. Both the wire type and
the inferred comparator now use `ConfigurationHelper.is_mapping_annotation`.

- The mapping substitution works under `from __future__ import annotations`. It
read the raw `__annotations__`, which hold the STRING `"Dict[str, Any]"` under
PEP 563, decided that was not a mapping, and skipped every field. The engine
still scored with ANLS* via the read-time fallback while `to_json_schema()` and
`explain()` reported `LevenshteinComparator`, reintroducing exactly the
schema/engine divergence the substitution exists to prevent. It now runs in
`__pydantic_init_subclass__` over `model_fields`, whose annotations are already
resolved. An explicit `clip_under_threshold=True` is honoured again as a result.

- `ExactComparator` and `StructuredModelComparator` can score a mapping, and are
no longer zeroed for trying. `ExactComparator` now canonicalises a mapping
first, so identical content scores `1.0` regardless of key order; it previously
used `str(dict)`, which made key order significant and returned `0.0` or `1.0`
depending only on how the JSON arrived. `LevenshteinComparator` and
`FuzzyComparator` stay excluded: the first raises on a dict, and the second
scores a changed value (`0.944`) higher than a mere reordering (`0.667`).

- The mapping substitution copies the field descriptor instead of mutating it.
Pydantic does not clone the `json_schema_extra` closure, so one
`ComparableField(...)` bound to both a `str` field and a `Dict` field had ANLS*
and `clip=False` written onto the string field, order-dependently on which class
was defined first.

- A dict field scored `0.0` against an identical copy of itself on the explicit
path, and its configured comparator was never called.
`ComparisonDispatcher` handled `str`/`int`/`float`, `list` and
`StructuredModel` only, so a mapping fell through to the mismatched-types
branch. A comparator hardcoded to return `1.0` still produced `0.0`
([#297](https://github.com/awslabs/stickler/issues/297)).

- A mapping-annotated field with no explicit comparator no longer gets the
type-blind `LevenshteinComparator`, which rejects mappings outright. The
substitution happens at class definition, so `to_json_schema()`, `explain()`,
the HTML reports and the comparison engine all report the same comparator; a
schema round-trip previously exported `LevenshteinComparator` for a field the
engine scored with something else, and the reimported model then raised.

- A dict field whose value is a mapping but whose comparator scores scalars
(reachable through `Any` or `Union[str, Dict[...]]`, where no annotation
declares the shape) is now counted as a false discovery with a warning naming
the remedies, instead of raising. Value shape can be data-dependent, so
raising ended a corpus run on document N after succeeding on N-1.

- A `dict`-typed field is no longer exempt from a `match_threshold` the caller
or the model class declared; it previously used a hardcoded `0.7` while sibling
fields honoured the declared value.

- **Breaking:** `all_fields_matched` is no longer returned by `compare_with()`,
and no longer appears on `confusion_matrix.overall`. It quantified over
**top-level** fields only and did not recurse, so a nested field "matched" when
its own subtree mean cleared its own threshold and a failing leaf underneath was
invisible. Two external reports read it the way its name and the documentation
implied, as a quantifier over every leaf, and expected opposite behaviours from
each other, so no single implementation satisfied both
([#23](https://github.com/awslabs/stickler/issues/23),
[#275](https://github.com/awslabs/stickler/issues/275),
[#287](https://github.com/awslabs/stickler/issues/287)).

Replacements, all of which already existed: `overall_score` for the scalar
summary, `EvalResult.matched` for a single object-level verdict, and
`field_comparisons` for the individual failures. To ask whether anything failed
at all, both rollup nodes have to be read, because a list item that scores
below `match_threshold` is recorded as one `fd` on `confusion_matrix.overall`
and is not descended into, so its leaves never appear under
`confusion_matrix.aggregate`:

```python
clean = (
cm['aggregate']['fd'] + cm['aggregate']['fn'] == 0
and cm['overall']['fd'] + cm['overall']['fn'] + cm['overall']['fa'] == 0
)
```

A below-threshold object is a spurious non-match, so not descending into it is
deliberate: `overall` carries the object verdict and `aggregate` carries leaf
detail for the objects that were comparable. A caller wanting leaf detail for a
marginal object lowers `match_threshold` until it qualifies. See
[#288](https://github.com/awslabs/stickler/issues/288) for the naming.


Replacements, all of which already existed: `overall_score` for the scalar
summary, `EvalResult.matched` for a single object-level verdict, and
`field_comparisons` for the individual failures. To ask whether anything failed
at all, both rollup nodes have to be read, because a list item that scores
below `match_threshold` is recorded as one `fd` on `confusion_matrix.overall`
and is not descended into, so its leaves never appear under
`confusion_matrix.aggregate`:

```python
clean = (
cm['aggregate']['fd'] + cm['aggregate']['fn'] == 0
and cm['overall']['fd'] + cm['overall']['fn'] + cm['overall']['fa'] == 0
)
```

A below-threshold object is a spurious non-match, so not descending into it is
deliberate: `overall` carries the object verdict and `aggregate` carries leaf
detail for the objects that were comparable. A caller wanting leaf detail for a
marginal object lowers `match_threshold` until it qualifies. See
[#288](https://github.com/awslabs/stickler/issues/288) for the naming.

- `overall_score` and the confusion matrix no longer disagree about a field that
is absent on both sides. The two read different scores for the same object
pair: `overall_score` takes the threshold-corrected score, while object
Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.