From 7bcb62cdf396e2fcabe743fc54363e628bcecfee Mon Sep 17 00:00:00 2001 From: pos-ei-don <1822533+pos-ei-don@users.noreply.github.com> Date: Mon, 15 Jun 2026 11:40:55 +0000 Subject: [PATCH] fix(vllm): structured outputs silently ignored on vLLM >= 0.23 vLLM >= 0.23 removed GuidedDecodingParams (now StructuredOutputsParams) and renamed the SamplingParams field guided_decoding -> structured_outputs. The import failed, HAS_GUIDED_DECODING became False, and the whole guided-decoding block was skipped, so response_format / grammar constraints were silently ignored. Adapt the existing request.Grammar path to the new class/field. Signed-off-by: pos-ei-don <1822533+pos-ei-don@users.noreply.github.com> --- backend/python/vllm/backend.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/backend/python/vllm/backend.py b/backend/python/vllm/backend.py index 5d566285765f..20064e2332f4 100644 --- a/backend/python/vllm/backend.py +++ b/backend/python/vllm/backend.py @@ -48,8 +48,10 @@ except ImportError: HAS_REASONING_PARSERS = False +# vLLM >= 0.23 renamed GuidedDecodingParams -> StructuredOutputsParams and the +# SamplingParams field guided_decoding -> structured_outputs. try: - from vllm.sampling_params import GuidedDecodingParams + from vllm.sampling_params import StructuredOutputsParams HAS_GUIDED_DECODING = True except ImportError: HAS_GUIDED_DECODING = False @@ -536,13 +538,13 @@ async def _predict(self, request, context, streaming=False): if value not in (None, 0, [], False): setattr(sampling_params, param_field, value) - # Guided decoding: use Grammar field to pass JSON schema or BNF + # Structured-output decoding: use Grammar field to pass JSON schema or BNF if HAS_GUIDED_DECODING and request.Grammar: try: json.loads(request.Grammar) # valid JSON = JSON schema - sampling_params.guided_decoding = GuidedDecodingParams(json=request.Grammar) + sampling_params.structured_outputs = StructuredOutputsParams(json=request.Grammar) except json.JSONDecodeError: - sampling_params.guided_decoding = GuidedDecodingParams(grammar=request.Grammar) + sampling_params.structured_outputs = StructuredOutputsParams(grammar=request.Grammar) # Extract image paths and process images prompt = request.Prompt