Skip to content

docs(489): say what drives the 0.85 on a str field and what explain() reports without the flag - #673

Open
MaxonT wants to merge 6 commits into
awslabs:devfrom
MaxonT:contrib/489-auto
Open

MaxonT wants to merge 6 commits into
awslabs:devfrom
MaxonT:contrib/489-auto

Conversation

@MaxonT

@MaxonT MaxonT commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Following up on the claim I left on #489, this covers the two items I said I would take, as far as they are still true on dev.

This covers the parts of #489 that are still true on current dev. I claimed items 2 and 3 on the issue; item 1 (where match_threshold is read) already lists all three nested field types on dev, so I left it alone.

Item 2: the "What inference chooses" table labels rows by type, so vendor: str reads as if 0.85 were the str default. It comes from the name vendor. A str field with no matching name gets LevenshteinComparator at 0.7. I added that row and noted the name on the vendor row.

Item 3, what is left of it: the sentence under the explain() example is already correct for fields that were configured or inferred, and the code now reports the inference trail instead of explicit. One case still reads differently from what a reader expects: a model built with from_json_schema() and no inference flag reports every field as explicit, including fields left at the type default, because nothing was inferred. I added one sentence saying so.

Part of #489, so I am not using "Fixes". The issue's wording of item 3 and its other sentences I did not change.

How was this tested?

  • Ran the examples on this head with pip install -e . in a clean venv (the printed stickler path is the checkout): model_from_json with infer_unspecified_fields gives vendor: str Levenshtein 0.85 name-token and color: str Levenshtein 0.7 type; from_json_schema() without the flag gives both fields Levenshtein 0.5 explicit.
  • mkdocs build from docs/ exits 0 and the new table row is in the rendered Advanced/dynamic-models page.
  • Not run: make docs-build with --frozen through uv, the link checker, and the test suite (docs only, no code or test files touched).

… reports without the flag

Signed-off-by: Ym <173550318+MaxonT@users.noreply.github.com>

@vawsgit vawsgit left a comment

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.

✅ LGTM!

Checked at 4aa668f2. The merge base is dev 0a4820f4. The diff touches only docs/docs/Advanced/dynamic-models.md, and git diff --stat origin/dev HEAD -- src tests is empty.

Measured on dev 0a4820f4 (PYTHONPATH=<dev>/src, with inspect.getfile(stickler) pointing at that tree). Each line below is explain() output, showing comparator, threshold and source:

Model vendor: str color: str
model_from_json, infer_unspecified_fields: true Levenshtein 0.85 name-token Levenshtein 0.7 type
from_json_schema, x-aws-stickler-infer-unspecified Levenshtein 0.85 name-token Levenshtein 0.7 type
from_json_schema, no flag Levenshtein 0.5 explicit Levenshtein 0.5 explicit
  • The new vendor row is right: the 0.85 comes from the name. label and issued_date also get 0.7 type, so 0.7 is the str default.
  • The new color row is right in both columns.
  • The new explain() sentence is right. With no flag, total and paid (left at the type default) also report 0.5 explicit.

Issue keyword. Part of #489 is right.

  • Item 1 is already done on dev. dynamic-models.md:346 names all three nested field types.
  • Item 2 is done by this PR.
  • Item 3 is partly done. See the optional inline note: from_pydantic() and hand-written StructuredModel classes still report explicit for fields Stickler chose. #489 should stay open for that.

No CI checks are reported on this head yet. I did not run the suite, because the PR changes no code or tests.

Comment thread docs/docs/Advanced/dynamic-models.md Outdated
`stickler.evaluate()` reports, so the two paths read alike.

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.

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.

Optional, not blocking. This sentence is true, but from_json_schema() is not the only case. On dev 0a4820f4, explain() also reports explicit for fields Stickler chose in these two cases:

from_pydantic(P)  # class P(BaseModel): vendor: str; color: str; total: float
   vendor  LevenshteinComparator 0.85 explicit
   color   LevenshteinComparator 0.7  explicit
   total   NumericComparator     0.95 explicit
class H(StructuredModel): a: str = ComparableField(); vendor: str; color: str
   a       LevenshteinComparator 0.5  explicit
   vendor  LevenshteinComparator 0.7  explicit

eval_for(P) on the plain Pydantic class reports name-token / type for the same fields. So the line above, "source is explicit for a field you configured", is still not true for those two paths. That is #489 item 3's remaining case. You can widen this sentence here or leave it to a follow-up. Part of #489 already keeps the issue open.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for naming the two cases. I reproduced both on the dev branch tip with PYTHONPATH=src. from_pydantic(P) reports explicit at 0.85, 0.7 and 0.95 for vendor, color and total. The StructuredModel class reports explicit for all three fields. eval_for(P) on the plain Pydantic class reports name-token, type and name-token.

I widened the sentence in 540bc2f. It now says explicit is not always a field you configured, and it covers from_json_schema() with no flag, from_pydantic() and hand-written StructuredModel classes. The change touches only this docs file. I did not run the full suite or the docs build on this head. Part of #489 stays, because the explain() source behaviour itself is unchanged.

… report explicit

Signed-off-by: Ym <173550318+MaxonT@users.noreply.github.com>

@sromoam sromoam left a comment

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.

Thanks @MaxonT, and thanks for picking up vawsgit's note so quickly. I checked 540bc2f8, which merges cleanly into current dev (ce0f710b). Both table rows are right: vendor: str gets Levenshtein 0.85 name-token and color: str gets 0.7 type through model_from_json and from_json_schema with the flag, and both get 0.5 explicit from from_json_schema without it. The docs check (make -C docs check) passes with only the six known griffe warnings. The sentence widened in 540bc2f says one thing the code doesn't do, though.

Must fix

  1. A hand-written StructuredModel takes nothing from the name, and a bare float or int stays on LevenshteinComparator (dynamic-models.md:485-487). The new sentence says its fields report explicit "even where Stickler picked the comparator from the type or the name". On this head, class H(StructuredModel): total: float; invoice_id: int; vendor: str gives all three LevenshteinComparator @ 0.7, and total 100.0 against 100.5 scores 0.8 by edit distance. vawsgit's repro shows the same for vendor: 0.7, not the 0.85 its name gets on the inference path. thresholds-and-metrics.md:158 already says a bare int or float is compared as text, so the two pages now disagree, and a reader of this one would expect total: float to get NumericComparator. Suggestion inline.

Smaller

  1. "auto" infers without the flag (:484). With no object-level key and "total": {"type": "number", "x-aws-stickler-comparator": "auto"}, explain() reports total as NumericComparator 0.95 name-token, so "infers nothing" does not hold there. The page calls only the model-level key the flag (:435). The same suggestion covers it.

  2. Point to the real trail for a Pydantic class (:485). stickler.eval_for(P).explain() on the plain class reports name-token and type, with the same comparators and thresholds that from_pydantic(P) reports as explicit. One clause saying so, as #489's proposed fix does, gives the reader something to do about the caveat. Also in the suggestion.

  3. CHANGELOG. Readers could have taken 0.85 as the str default and explicit as "you configured this", so a ### Documentation line under [Unreleased] fits (RELEASING.md, "What belongs in the changelog"). Something like:

    - Dynamic Model Creation no longer reads as if 0.85 were the `str` default:
      `vendor: str` gets it from its name, and a `str` field that no name rule
      matches gets 0.7. The page also says when `explain()` reports `explicit`
      for a field you did not configure
      ([#489](https://github.com/awslabs/stickler/issues/489)).

One heads-up: we're not merging anything outside the 1.1.0 milestone until 1.1.0 lands, so this will wait until after that even once it's ready.

Comment thread docs/docs/Advanced/dynamic-models.md Outdated
Comment on lines +483 to +487
`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)).

…gelog entry

Address the review on 540bc2f: the explicit paragraph now matches the
measured output for from_json_schema() with and without the flag
(including "auto"), from_pydantic(), and hand-written StructuredModel
classes, with a link to the threshold precedence table. Add a
Documentation entry under [Unreleased].

Part of awslabs#489.

Signed-off-by: Ym <173550318+MaxonT@users.noreply.github.com>
@MaxonT

MaxonT commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for catching this, and for the repro and suggested wording. I pushed d23eb45, which uses your paragraph. It now says from_json_schema() infers only the fields reached by x-aws-stickler-infer-unspecified or x-aws-stickler-comparator: "auto". It points to stickler.eval_for() on the plain Pydantic class for type and name-token. It also says a hand-written StructuredModel takes nothing from the name and compares a bare int or float with LevenshteinComparator, with a link to "Precedence, in one line".

I also added the ### Documentation entry under [Unreleased] in CHANGELOG.md. make -C docs check exits 0 with the six known griffe warnings. No code or tests changed, so I did not run the suite, and no CI runs are reported on this head yet. I understand this waits until after 1.1.0.

@sromoam sromoam added the anytime Non-breaking improvement off the release critical path: merge whenever it's ready label Dec 4, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

anytime Non-breaking improvement off the release critical path: merge whenever it's ready

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants