[feature] [xgrammar] support patternProperties and propertyNames kw for object types#42904
[feature] [xgrammar] support patternProperties and propertyNames kw for object types#42904cjackal wants to merge 2 commits into
patternProperties and propertyNames kw for object types#42904Conversation
There was a problem hiding this comment.
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.
| "student": { | ||
| "type": "object", | ||
| "properties": { | ||
| "name": {"type": "string"}, | ||
| "grade": {"type": "string"}, | ||
| }, | ||
| "required": ["name", "grade"], | ||
| "patternProperties": {"^grade$": {"type": "string"}}, | ||
| }, |
There was a problem hiding this comment.
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.
| "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_]*$"}, | |
| }, |
|
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-filesThen, commit the changes and push to your branch. For future commits, Tip Is
|
321dfa4 to
f9aff35
Compare
Signed-off-by: cjackal <44624812+cjackal@users.noreply.github.com>
Signed-off-by: cjackal <44624812+cjackal@users.noreply.github.com>
f9aff35 to
31409f3
Compare
Purpose
Support
patternPropertiesandpropertyNameskeywords forobjecttypes 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 sincexgrammar>=0.2.1by 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
supported_models.mdandexamplesfor a new model.