sgl-project/sglang · error · ValueError
schema_ is required for json_schema response format request.
Error message
schema_ is required for json_schema response format request.
What it means
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.
Source
Thrown at python/sglang/srt/entrypoints/openai/serving_completions.py:178
"repetition_penalty": request.repetition_penalty,
"regex": request.regex,
"json_schema": request.json_schema,
"ebnf": request.ebnf,
"n": request.n,
"no_stop_trim": request.no_stop_trim,
"ignore_eos": request.ignore_eos,
"skip_special_tokens": request.skip_special_tokens,
"logit_bias": request.logit_bias,
"custom_params": request.custom_params,
"sampling_seed": request.seed,
}
# Handle response_format constraints
if request.response_format and request.response_format.type == "json_schema":
json_schema = request.response_format.json_schema
schema = getattr(json_schema, "schema_", None)
if schema is None:
raise ValueError(
"schema_ is required for json_schema response format request."
)
sampling_params["json_schema"] = convert_json_schema_to_str(schema)
elif request.response_format and request.response_format.type == "json_object":
sampling_params["json_schema"] = '{"type": "object"}'
elif (
request.response_format and request.response_format.type == "structural_tag"
):
sampling_params["structural_tag"] = convert_json_schema_to_str(
request.response_format.model_dump(by_alias=True)
)
return sampling_params
async def _handle_streaming_request(
self,
adapted_request: GenerateReqInput,
request: CompletionRequest,View on GitHub (pinned to 0132848349)
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
Example fix
# before
{"response_format": {"type": "json_schema", "json_schema": {"name": "user"}}}
# after
{"response_format": {"type": "json_schema", "json_schema": {"name": "user", "schema_": {"type": "object", "properties": {"name": {"type": "string"}}, "required": ["name"]}}}} Defensive patterns
Strategy: validation
Validate before calling
if rf.get('type') == 'json_schema':
assert rf['json_schema'].get('schema_'), 'schema_ required' Type guard
def valid_json_schema_rf(rf) -> bool:
js = rf.get('json_schema') or {}
return rf.get('type') != 'json_schema' or isinstance(js.get('schema_'), (dict, str)) and js.get('schema_') is not None Prevention
- Build response_format from SDK typed models
- Remember the field is schema_ not schema
- Integration-test the request once before shipping
When it happens
Trigger: POST /v1/completions with response_format.type == 'json_schema' and json_schema.schema_ missing/None (e.g. only json_schema.name given).
Common situations: 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.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Kimi K3 additional parameter schema accepts no values
- Kimi K3 tool parameters 'properties' must be an object
- Kimi K3 tool parameters 'required' must be a string list
- Kimi K3 required parameters are missing schemas: {sorted(mis
- Kimi K3 tool property schemas must be JSON schemas
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/ae68d8d7450fb3d8.
Report an issue: GitHub.