Skip to content

[Feature] Support disabling of any_whitespace for XGrammar JSON structured outputs #8250

@lulor

Description

@lulor

Checklist

Motivation

When using JSON structured outputs, the generation can get stuck on endlessly repeating whitespace characters (#2216, #2414, #1438, dottxt-ai/outlines#691). For the outlines and llguidance backends, it is possible to avoid this issue by leveraging the constrained_json_whitespace_pattern server argument, but for xgrammar such parameter is ignored.

XGrammar supports a similar any_whitespace argument that, although less flexible, would at least allow to avoid the infinite loop issue in generation (mlc-ai/xgrammar#345). It would be useful for SGLang to expose such parameter as a server argument (something like disable-any-whitespace), especially considering that XGrammar is the default and recommended backend for constrained generation. Furthermore, I think it would be useful if the documentation mentioned that the constrained-json-whitespace-pattern is not supported for XGrammar.

I'm happy to open a small PR with these changes (which should be quite minimal, unless I'm missing something).

Related resources

vllm-project/vllm#15252

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions