Repository navigation
Conversation
f7507fe to
303c786
Compare
vawsgit
left a comment
There was a problem hiding this comment.
needs changes
Two blockers and one medium. I ran the repro for blocker 1 on the PR head (303c786).
Blockers
1. The required check makes the library's own to_json_schema() output unimportable.
json_schema_importer.py L758-L763 raises for any decision property listed in required. The PR body says exports never put decision fields in required. That is false for a decision field declared with default=..., which dev already tests (tests/decisions/test_config_round_trip.py::test_round_trip_keeps_a_required_decision_field).
class M(StructuredModel):
q: Optional[str] = Choice(["a", "b"], default=...)
note: str
s = M.to_json_schema()
# s["required"] == ['q', 'note']; s["properties"]["q"]["type"] == ['string', 'null']
StructuredModel.from_json_schema(s)- PR head:
ValueError: Field 'q' is a choice decision field, which is None when its question was not asked; remove it from 'required' origin/dev(3dc3aec): imports, and the rebuilt field hasis_required() == False.
The message is also wrong here. A required field may be None; "required" does not mean "question asked". ["string","null"] plus required is the usual JSON Schema spelling of "must be present, may be null".
What to change: keep the field required and nullable, or drop the check. Do not raise. Add a round-trip test for a required decision field.
2. The branch is stale against dev and conflicts with dev's required semantics.
git merge-tree against origin/dev (3dc3aec) conflicts in three files: CHANGELOG.md, docs/docs/Guides/Evaluation/decision-models.md and json_schema_importer.py.
devnow computesdefault = None if field_info.is_required() else field_info.defaultand calls_decision_default(spec, default, field_path)(the fix(703) work). This PR'srequiredcheck contradicts it.dev's docs now say a decision field'srequired"works as it does on any field". This PR's text says it "must not be inrequired".
What to change: rebase on dev, and settle the required behaviour against blocker 1 and #703. A hand-merge of the type check onto dev passes the full suite (7501 passed, 3 skipped, 1 xfailed), but no existing test covers blocker 1.
Medium
3. The CHANGELOG entry sits in a released section.
On dev, ## [Unreleased] is empty and ## [1.1.0] - 2026-12-04 is dated, so "still unreleased" in the PR body is no longer true. After 1.1.0, rejecting a required property, a wrong type, or a choice with enum/format/const is a change to input that 1.1.0 accepted. RELEASING.md requires a PR that relies on "the docs never allowed it" to cite the docs line that made the input invalid, in the PR and in the CHANGELOG entry. This PR cites none. Move the entry under [Unreleased] as Changed or Fixed and add the citation (or settle blocker 1 so the required part goes away).
4. Test gap: test_required_is_rejected never uses a nullable type.
tests/decisions/test_schema_import.py L47-L54 only passes the bare json_type. Mutation: changing the check to if field_info.is_required() and not unwrap_optional(field_info.annotation)[1]: left all 22 tests passing. Add the [type, "null"] plus required case; it is the case blocker 1 hits.
Verified
- 22 new tests pass on the PR head. On
devsource with the new test file copied in, 14 fail and 8 pass, as the PR body says. - Full suite on the PR head with all extras installed: 7269 passed, 3 skipped, 1 xfailed (the PR body's 13 skips pass once the extras are installed).
- 10 of 11 mutations of the type and
requiredchecks are killed by the new tests. The survivor is the one in item 4. - Still accepted as before:
string,["string","null"],["null","string"],anyOf/oneOfwith null,nullable: true, length and pattern limits,default: null,$refto a plain string,["boolean","null"]for noul. - Rejected as intended: wrong type for each kind, multi-type unions,
type: nullonly,array/object,enum/const/format,$refto an integer or enum. Error messages name nested paths (o.q,o[].q). - Non-decision required properties are unchanged.
303c786 to
ab8c4bf
Compare
|
Thanks for the careful review and the repro. The branch is now one commit rebased on
One more thing I noticed: |
vawsgit
left a comment
There was a problem hiding this comment.
✅ LGTM!
All four findings from my review of 303c786 are fixed at ab8c4bf. No medium or high findings remain.
Previous findings
requiredcheck (fixed). The raise is gone. The diff adds only the type check atjson_schema_importer.pyL751-L757 and keeps dev's_decision_default/is_required()path. My repro (q: Optional[str] = Choice(["a","b"], default=...)plusnote: str) now exportsrequired == ['q', 'note'],q.type == ['string', 'null'], imports, and the rebuilt field hasis_required() == False, the same asdev. Before:ValueError ... remove it from 'required'.- Stale branch (fixed). One commit on
origin/dev(9680269).git merge-tree --write-tree origin/dev pr720is clean. The docs keep dev's "requiredworks as it does on any field". - CHANGELOG (fixed). The entry is under
[Unreleased]/### Fixedwith an "Upgrade note:". The quoted docs line exists at base (decision-models.md:48) and the quote is exact. - Nullable plus required test gap (fixed).
test_required_importsandtest_exported_required_decision_field_round_tripscover each kind, bare and withnull. Restoring the oldrequiredraise, in either the plain or the nullable-exempt form, fails them.
Verified
tests/decisions/test_schema_import.py: 28 pass at the PR head. With the same file ondevsource, 13 fail and 15 pass, as the PR body says.tests/decisionsas a whole: 239 passed.- Full suite without the llm/bert extras (not installable on this host): 7490 passed, 13 skipped (missing extras), 1 xfailed. The PR body reports 7507 passed with extras.
- 12 of 12 meaningful mutations of the type check are killed (skip when nullable, skip nested, skip per kind, let enum/const/format through, accept float or bool for score, accept a bool subclass for noul, remove the check). The one survivor was equivalent.
- 33 property shapes compared on
devand the PR head:anyOf/oneOfwith null,nullable: true,["null", T],default: null, length/pattern/range limits,$refandanyOf[$ref, null]to a plain type. All behave the same on both. Wrong types now raise with the field path in the message (items[].q).
Non-blocking, optional
- The message always says "no enum, const or format", even for a plain wrong type, and
format: email/hostnameon a choice are still accepted. - There is no test for a
$refto a wrong-type definition. The same check covers it. - One judgement call for the maintainers: the cited docs line is written for a hand-written config. The PR adds a docs sentence for JSON Schema, and the CHANGELOG entry says so openly. The author offered warn-first as an alternative.
stickler.decisionsis marked experimental.
sromoam
left a comment
There was a problem hiding this comment.
Thanks @Markgugg, this fixes all four of vawsgit's points, and dropping the required raise rather than reshaping it was the right call. At head ab8c4bf (one commit on dev 9680269d, so the merge is a fast-forward), tests/decisions/test_schema_import.py gives 28 passed. With the importer back at dev it gives 13 failed, 15 passed. Full suite with all extras: 7507 passed, 3 skipped, 1 xfailed. The entry lands under ## [Unreleased] / ### Fixed. On the judgement call, raising in 1.1.1 is fine and there's no need to warn first. The guide gives a decision field one answer type, model_from_json() already refuses any other, and 1.1.0 ignored the schema's type instead of honouring it. RELEASING.md counts that as input misread, so the citation holds.
Must fix
- The guide, the CHANGELOG and the error say a
formatraises, and most don't (decision-models.md:54,CHANGELOG.md:23,json_schema_importer.py:757). The check compares the imported Python type, so it only refuses aformatthat imports as something other thanstr. On this headdate,time,date-time,urianduuidraise, whileemail,hostname,ipv4,durationandpasswordimport asOptional[str]. Either refuse anyformaton a decision property, or say what the check does. For example: "itstypemust import as its answer type (string,integerorboolean, alone or withnull), so anenum, aconstor aformatsuch asdate-timeraisesValueError". The error text should match, and for a plain wrong type it can leave out the enum/const/format clause.
Smaller
- Title and closing keyword. The title still says "or required", and it becomes the squash commit, so please retitle it to match the commit ("raise for a decision property whose type is not its kind's"). Also,
Fixes #707would close therequiredhalf of #707, which this rightly leaves alone. To your question: makingfrom_json_schema()matchmodel_from_json()onrequiredis the follow-up I left in #724, so it belongs in a separate PR. Please change it toRefs #707and I'll keep #707 open for that. - Optional: a
$refto a wrong-type definition raises here too, but no test pins it.
from_json_schema() rebuilt every x-aws-stickler-decision property as an optional field of its kind's type, whatever the property's own type. An integer-typed choice came back as Optional[str], with no warning. _decision_field now raises ValueError naming the field when the property does not import as its kind's answer type (string for choice, integer for score, boolean for noul, alone or with null). It reads the parsed field, so a $ref or nested property is checked the same way, and an enum, a const or a format that imports as another type (such as date-time) is rejected too. A format that imports as a string, such as email, is not. required is left as dev reads it: a required decision property, including the ["<type>", "null"] plus required that to_json_schema() writes for a field declared with default=..., still imports. Refs awslabs#707
ab8c4bf to
621896a
Compare
|
Thanks @sromoam, and thanks for settling the release question. Pushed as one commit on
|
Pull Request
Issue Reference
Refs #707 (the
requiredhalf stays open for #724)Description of Changes
from_json_schema()ignored thetypeof a property withx-aws-stickler-decision. An integer-typed choice came back asOptional[str]with no warning. It now raises aValueErrorthat names the field, the same way a conflicting comparator or threshold is already rejected.requiredis not touched. A required decision property imports as it does ondev, including the["string", "null"]plusrequiredthatto_json_schema()writes for a field declared withdefault=....Changes Made
_decision_fieldraises when the property doesn't import as its kind's answer type (stringfor choice,integerfor score,booleanfor noul, alone or withnull). It reads the parsed field, so$refand nested properties are checked too. Anenum, aconstor aformatthat imports as another type (such asdate-time) is rejected as well; aformatthat imports as a string (such asemail) is not. The error only mentions enum/const/format when the property imported as something other than a plain type.[Unreleased].Rebased on current
dev(9680269) as one commit.Why These Changes Are Needed
The schema said one thing and the model did another, with no warning.
Is it breaking?
I couldn't find a docs line that made a wrong
typeon a JSON Schema decision property invalid. The closest is in the Evaluating Decision Models guide, and it only covers a hand-written Stickler config:model_from_json()already enforces that line, andfrom_json_schema()builds the same decision fields, so I read a JSON Schema property with another type as input the docs never allowed. Under RELEASING.md that makes the entry a Fixed with an "Upgrade note:" and the line above quoted in it. I also added a sentence to the guide saying the same rule applies to a JSON Schema property. Only hand-written schemas can hit it;to_json_schema()output always imports.If you read that line as covering only the config path, I can switch this to a warning now and a raise in a later minor release instead.
Testing
New
tests/decisions/test_schema_import.py(32 tests) covers:nullrequiredfor each kind, bare and withnull, which importsitems[].q)enum,const,format: dateandformat: date-timeon a choice are rejected;format: emailimports$refto a wrong-type definition is rejectedto_json_schema()round trip with and without description and weightChoice(..., default=...)), which exports as["string", "null"]plusrequiredand imports again16 of the 32 fail on
devand all pass here. Full suite with--extra llm --extra bert: 7511 passed, 3 skipped, 1 xfailed.ruff check .is clean.Checklist
CHANGELOG.mdentry added under[Unreleased], or not needed becausenothing user-visible changed (see RELEASING.md)
Additional Notes
from_json_schema()rebuilds a required decision field as not required (default = None if field_info.is_required() ...), whilemodel_from_json()keeps it required. The new test checks that it imports and round-trips, not which wayrequiredgoes. Happy to make the schema path keep it required here or in a follow-up if you want them to match.