Skip to content

[feature] [xgrammar] support patternProperties and propertyNames kw for object types#42904

Open
cjackal wants to merge 2 commits into
vllm-project:mainfrom
cjackal:allow-xgrammar-patternproperties
Open

[feature] [xgrammar] support patternProperties and propertyNames kw for object types#42904
cjackal wants to merge 2 commits into
vllm-project:mainfrom
cjackal:allow-xgrammar-patternproperties

Conversation

@cjackal

@cjackal cjackal commented May 18, 2026

Copy link
Copy Markdown
Contributor

Purpose

Support patternProperties and propertyNames keywords for object types in JSON schema for xgrammar structured output backend. Makes openai-compatible endpoint more feature-complete by covering more JSON schema under a structured output engine. This is supported since xgrammar>=0.2.1 by mlc-ai/xgrammar#594.

Test Plan

The corresponding unit test has been updated so that it can be tested continuously in CI pipeline.

Test Result

Via CI result.


Essential Elements of an Effective PR Description Checklist
  • The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
  • The test plan, such as providing test command.
  • The test results, such as pasting the results comparison before and after, or e2e results
  • (Optional) The necessary documentation update, such as updating supported_models.md and examples for a new model.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates the xgrammar dependency to version 0.2.1 and enables support for patternProperties and propertyNames within the backend_xgrammar module. Correspondingly, the test suite was updated to treat these features as supported. Feedback was provided regarding the test implementation, specifically noting that the patternProperties test case was redundant and that a test case for propertyNames was missing; a code suggestion was offered to improve coverage for these features.

Comment on lines +71 to +79
"student": {
"type": "object",
"properties": {
"name": {"type": "string"},
"grade": {"type": "string"},
},
"required": ["name", "grade"],
"patternProperties": {"^grade$": {"type": "string"}},
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The test case for patternProperties is currently redundant as it only matches a property already defined in properties. Furthermore, there is no test case for propertyNames, which is one of the primary features introduced in this PR. I suggest updating the student object to more effectively test patternProperties with dynamic keys and to include a test for propertyNames to ensure full coverage of the new functionality.

Suggested change
"student": {
"type": "object",
"properties": {
"name": {"type": "string"},
"grade": {"type": "string"},
},
"required": ["name", "grade"],
"patternProperties": {"^grade$": {"type": "string"}},
},
"student": {
"type": "object",
"properties": {
"name": {"type": "string"},
},
"required": ["name"],
"patternProperties": {"^grade_[0-9]+$": {"type": "integer"}},
"propertyNames": {"pattern": "^[a-zA-Z_][a-zA-Z0-9_]*$"},
},

@mergify

mergify Bot commented May 18, 2026

Copy link
Copy Markdown
Contributor

Hi @cjackal, the pre-commit checks have failed. Please run:

uv pip install pre-commit>=4.5.1
pre-commit install
pre-commit run --all-files

Then, commit the changes and push to your branch.

For future commits, pre-commit will run automatically on changed files before each commit.

Tip

Is mypy failing?
mypy is run differently in CI. If the failure is related to this check, please use the following command to run it locally:
# For mypy (substitute "3.10" with the failing version if needed)
pre-commit run --hook-stage manual mypy-3.10

cjackal added 2 commits June 13, 2026 03:21
Signed-off-by: cjackal <44624812+cjackal@users.noreply.github.com>
Signed-off-by: cjackal <44624812+cjackal@users.noreply.github.com>
@cjackal cjackal force-pushed the allow-xgrammar-patternproperties branch from f9aff35 to 31409f3 Compare June 13, 2026 03:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant