Skip to content

fix(grammar): preserve type-specific constraints in schema unions - #2449

Open
remote-controlled-man wants to merge 2 commits into
abetlen:mainfrom
remote-controlled-man:codex/prflow-4c599f476a78
Open

remote-controlled-man wants to merge 2 commits into
abetlen:mainfrom
remote-controlled-man:codex/prflow-4c599f476a78

Conversation

@remote-controlled-man

Copy link
Copy Markdown
Contributor

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:

  • Original implementation: 14 regression failures and 9 passing controls in the grammar module.
  • Fixed implementation: 23 grammar tests pass.
  • Real 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.
  • Full 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.

Copilot AI balanced review requested due to automatic review settings November 25, 2026 04:35

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants