Skip to content
Prev Previous commit
Next Next commit
Merge branch 'dev' into fix/231-hungarian-fd-contract
Resolve the CHANGELOG.md conflict under [Unreleased]. Both sides appended
sections, so the resolution keeps both: the two #231 entries move into the
single ### Fixed list that dev introduced, ahead of the #233 entries, and
dev's ### Removed, ### Performance and ### Changed sections are untouched.

No upstream commit touched src/stickler/algorithms/hungarian.py or its
tests. 358c455 (#233) edited two of this branch's docs files and merged
cleanly; it adopts the same FD vocabulary at object level.
  • Loading branch information
digalaviz committed Sep 2, 2026
commit 87d82fd4026cf0d6b3efb493df538903d0f2317b
163 changes: 162 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@ Each release links to full notes on the

## [Unreleased]

### Removed

- The deprecated `aggregate` parameter on `ComparableField`, along with its dead
code path (`_is_aggregate_field`, `ConfigurationHelper.is_aggregate_field`, and
the `parent_is_aggregate` plumbing in the confusion-matrix calculator). The
flag had no effect once aggregation moved to the comparison layer in
[#94](https://github.com/awslabs/stickler/issues/94): every node in
`compare_with()` output already carries an `aggregate` block summing the
primitive field metrics below it. Passing `aggregate=` now raises `TypeError`
instead of emitting a `DeprecationWarning`. The comparison parameters after
`default` (`clip_under_threshold`, `alias`, ...) are now keyword-only, so an
old five-positional call raises `TypeError` rather than silently rebinding its
fifth argument to `clip_under_threshold`. A JSON Schema carrying
`x-aws-stickler-aggregate` still imports — the key is accepted but ignored — so
existing schema files keep loading.
([#226](https://github.com/awslabs/stickler/issues/226))

### Fixed

- **Breaking:** `HungarianMatcher.calculate_metrics` no longer reports a paired
Expand Down Expand Up @@ -39,7 +56,8 @@ Each release links to full notes on the
(`HungarianHelper.get_complete_matching_info` and
`ComparisonHelper.compare_unordered_lists`) read only `matched_pairs` and
classify the scores themselves. Both are on the traditional path; ANLS Star
matches lists with its own `munkres` call in `trees/list_tree.py` and is
matches lists with its own `munkres` call in
`structured_object_evaluator/trees/list_tree.py` and is
untouched. The counts now agree with what
`ComparisonHelper.unordered_list_metrics` already produced and with the rule
that [Hungarian Matching](https://awslabs.github.io/stickler/Advanced/hungarian-matching/)
Expand All @@ -52,6 +70,149 @@ 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.

- `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
classification against `match_threshold` takes the raw pairwise similarity.
The raw path tested absence with a bare `is None`, so it scored `[]` against
`None` on a list field, `""` against `None` on a string field, and two empty
lists against each other all as `0.0` -- while `ComparisonDispatcher` scored
every one of those as a true negative worth `1.0`.

The result was a pair reported as `overall_score == 1.0` and `fd == 1` at once:
a perfect match that is also a false discovery. Two **identical** objects were
enough to trigger it. Any `List[Model]` whose element model declares an
optional list or string field reaches this whenever that field is left absent
on both sides, which for a document-extraction schema is the common case, not
an edge one -- and the contradiction is invisible unless you read both numbers
together, so it silently deflated precision on object-level metrics.

Both readers now define absence the same way the dispatcher does, per field
kind: `None` and `[]` for a list field, `None`, `""` and `{}` for everything
else. This is the rule the docs already
[documented](https://awslabs.github.io/stickler/Advanced/classification-logic/)
([#233](https://github.com/awslabs/stickler/issues/233))

- An empty dict is now read as absent, the third case that documented rule
names. `NullHelper.is_effectively_null_for_primitives` covered `None` and `""`
but not `{}`, so the #233 contradiction survived for a `Dict` field in the
opposite direction: two **identical** objects each holding `{}` classified as
a false discovery instead of a match, and `{}` against `None` recorded an FN
while `None` against `{}` recorded an FA, where the rule calls for a TN in all
three.

A populated dict field was worse than misclassified, it was unscoreable. No
comparator accepts a dict -- `LevenshteinComparator` raises `TypeError`
pointing at `StructuredModel` instead -- so `{}` against `{"k": "v"}` fell
through to the comparator and *raised*, taking out Hungarian matching for any
`List[Model]` whose element model had a populated dict field. That pair is now
an ordinary false alarm.

Two **populated** dicts still reach the comparator and still raise. Giving
dicts a comparator is a separate change; this one only closes the absence
cases.

- A field annotated `Optional[Annotated[List[str], ...]]` is now recognized as a
list field. Pydantic strips `Annotated` when it wraps a whole annotation, so
`Annotated[Optional[List[str]], ...]` always worked, but it leaves the wrapper
on a union arm -- and `get_origin` reports `Annotated` there rather than the
type inside. `Annotated[List[str], ...] | None` normalises to exactly that
spelling, so both PEP 604 and subscript forms were affected.

This is the annotation a `Field(description=...)` produces, which makes it
common in extraction schemas rather than exotic. The cost landed three
different ways on one field, all silent: `[]` against `[]` recorded **no
counter at all** and the field vanished from the confusion matrix, `[]`
against `None` recorded an FN, and `None` against `[]` recorded an FA -- while
a sibling `Optional[List[str]]` recorded a TN for all three.

Union arms are unwrapped through a new shared
`optional_annotation.unwrap_annotated`, alongside the existing helpers for
destructuring a union, rather than a fourth hand-rolled check. Routing is
unaffected: `List[Model]` on this spelling already reached
`StructuredListComparator` through the dispatcher's runtime type check, so
only the null and empty cases move.

- A field annotated `list`, `list | None`, or `Optional[list]` is now recognized
as a list field. `_is_list_field` tested `get_origin(...) is list`, which
matches only a *parameterized* spelling, so the three unparameterized ones
answered `False` while `List`, `list[str] | None`, and `Optional[List[str]]`
answered `True`. `list | None` is the incongruous case: it is a PEP 604
optional list, and `list[str] | None` was already handled.

An unrecognized spelling skips list null handling and falls into the primitive
null check, where `[]` is not "effectively null". Such a field scored `1.0`
when empty on both sides but recorded **no classification evidence at all** --
no TN, no TP, no row. Because the score was right, the missing count was easy
to miss; it understated `tn` and every metric derived from it. Comparing a
six-field model against itself with every field `[]` reported `tn == 3` where
the docs call for `6`.

Recognition is now spelling-independent within a union: bare and parameterized
members answer alike. Only the null and empty cases move -- a populated list
reached `PrimitiveListComparator` before and still does, and no raw score
changes.

One spelling is still not a list field, deliberately: `Any` holding a list.
Inferring list-ness from a runtime value rather than an annotation is a
different question from reading a spelling correctly, and every caller here
has only the annotation.

- Raw object similarity used by Hungarian matching no longer treats a true
negative as evidence that two objects match. Fields absent on both sides are
excluded from the weighted-average numerator and denominator. If every field
is absent, the score is defined as `1.0`, preserving the #233 fix; otherwise,
empty optional fields can no longer hide a missed value or make an empty
candidate tie one that extracted real content.

- Threshold-gated recursion now applies consistently to nested metrics,
`non_matches`, and `field_comparisons` for `List[StructuredModel]`. An
assigned pair below the element model's `match_threshold` produces one atomic
FD, while unmatched GT and prediction objects produce one atomic FN and FA.
None of these objects contributes leaf-level metrics or report entries.
Lower the element model's `match_threshold` to inspect leaf comparisons for
weaker pairs.

### Performance

- Restored the fast path in `ComparisonHelper.compare_field_raw`. Reading a
field's absence rule requires knowing whether the field is a list, and
`_is_list_field` re-reads `model_fields` and destructures the annotation on
every call. The bare `is None` check it replaced short-circuited before doing
any of that, so consulting the annotation unconditionally cost about 23% on a
60x60 Hungarian cost matrix of 20-field models -- 72,000 calls for one list
comparison (0.531s to 0.651s; measured best-of-three).

The lookup is now guarded by a cheap value test that is the union of both
`NullHelper` rules, so anything either one calls absent still reaches the full
check and no outcome changes, while the common case of both sides being
populated skips the annotation entirely (0.537s, within noise of the original).
A test pins the superset property so adding a case to either rule without
widening the guard fails loudly rather than silently skipping the check.

### Changed

- JSON Schema import now delegates standard types, local references, combiners,
and constraint parsing to `json-schema-to-pydantic`. Stickler retains a narrow
adapter for comparison metadata and nested `StructuredModel` creation. Parsed
types still choose comparison behavior, but schema constraints do not reject
imperfect predictions before scoring: malformed enum, date, and
constraint-violating values remain constructible and reach their comparator.

Unconfigured enum fields now use `ExactComparator` at threshold `1.0`, and
`date` / `date-time` formats use `DateComparator` at threshold `1.0`; both used
`LevenshteinComparator` at threshold `0.5` before this change, so default scores
can move for those fields.
This adds support for valid Draft 7 multi-type unions and multi-arm `allOf`,
`anyOf`, and `oneOf` schemas; recursive models and `patternProperties` remain
explicit unsupported boundaries ([#212](https://github.com/awslabs/stickler/issues/212)).

- Confidence AUROC and document-splitting statistics now use NumPy
implementations with randomized scikit-learn and SciPy equivalence tests.
`scikit-learn` is no longer a core dependency, and the `docsplit` extra now
adds only pandas; SciPy remains isolated to the `semantic` extra
([#216](https://github.com/awslabs/stickler/issues/216)).

## [0.7.0] - 2026-08-18

### Added
Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.