Fix the JsonSchema whitespace_pattern being ignored by the backend#1924
Merged
RobinPicard merged 2 commits intoJul 20, 2026
Merged
Conversation
The whitespace_pattern set on a JsonSchema output type was not passed to the backend during generation, so it had no effect on the default outlines_core backend even though to_regex already honors it. Thread the whitespace_pattern through the backend interface and forward it to build_regex_from_schema. The llguidance and xgrammar backends raise NotImplementedError when a pattern is set, since they compile the schema with their own grammar engines and cannot apply it.
|
📚 Documentation preview: https://dottxt-ai.github.io/outlines/pr-preview/pr-1924/ Preview updates automatically with each commit. |
…ends The backends raise NotImplementedError when whitespace_pattern is set, but only the outlines_core backend had a test. Add a regression test for each so the unsupported whitespace path is exercised.
RobinPicard
approved these changes
Jul 20, 2026
RobinPicard
left a comment
Contributor
There was a problem hiding this comment.
Great PR, thanks! And good idea to raise an error when the parameter is used with xgrammar/llguidance instead of silently ignoring it.
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.
Problem
When you set
whitespace_patternon aJsonSchemaoutput type, it has no effect during generation on the defaultoutlines_corebackend. The JSON is always produced with the default whitespace, whatever pattern you pass.The cause is a dropped argument. When the generator builds the logits processor for a
JsonSchema, it passes onlyterm.schemato the backend and never passesterm.whitespace_pattern(src/outlines/generator.py). The backend then callsbuild_regex_from_schema(json_schema)without the pattern (src/outlines/backends/outlines_core.py). Callingto_regex(JsonSchema(...))directly does apply the pattern, so the two paths disagree.whitespace_patternis a documented parameter (docs/features/core/output_types.md) and worked in v0, where it was added to control JSON whitespace (#916). It stopped being applied when JSON-schema handling moved to the backend layer in the v1 refactor.Fix
Pass
whitespace_patternthrough to the backend so it is actually used:term.whitespace_patternwhen it builds the JSON-schema logits processor.get_json_schema_logits_processor(the backend dispatcher,BaseBackend, andOutlinesCoreBackend) takes an optionalwhitespace_patternand forwards it tobuild_regex_from_schema.llguidanceandxgrammarbackends build the grammar their own way and cannot use this pattern, so they raiseNotImplementedErrorif one is set instead of ignoring it.The default (
whitespace_pattern=None) behaves exactly as before.Tests
Two new tests in
tests/backends/test_outlines_core.py:build_regex_from_schema,None.Both fail on
mainand pass with this change (verified by stashing the fix). Thetests/backends/test_outlines_core.pysuite passes (one MLX test is skipped).ruffandmypyare clean.Docs
docs/features/core/output_types.mdnow sayswhitespace_patternis applied by theoutlines_corebackend, and thatllguidance/xgrammardo not support it.