Repository navigation
fix(grammar): preserve type-specific constraints in schema unions - #2449
Open
remote-controlled-man wants to merge 2 commits into
Open
remote-controlled-man wants to merge 2 commits into
remote-controlled-man wants to merge 2 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.
A JSON Schema such as
{"type":["string","null"],"minLength":2,"maxLength":3}currently compiles to an unrestricted string-or-null grammar. The type-list expansion drops every sibling keyword, so array item limits, object properties, string patterns, and formats are lost as well.Preserve the schema keywords when expanding each type branch and let the existing type-specific conversion apply them. Add native grammar-sampler regression tests for valid and invalid values, nullable types in either order, single-type controls, mixed non-null types, and nested references. Include an Unreleased changelog entry.
Validation on macOS arm64, Python 3.12, and the locally built bundled llama.cpp library:
create_chat_completion(response_format=...)with the tiny stories15M Q4_0 GGUF produces the constrained{"name":"ab"}value with both single and nullable type lists.make test: 46 passed, with no skips (including transformer, recurrent, hybrid, and embedding model tests).make lint: Ruff checks and formatting pass for all 29 Python source/test files.This changes Python schema conversion only. No model weights, native backend code, or new dependencies are included. Cross-platform and GPU backend matrices remain for CI.