{"record":{"id":"05c89fcdbfc462e1","repo":"sgl-project/sglang","slug":"cannot-combine-tool-calls-with-constrained-decodin","errorCode":null,"errorMessage":"Cannot combine tool calls with constrained decoding (text.format / regex / ebnf / structural_tag / json_schema). Remove one.","messagePattern":"Cannot combine tool calls with constrained decoding \\(text\\.format / regex / ebnf / structural_tag / json_schema\\)\\. Remove one\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/entrypoints/openai/protocol.py","lineNumber":1827,"sourceCode":"\n        # Apply any additional default parameters\n        for key, value in default_params.items():\n            if key not in params or params[key] is None:\n                params[key] = value\n\n        json_schema = self._json_schema_from_text_format(self.text)\n        if json_schema is not None:\n            params[\"json_schema\"] = json_schema\n\n        has_existing_constraints = (\n            params.get(\"regex\")\n            or params.get(\"ebnf\")\n            or params.get(\"structural_tag\")\n            or params.get(\"json_schema\")\n        )\n        if tool_call_constraint and has_existing_constraints:\n            # Refuse rather than silently drop the tool-call grammar.\n            raise ValueError(\n                \"Cannot combine tool calls with constrained decoding \"\n                \"(text.format / regex / ebnf / structural_tag / json_schema). \"\n                \"Remove one.\"\n            )\n        if tool_call_constraint:\n            constraint_type, constraint_value = tool_call_constraint\n            if constraint_type in (\"structural_tag\", \"json_schema\"):\n                params[constraint_type] = convert_json_schema_to_str(\n                    constraint_value.model_dump(by_alias=True)\n                    if hasattr(constraint_value, \"model_dump\")\n                    else constraint_value\n                )\n            else:\n                params[constraint_type] = constraint_value\n\n        return params\n\n","sourceCodeStart":1809,"sourceCodeEnd":1845,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/entrypoints/openai/protocol.py#L1809-L1845","documentation":"The Responses-API request converter refuses tool calls combined with any constrained-decoding output constraint (text.format, regex, ebnf, structural_tag, or json_schema params). Both mechanisms compile to XGrammar constraints that would conflict, so the request is rejected rather than silently dropping one.","triggerScenarios":"POST /v1/responses with tools + tool_choice forcing calls, and text.format={...} or regex/ebnf/structural_tag/json_schema set in text.format params.","commonSituations":"Wanting schema-validated tool arguments and adding an output schema too; copying structured-output examples into a function-calling app; embedding json_schema in text.format while tools are attached.","solutions":["Drop text.format/regex/ebnf/structural_tag/json_schema from the request and constrain arguments via the tool's parameters schema","Or remove tools/tool_choice if structured text output is what you need"],"exampleFix":"// before\n{\"tools\": [...], \"tool_choice\": \"auto\", \"text\": {\"format\": {\"type\": \"json_schema\", ...}}}\n// after\n{\"tools\": [...], \"tool_choice\": \"auto\"}","handlingStrategy":"validation","validationCode":"fmt = (body.get(\"text\") or {}).get(\"format\")\nif body.get(\"tools\") and fmt:\n    body[\"text\"].pop(\"format\")  # or drop tools","typeGuard":"def has_output_constraint(text): return bool((text or {}).get('format'))","tryCatchPattern":"try: responses.create(...)\nexcept ValueError as e: if 'constrained decoding' in str(e): retry without text.format","preventionTips":["Pick one mechanism: tool schemas OR output format, never both","Lint request payloads in CI"],"tags":["responses-api","tool-calling","constrained-decoding","structured-output","sglang"],"backgroundTag":"conflicting-request-options","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}