{"record":{"id":"35c2c4236fd58e17","repo":"sgl-project/sglang","slug":"unknown-dtype-sampling-params-dtype","errorCode":null,"errorMessage":"Unknown dtype: {sampling_params.dtype}","messagePattern":"Unknown dtype: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/lang/backend/openai.py","lineNumber":220,"sourceCode":"        elif sampling_params.dtype in [int, \"int\"]:\n            assert (\n                not self.is_chat_model\n            ), \"constrained type not supported on chat model\"\n            kwargs = sampling_params.to_openai_kwargs()\n            kwargs.pop(\"stop\")\n            comp = openai_completion(\n                client=self.client,\n                token_usage=self.token_usage,\n                is_chat=self.is_chat_model,\n                model=self.model_name,\n                prompt=s.text_,\n                logit_bias=self.logit_bias_int,\n                stop=[\" \"],\n                **kwargs,\n            )\n            # Leave as a list if that's what is returned.\n        else:\n            raise ValueError(f\"Unknown dtype: {sampling_params.dtype}\")\n\n        return comp, {}\n\n    def spec_fill(self, value: str):\n        assert self.is_chat_model\n        self.spec_format.append({\"text\": value, \"stop\": None, \"name\": None})\n\n    def spec_pattern_match(self, comp):\n        for i, term in enumerate(self.spec_format):\n            text = term[\"text\"]\n            if text != \"\":\n                if comp.startswith(text):\n                    comp = comp[len(text) :]\n                else:\n                    return False\n            else:\n                pos = comp.find(term[\"stop\"])\n                if pos != -1:","sourceCodeStart":202,"sourceCodeEnd":238,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/lang/backend/openai.py#L202-L238","documentation":"OpenAI backend generate() dispatches on sampling_params.dtype: None means free text, 'str'/'int'/'float'/'bool' map to constrained completion calls. Any other dtype value falls through to ValueError(f\"Unknown dtype: {dtype}\") — the requested structured-output type is unsupported.","triggerScenarios":"sgl.gen(..., dtype=some_unsupported_value) with the OpenAI backend — e.g. dtype='json', dtype=list, dtype='number', or a typo like 'integer' instead of 'int'.","commonSituations":"Expecting JSON-mode or arbitrary schema output (OpenAI backend doesn't implement it here); mismatch between dtype names supported by the RuntimeEndpoint backend vs the OpenAI backend; passing Python types instead of the string names.","solutions":["Use one of the supported dtype strings: 'str', 'int', 'float', 'bool', or omit dtype for free text.","For structured/JSON output switch to a backend that supports regex/schema (RuntimeEndpoint against a local sglang server with json schema enforcement).","Check for typos: it's 'int' not 'integer', 'float' not 'double'."],"exampleFix":"# before\ns += sgl.gen(\"answer\", dtype=\"integer\")\n\n# after\ns += sgl.gen(\"answer\", dtype=\"int\")","handlingStrategy":"validation","validationCode":"ALLOWED_DTYPES = {None, \"str\", \"int\", \"float\", \"bool\"}\nassert sampling_params_dtype in ALLOWED_DTYPES, f\"dtype must be one of {ALLOWED_DTYPES}\"","typeGuard":"def is_supported_dtype(d) -> bool:\n    return d in (None, \"str\", \"int\", \"float\", \"bool\")","tryCatchPattern":"try:\n    run(program)\nexcept ValueError as e:\n    if \"Unknown dtype\" in str(e):\n        fix dtype to nearest supported ('integer'->'int') and rerun\n    else:\n        raise","preventionTips":["Centralize dtype choices in constants validated against backend capabilities.","Remember OpenAI backend has no json/schema dtype; use regex only where supported."],"tags":["frontend","openai","dtype","invalid-argument","sglang"],"backgroundTag":"unsupported-output-dtype","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}