fix(schema): respect maxItems and avoid crash on minItems>=3 in example generator#1553
Open
devteamaegis wants to merge 1 commit into
Open
fix(schema): respect maxItems and avoid crash on minItems>=3 in example generator#1553devteamaegis wants to merge 1 commit into
devteamaegis wants to merge 1 commit into
Conversation
…efault in example generator
|
@devteamaegis is attempting to deploy a commit to the Guardrails AI Team on Vercel. A member of the Team first needs to authorize it. |
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.
What's broken
gen_arrayinguardrails/schema/generator.pyreads the array upper bound frommaxItem, but the JSON Schema keyword ismaxItems(also what the function's docstring claims to support). Two effects:maxItemsis silently ignored — the generator always uses the default cap of2.minItems >= 3crashes withValueError: empty range in randrange(...), becauserandint(min_items, 2)is called withmin_items > 2.generate_exampleis invoked during reask setup (guardrails/actions/reask.py), so a guard with aminItems >= 3array field raises on reask.Why it happens
Misspelled schema key
maxItem(should bemaxItems) pins the upper bound to the default2, somaxItemsis never read andrandint(min_items, 2)blows up wheneverminItems > 2.Fix
Read
maxItems(correct key), default it tomax(minItems, 2), and clampmax_items = max(min_items, max_items)so a user-suppliedminItems > maxItemscan't makerandintraise.Test
Added a parametrized test covering the crash case, the previously-ignored
maxItems, and a tightmaxItems:1bound. Fails before the change (2 failures), passes after.