Repository navigation
fix(grammar): enforce array length limits without items - #2463
Open
remote-controlled-man wants to merge 3 commits into
Open
remote-controlled-man wants to merge 3 commits into
remote-controlled-man wants to merge 3 commits into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Array schemas that specify
minItemsormaxItemswithoutitemsorprefixItemsfall back to the unrestricted array primitive. For example,{"type":"array","minItems":1,"maxItems":1}incorrectly permits both[]and[1,2].Route these schemas through the existing repetition builder, using the existing JSON value rule for unconstrained elements. Keep typed arrays and prefix tuples on their existing paths. Explicitly raise ValueError for unsatisfiable repetition bounds (maximum below minimum), including the shared typed-array and string-length paths, instead of producing a grammar that violates the maximum.
Add native grammar-sampler regressions for minimum/maximum/exact/zero lengths, nested arrays, all JSON element types (including UTF-8), invalid/incomplete documents, and typed-array/tuple controls. The same tests on the original implementation produce 11 failures and 35 passing controls; the fix passes all 46 grammar tests.
Validation on macOS arm64 / Python 3.12.14, bundled llama.cpp
f5e6915c2:make test: 69 passed, no skips.make lint: Ruff lint and formatting passed for all 29 files.This follows the JSON Schema array length contract. The explicit empty-
itemsschema case is handled separately in #2378.Prepared with AI assistance, including independent review.