Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
e2de968
docs: state the list contract in one place, and correct the claims th…
sromoam Oct 16, 2026
ecaaecd
docs: link the None-list row gap to #418
sromoam Oct 16, 2026
91928e7
docs: link the first-pair mean_score exception to #428
sromoam Oct 19, 2026
9193892
Merge remote-tracking branch 'origin/dev' into docs/lists-contract
sromoam Oct 20, 2026
94f8401
Merge remote-tracking branch 'origin/dev' into m419
sromoam Oct 28, 2026
260fc04
docs: narrow the raw_similarity_score gap to List[StructuredModel] af…
sromoam Oct 28, 2026
1dd9089
Merge origin/dev into docs/lists-contract
sromoam Nov 17, 2026
a17dc85
docs(lists): correct the list contract against dev
sromoam Nov 17, 2026
0597663
docs(results): drop the fixed match gap and correct weighted_score fo…
sromoam Nov 17, 2026
789509f
docs(thresholds): correct what the runtime match_threshold gates
sromoam Nov 17, 2026
71fc040
docs(threshold-gated): qualify equal-length pairing for None, link th…
sromoam Nov 17, 2026
63af654
docs(hungarian): make the Result Structure checkable and nest leaf co…
sromoam Nov 17, 2026
ec0a2f9
docs: point list clipping at the Score rule, and limit the unordered …
sromoam Nov 17, 2026
5528a7e
docs(auto): state every effect of the runtime match_threshold in the …
sromoam Nov 17, 2026
d7dd08b
docs(changelog): re-add the list contract entry under Unreleased
sromoam Nov 17, 2026
4782d50
docs(auto): describe the List[BaseModel] clip gap without an issue link
sromoam Nov 17, 2026
e1d4e47
docs(lists): word the known gaps as defects, not as places the table …
sromoam Nov 17, 2026
174ed08
docs(thresholds): the runtime match_threshold also gates zero-config …
sromoam Nov 17, 2026
8150c77
docs: clip_under_threshold is off by default on dict and plain-model …
sromoam Nov 17, 2026
310a741
docs: qualify the equal-length pairing claims for None elements
sromoam Nov 17, 2026
90db276
docs(lists): scope the order claim to a list field's elements
sromoam Nov 17, 2026
9de4212
docs(lists): mark the List[StructuredModel] clip behaviour as a known…
sromoam Nov 17, 2026
e649f73
docs(lists): fix the review nits on reports, null lists and examples
sromoam Nov 17, 2026
0a314cf
docs(lists): scope the Reports row to field_comparisons, and say non_…
sromoam Nov 17, 2026
3218bc4
docs(lists): scope the clip defaults to a StructuredModel declared in…
sromoam Nov 17, 2026
23bc208
docs(json-schema): x-aws-stickler-infer-unspecified also infers the c…
sromoam Nov 17, 2026
6330692
docs(json-schema): keep the clip Default cell at true, and put the in…
sromoam Nov 17, 2026
69e178c
Merge origin/dev into docs/lists-contract
sromoam Nov 17, 2026
1d7ae07
docs(thresholds): fix the list rows the dev merge left inconsistent
sromoam Nov 17, 2026
aea762b
docs(thresholds): keep the List[StructuredModel] exception in Key Rul…
sromoam Nov 17, 2026
9a375d3
Merge branch 'dev' into docs/lists-contract
sromoam Nov 18, 2026
b918a52
Merge origin/dev into docs/lists-contract
sromoam Nov 18, 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
32 changes: 32 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,38 @@ Each release links to full notes on the
`match_threshold` overrides the element class's for list pairing; on a
`StructuredModel` it sets only `EvalResult.matched`. Scoring is unchanged
([#484](https://github.com/awslabs/stickler/issues/484))
- The list contract is stated once, as a table in `classification-logic.md`
(pairing, bar, counts, recursion, score, reports), and other pages link to
it instead of restating it. Scoring is unchanged. Claims corrected against
measured output:
- A list declared without `ComparableField` pairs against the class
`match_threshold` (`0.7` unless set), not `0.5`.
- A list field's element order does not matter, but a nested list element
is compared as one value, and on the zero-config path it must match
exactly, order included.
- On a plain pydantic class, the runtime `match_threshold` of `evaluate()`
and `eval_for()` also sets `List[Model]` and `List[dict]` pairing and the
threshold of nested plain-model and `dict` fields, while a primitive list
keeps its inferred threshold. On a `StructuredModel` class it sets only
`matched`, and a `List[StructuredModel]` field pairs at the element
class's own `match_threshold` on either path
([#416](https://github.com/awslabs/stickler/issues/416)). The docstrings
now say TP/FD, not TP/FN/FA.
- `clip_under_threshold` has no effect on `List[StructuredModel]`, so an FD
pair keeps its score, a known defect
([#415](https://github.com/awslabs/stickler/issues/415)).
- `clip_under_threshold` defaults to off, not on, for dict and plain-model
fields and lists of them on a `StructuredModel` declared in Python. With
`x-aws-stickler-infer-unspecified`, an inferred JSON Schema property takes
its clip setting from inference, which is off for a free-form object and a
free-text string, rather than always `true`.
- `aggregate` leaves out FN and FA items beside an accepted sibling, and a
field `threshold` on `List[StructuredModel]` raises `ValueError`.
- A primitive list element row's `weighted_score` in `field_comparisons` is
its raw similarity, unweighted. Rows inside list items are described as
they are today ([#418](https://github.com/awslabs/stickler/issues/418)).
- The Hungarian matching example shows measured counts and the list score,
and its result block is checkable.
- Amount examples no longer present a field threshold as rounding tolerance for
`NumericComparator`. It scores 1.0 or 0.0, so the README, Best Practices,
Evaluation and IDP Accelerator examples now set `absolute_tolerance=0.01` (or
Expand Down
7 changes: 5 additions & 2 deletions docs/docs/Advanced/aggregate-metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Stickler automatically includes an `aggregate` field at every node in the confus
## Key Features

- **Automatic** -- Every node gets an `aggregate` field, with no per-field configuration.
- **Hierarchical** -- Parent nodes sum metrics from all child primitive fields, except where a list's items were all rejected and the node reports object rows instead ([why](#aggregate-counts-objects-for-an-all-rejected-list)).
- **Hierarchical** -- Parent nodes sum metrics from all child primitive fields, except where a list's items were all rejected and the node reports object rows instead ([why](#aggregate-counts-objects-for-an-all-rejected-list)). In a list of models only accepted (TP) items contribute leaves, so an unmatched FN or FA item beside an accepted sibling appears on `overall` only ([Recursion](classification-logic.md#list-contract)).
- **Consistent** -- The same access pattern works at every level: `result['confusion_matrix']['aggregate']` or `result['confusion_matrix']['fields']['contact']['aggregate']`.
- **Derived metrics included** -- Each aggregate contains precision, recall, F1, and accuracy.

Expand Down Expand Up @@ -142,7 +142,10 @@ Coinciding is not evidence that nothing was hidden, which is the separate and mo
has **no child field nodes at all**. `AggregateMetricsCalculator` decides leaf
versus parent on exactly that -- whether `fields` has any entries -- so such a
node is treated as a leaf and its `aggregate` becomes a copy of its own
`overall`: one row per rejected item. The **unit of the count changes with the
`overall`: one row per rejected item. The same holds for any list with no
accepted item, so its FN and FA items count here as object rows too; beside an
accepted sibling they are left out of `aggregate` (with two-field items,
`[A, B]` vs `[A]` reads `overall tp=1 fn=1`, `aggregate tp=2`). The **unit of the count changes with the
data**. This is decided per node, and needs only that one list's items to be
rejected -- not the whole document:

Expand Down
24 changes: 16 additions & 8 deletions docs/docs/Advanced/classification-logic.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,20 @@ False Alarm (FA) and False Discovery (FD) together make up the broader False Pos

### Lists

Lists use the [Hungarian algorithm](hungarian-matching.md) for optimal element pairing.
#### The list contract {: #list-contract }

1. **Empty lists**: `[] vs []` is TN; `[] vs [items]` produces one FA per item; `[items] vs []` produces one FN per item.
2. **Matched elements**: similarity >= threshold is TP; below threshold is FD. See [Meeting a Threshold](../Getting-Started/thresholds-and-metrics.md#meeting-a-threshold).
3. **Unmatched elements**: leftover GT elements are FN; leftover EST elements are FA.
4. **`None` elements**: absent, so they are not matched or counted. A list of only `None` is an empty list. See [`None` elements in a list](#none-elements-in-a-list).
This table is the single statement of how Stickler treats a list field. Other pages link here rather than restate it. The Known gaps note under it lists where the code does not yet follow it.

| Aspect | Rule |
|---|---|
| Pairing | A list field's elements are paired one-to-one by the [Hungarian algorithm](hungarian-matching.md), maximising total similarity, so their order does not matter: `["a", "b"]` vs `["b", "a"]` scores `1.0`. An element that is itself a list (`List[List[str]]`) is compared as one whole value, so order inside it does count. On the zero-config path (`stickler.evaluate()` on a plain pydantic class) that inner list, and a list held in an `Any` field, must match exactly, order included. `None` and `NaN` elements are removed first ([`None` elements in a list](#none-elements-in-a-list)); reports keep original indices. Pair similarity is the field's comparator, or `GT[i].compare(Pred[j])` for `List[StructuredModel]` (fields absent on both sides excluded). |
| Bar | `List[StructuredModel]`: the element class's `match_threshold`; a runtime `match_threshold` does not change it. A field `threshold` there raises `ValueError` in Python, and JSON Schema ignores it. Primitive, dict and plain-model lists on a `StructuredModel` declared in Python: the field's `threshold`, else a threshold named on the comparator, else `0.5` when declared with `ComparableField()`, or the class `match_threshold` (`0.7` unless set) when declared without it (`tags: List[str]`). JSON Schema and the zero-config path have their own defaults ([JSON Schema](../Guides/Evaluation/README.md#extension-reference), [zero-config](../Getting-Started/thresholds-and-metrics.md#4-runtime-match-threshold)). A pair that [meets](../Getting-Started/thresholds-and-metrics.md#meeting-a-threshold) the bar is a TP. |
| Counts (the list node's `overall`) | Paired element: TP if it meets the bar, else FD. Unpaired GT element: FN. Unpaired prediction: FA. An empty, `None` or all-`None` list is null: both null is one TN (score `1.0`); one side null gives one FN or FA per present element (score `0.0`). |
| Recursion | Only TP pairs of `StructuredModel` items are descended into. FD, FN and FA items are atomic. `aggregate` holds the leaves of TP items only, so FD, FN and FA items are left out of it when any sibling was accepted. With no accepted item it falls back to the list node's own counts ([why](aggregate-metrics.md#aggregate-counts-objects-for-an-all-rejected-list)). |
| Score | `sum(pair scores) / max(n_gt, n_pred)`, never clipped as a whole against a field threshold. For primitive, dict and plain-model lists the pair score is the element similarity, zeroed below the bar when `clip_under_threshold` is on. On a `StructuredModel` declared in Python it defaults to on for primitive lists and off for dict and plain-model lists. JSON Schema and the zero-config path have their own defaults ([JSON Schema](../Guides/Evaluation/README.md#extension-reference), [zero-config](../API-Reference/auto.md#inference)). For `List[StructuredModel]` the pair score is `GT[i].compare_with(Pred[j])["overall_score"]`, which applies each field's own threshold and can differ from the pairing similarity. Currently `clip_under_threshold` has no effect there, so an FD pair keeps its score: a known gap. [Worked example](hungarian-matching.md#step-4-list-score). |
| Reports | `field_comparisons`: one row per element of a primitive, dict or plain-model list, whatever its classification (a dict or plain-model element is not expanded into its keys or fields); for `List[StructuredModel]`, one row per leaf of a TP item and one object row per FD, FN or FA item. `non_matches` has the same rows, but only the FD, FN and FA ones. A `field_comparisons` row's `match` is true when its own classification is TP or TN: a value or object row met its bar; a list row had every element paired as a TP, with no FD, FA or FN at the element level. Failures deeper down get their own rows. |

**Known gaps.** Four behaviours are defects, not the contract: `clip_under_threshold` having no effect on `List[StructuredModel]`; inside a list item, a `field_comparisons` row reporting the clipped `score`, and a nested list or object getting one row; a `None` list being reported differently from `[]` in `field_comparisons` (one row for the whole field against a non-empty list, and one row against another `None`, where every other pair of null lists, such as `[]` vs `[]`, gets none); and inside a list item, the cases listed under **Nested lists** below counting differently than at top level.

#### `None` elements in a list {: #none-elements-in-a-list }

Expand Down Expand Up @@ -214,7 +222,7 @@ neither term. The mixed-matching example above scores recall `1.000` even though
`0.667`. `HungarianMatcher.calculate_metrics` always uses that second formula.
See [FD and recall](hungarian-matching.md#fd-and-recall).

These are computed at every node of the result tree, from that node's own counts, and which counts those are depends on which node you read. `overall` classifies that node's direct children: for a list field, whether each pairing was genuine or spurious; at the root, its own fields, which means the two units can mix in a single count. `aggregate` gives leaf detail, and for a list of objects that means only the items that were comparable, since a list item below the element class's `match_threshold` is one FD and is not descended into. A single nested `StructuredModel` field is not gated this way: its leaves are always reported. See [Which node answers which question](aggregate-metrics.md#which-node-answers-which-question).
These are computed at every node of the result tree, from that node's own counts, and which counts those are depends on which node you read. `overall` classifies that node's direct children: for a list field, whether each pairing was genuine or spurious; at the root, its own fields, which means the two units can mix in a single count. `aggregate` gives leaf detail, and for a list of objects that means only the items that were comparable, since a list item below the element class's `match_threshold` is one FD and is not descended into; unmatched FN and FA items are left out too when a sibling was accepted ([Recursion](#list-contract)). A single nested `StructuredModel` field is not gated this way: its leaves are always reported. See [Which node answers which question](aggregate-metrics.md#which-node-answers-which-question).

## Edge Cases

Expand All @@ -224,9 +232,9 @@ These are computed at every node of the result tree, from that node's own counts

**Threshold boundary** -- A similarity score exactly equal to the threshold counts as a match (TP). So does a score less than `1e-10` under it, at every gate listed in [Meeting a Threshold](../Getting-Started/thresholds-and-metrics.md#meeting-a-threshold), so a rounding error such as `0.7 + 0.1` (`0.7999999999999999`) against `0.8` does not turn a TP into an FD.

**List order** -- Order does not matter. The Hungarian algorithm finds the optimal pairing regardless of element position.
**List order** -- The order of a list field's elements does not matter. The Hungarian algorithm finds the optimal pairing regardless of element position. A nested list element is compared as one whole value ([Pairing](#list-contract)).

**Nested lists** -- For `List[StructuredModel]`, the Hungarian algorithm pairs objects at the list level, then each matched pair is evaluated recursively: every field the ground-truth element's class declares is classified by the same dispatcher as a top-level field, so it follows the rules on this page. A field annotated as a model, a list, or an `Optional` model or union of models, such as `Optional[Inner]`, `List[str]`, `Optional[Union[A, B]]` or `Union[A, B, List[str]]`, goes to the dispatcher directly. Any other field, such as `Any`, `object`, `Union[A, B]`, `Sequence[str]` or `Optional[Annotated[Inner, Field(...)]]`, is read by its value first. If the classes in one list annotate a field differently, the first matched ground-truth element that declares it decides which, or, when the list's first element is not matched, each pair's own class does. These cases are counted differently from top level:
**Nested lists** -- For `List[StructuredModel]`, the Hungarian algorithm pairs objects at the list level, then each TP pair is evaluated recursively ([Recursion](#list-contract)): every field the ground-truth element's class declares is classified by the same dispatcher as a top-level field, so it follows the rules on this page. A field annotated as a model, a list, or an `Optional` model or union of models, such as `Optional[Inner]`, `List[str]`, `Optional[Union[A, B]]` or `Union[A, B, List[str]]`, goes to the dispatcher directly. Any other field, such as `Any`, `object`, `Union[A, B]`, `Sequence[str]` or `Optional[Annotated[Inner, Field(...)]]`, is read by its value first. If the classes in one list annotate a field differently, the first matched ground-truth element that declares it decides which, or, when the list's first element is not matched, each pair's own class does. These cases are counted differently from top level:

- A field the predicted element's class does not declare (an extra field) is not counted, where at top level it adds an FA to the root `overall`.
- In a field read by value, a model of another class than the ground truth's is one TP or FD, from the ground-truth model's `compare_with()` score against the field's threshold, and `aggregate` counts it the same way rather than per field. That score reads a field the prediction lacks as `None`, so `Search(query="hotels")` against `Browse(url="x.com")` scores `0.0` and is an FD. A ground-truth field left `None` matches the missing one, so `Inner(a="x", b=None)` against `Other(c="z")` scores `0.5`, from `b`, and is a TP at the default threshold of `0.5`. It scores only the ground truth's own fields, so `Pet(name="tom")` against its subclass `Cat(name="tom", lives=9)` scores `1.0` and is a TP, as the warning under [Objects of different classes](#objects-of-different-classes) says. A field that goes to the dispatcher directly counts such a pair as top level does.
Expand Down
50 changes: 39 additions & 11 deletions docs/docs/Advanced/hungarian-matching.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,27 +165,55 @@ The Hungarian algorithm produces:

Because the lists are equal length, every element gets paired. Only the TP pair (GT[0] -> Pred[0]) receives field-level analysis; the FD pairs are treated as atomic mismatches.

### Step 4: List Score

The list's score is the sum of the pair scores over the longer list's length ([Score](classification-logic.md#list-contract)). For `List[StructuredModel]` a pair's score is `GT[i].compare_with(Pred[j])["overall_score"]`, which applies each field's threshold, so it can differ from the pairing similarity in Step 1:

| Pair | Pairing similarity | Pair score |
|------|-------------------|-----------|
| GT[0] -> Pred[0] | 0.860 | 0.667 (`description` 0.579 is below 0.7, so it contributes 0.0) |
| GT[1] -> Pred[1] | 0.572 | 0.500 |
| GT[2] -> Pred[2] | 0.124 | 0.000 |

`field_scores["transactions"]` = (0.667 + 0.5 + 0.0) / 3 = **0.3889**, and the account scores (2 x 1.0 + 3 x 0.3889) / 5 = 0.6333.

### Result Structure

```python
"transactions": {
"overall": {
"tp": 1, "fd": 2, "fa": 0, "fn": 0, "fp": 2
},
"fields": {
# Only from the TP pair (GT[0] -> Pred[0])
"transaction_id": {"tp": 1, "fd": 0, "fa": 0, "fn": 0},
"description": {"tp": 1, "fd": 0, "fa": 0, "fn": 0},
"amount": {"tp": 1, "fd": 0, "fa": 0, "fn": 0}
}
gt = Account(account_id="ACC-1", transactions=[
Transaction(transaction_id="TXN-001", description="Coffee shop payment", amount=4.95),
Transaction(transaction_id="TXN-002", description="Grocery store", amount=127.43),
Transaction(transaction_id="TXN-003", description="Gas station", amount=45.67),
])
pred = Account(account_id="ACC-1", transactions=[
Transaction(transaction_id="TXN-001", description="Coffee shop", amount=4.95),
Transaction(transaction_id="TXN-002", description="Online purchase", amount=89.99),
Transaction(transaction_id="TXN-004", description="Restaurant", amount=23.45),
])
result = gt.compare_with(pred, include_confusion_matrix=True)
result["confusion_matrix"]["fields"]["transactions"]
```

With other keys left out, the counts are:

```json
{
"overall": { "tp": 1, "fd": 2, "fa": 0, "fn": 0, "fp": 2 },
"fields": {
"transaction_id": { "overall": { "tp": 1, "fd": 0, "fa": 0, "fn": 0 } },
"description": { "overall": { "tp": 0, "fd": 1, "fa": 0, "fn": 0 } },
"amount": { "overall": { "tp": 1, "fd": 0, "fa": 0, "fn": 0 } }
}
}
```

The `fields` counts come only from the TP pair (GT[0] -> Pred[0]). A TP pair can still hold a failing leaf: the pair cleared `match_threshold`, and its `description` (0.579) did not clear its own `threshold` of 0.7.

## Key Architectural Principles

### Threshold Source

The threshold for Hungarian classification comes from the element model's `match_threshold` class attribute (default 0.7). It is **not** taken from the `ComparableField` on the parent list field.
The threshold for Hungarian classification comes from the element model's `match_threshold` class attribute (default 0.7). It is **not** taken from the `ComparableField` on the parent list field: `ComparableField(threshold=...)` on a `List[StructuredModel]` raises `ValueError` in Python, and `x-aws-stickler-threshold` on an array of models is ignored.

### Metric Separation

Expand Down
Loading
Loading