Skip to content
Open
Changes from 2 commits
Commits
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
9 changes: 8 additions & 1 deletion docs/docs/Advanced/dynamic-models.md
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,12 @@ declared type cannot support reports `type`, because the type default is what
shipped -- `row['why']` records the refusal. These are the same values
`stickler.evaluate()` reports, so the two paths read alike.

`explicit` is not always a field you configured. A model built with `from_json_schema()`
and no inference flag infers nothing, so `explain()` reports every field as `explicit`,
including fields left at the type default. A model from `from_pydantic()`, or a
hand-written `StructuredModel` class, does the same: its fields report `explicit` even
where Stickler picked the comparator from the type or the name.

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.

Must fix 1 and Smaller 1 and 2. Measured on 540bc2f8:

class H(StructuredModel): total: float; invoice_id: int; vendor: str
   total       LevenshteinComparator 0.7  explicit
   invoice_id  LevenshteinComparator 0.7  explicit
   vendor      LevenshteinComparator 0.7  explicit
from_json_schema, no object-level key, "x-aws-stickler-comparator": "auto" on total
   vendor      LevenshteinComparator 0.5  explicit
   total       NumericComparator     0.95 name-token

With this applied, the docs check still passes and the link resolves.

Suggested change
`explicit` is not always a field you configured. A model built with `from_json_schema()`
and no inference flag infers nothing, so `explain()` reports every field as `explicit`,
including fields left at the type default. A model from `from_pydantic()`, or a
hand-written `StructuredModel` class, does the same: its fields report `explicit` even
where Stickler picked the comparator from the type or the name.
`explicit` is not always a field you configured. A model from `from_json_schema()`
infers only the fields that `x-aws-stickler-infer-unspecified` or
`x-aws-stickler-comparator: "auto"` reaches, so every other field reports `explicit`,
including fields left at the type default. A model from `from_pydantic()` reports
`explicit` for every field, even where Stickler picked the comparator from the type or
the name; run `stickler.eval_for()` on the Pydantic class itself to see `type` and
`name-token`. A hand-written `StructuredModel` class also reports `explicit` for every
field, but nothing there is picked from the name, and a bare `int` or `float` field is
compared as text by `LevenshteinComparator` (see
[Precedence, in one line](../Getting-Started/thresholds-and-metrics.md#precedence-in-one-line)).


`row['why']` gives the full reasoning:

```python
Expand All @@ -504,7 +510,8 @@ Both the comparator and the threshold, matching `stickler.evaluate()`:
| `total: float` | NumericComparator @ 0.5 | NumericComparator @ 0.95 |
| `paid: bool` | ExactComparator @ 0.5 | ExactComparator @ 1.0 |
| `issued` (`format: date`) | DateComparator @ 1.0 | DateComparator @ 0.95 |
| `vendor: str` | LevenshteinComparator @ 0.5 | LevenshteinComparator @ 0.85 |
| `vendor: str` | LevenshteinComparator @ 0.5 | LevenshteinComparator @ 0.85 (from the name `vendor`) |
| `color: str` (no name rule matches) | LevenshteinComparator @ 0.5 | LevenshteinComparator @ 0.7 |
| `amounts: List[float]` | NumericComparator @ 0.5 | NumericComparator @ 0.95 |
| `meta: dict` | ExactComparator @ 1.0 | ANLSStarComparator @ the model's `match_threshold` |

Expand Down