SGLangTypeAdapter silently drops whitespace_pattern from JsonSchema (vLLM backend handles it correctly)
Bug Description
SGLangTypeAdapter.format_output_type silently drops the whitespace_pattern field from a JsonSchema instance. When a user sets whitespace_pattern on their schema — to control whitespace in generated JSON — the SGLang backend ignores it entirely and passes no whitespace constraint to the model. The vLLM backend handles this correctly.
Affected file
src/outlines/models/sglang.py, lines 74–80:
elif isinstance(term, JsonSchema):
return OpenAITypeAdapter().format_json_output_type(
json.loads(term.schema) # whitespace_pattern is never read
)Contrast with vLLM (correct behaviour)
src/outlines/models/vllm.py, lines 66–70:
structured_outputs = {"json": json.loads(term.schema)}
if term.whitespace_pattern:
structured_outputs["whitespace_pattern"] = term.whitespace_pattern
return structured_outputsMinimal reproducer
import json
from outlines.types.dsl import JsonSchema
js = JsonSchema('{"type": "string"}', whitespace_pattern=r"[ ]?")
# SGLang path (buggy):
sglang_result = {"json": json.loads(js.schema)} # whitespace_pattern missing
# vLLM path (correct):
vllm_result = {"json": json.loads(js.schema)}
if js.whitespace_pattern:
vllm_result["whitespace_pattern"] = js.whitespace_pattern
assert "whitespace_pattern" not in sglang_result # passes — bug confirmed
assert "whitespace_pattern" in vllm_result # passes — vLLM is correctImpact
Users who rely on whitespace_pattern to control output whitespace will get silently wrong results when using the SGLang backend — no error is raised, but the constraint is not applied. This is a silent correctness failure.
Fix
Forward whitespace_pattern in SGLangTypeAdapter.format_output_type, mirroring the vLLM implementation:
elif isinstance(term, JsonSchema):
structured_outputs = {"json": json.loads(term.schema)}
if term.whitespace_pattern:
structured_outputs["whitespace_pattern"] = term.whitespace_pattern
return structured_outputsEnvironment
Reproduced on Python 3.12 with Outlines main branch (2026-08-13).
Source: dottxt-ai/outlines