{"record":{"id":"ae68d8d7450fb3d8","repo":"sgl-project/sglang","slug":"schema-is-required-for-json-schema-response-forma","errorCode":null,"errorMessage":"schema_ is required for json_schema response format request.","messagePattern":"schema_ is required for json_schema response format request\\.","errorType":"validation","errorClass":"ValueError","httpStatus":400,"severity":"error","filePath":"python/sglang/srt/entrypoints/openai/serving_completions.py","lineNumber":178,"sourceCode":"            \"repetition_penalty\": request.repetition_penalty,\n            \"regex\": request.regex,\n            \"json_schema\": request.json_schema,\n            \"ebnf\": request.ebnf,\n            \"n\": request.n,\n            \"no_stop_trim\": request.no_stop_trim,\n            \"ignore_eos\": request.ignore_eos,\n            \"skip_special_tokens\": request.skip_special_tokens,\n            \"logit_bias\": request.logit_bias,\n            \"custom_params\": request.custom_params,\n            \"sampling_seed\": request.seed,\n        }\n\n        # Handle response_format constraints\n        if request.response_format and request.response_format.type == \"json_schema\":\n            json_schema = request.response_format.json_schema\n            schema = getattr(json_schema, \"schema_\", None)\n            if schema is None:\n                raise ValueError(\n                    \"schema_ is required for json_schema response format request.\"\n                )\n            sampling_params[\"json_schema\"] = convert_json_schema_to_str(schema)\n        elif request.response_format and request.response_format.type == \"json_object\":\n            sampling_params[\"json_schema\"] = '{\"type\": \"object\"}'\n        elif (\n            request.response_format and request.response_format.type == \"structural_tag\"\n        ):\n            sampling_params[\"structural_tag\"] = convert_json_schema_to_str(\n                request.response_format.model_dump(by_alias=True)\n            )\n\n        return sampling_params\n\n    async def _handle_streaming_request(\n        self,\n        adapted_request: GenerateReqInput,\n        request: CompletionRequest,","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/entrypoints/openai/serving_completions.py#L160-L196","documentation":"A completions request declared response_format={\"type\":\"json_schema\"} but the nested json_schema object had no schema_ field (the actual JSON Schema payload). SGLang requires the schema to convert into sampling_params.json_schema for constrained decoding.","triggerScenarios":"POST /v1/completions with response_format.type == 'json_schema' and json_schema.schema_ missing/None (e.g. only json_schema.name given).","commonSituations":"Clients building the request dict by hand and naming the schema field 'schema' instead of 'schema_'; partial request templating that leaves the schema out; version drift where clients sent the bare schema.","solutions":["Include the schema: response_format.json_schema.schema_ = {...}","If using OpenAI SDK types, populate ResponseFormatJsonSchema(schema_={...})","For loose object constraints, use type 'json_object' instead"],"exampleFix":"# before\n{\"response_format\": {\"type\": \"json_schema\", \"json_schema\": {\"name\": \"user\"}}}\n# after\n{\"response_format\": {\"type\": \"json_schema\", \"json_schema\": {\"name\": \"user\", \"schema_\": {\"type\": \"object\", \"properties\": {\"name\": {\"type\": \"string\"}}, \"required\": [\"name\"]}}}}","handlingStrategy":"validation","validationCode":"if rf.get('type') == 'json_schema':\n    assert rf['json_schema'].get('schema_'), 'schema_ required'","typeGuard":"def valid_json_schema_rf(rf) -> bool:\n    js = rf.get('json_schema') or {}\n    return rf.get('type') != 'json_schema' or isinstance(js.get('schema_'), (dict, str)) and js.get('schema_') is not None","tryCatchPattern":null,"preventionTips":["Build response_format from SDK typed models","Remember the field is schema_ not schema","Integration-test the request once before shipping"],"tags":["json-schema","response-format","validation"],"backgroundTag":"schema-validation-failed","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}