{"record":{"id":"d1873bf17fddc97f","repo":"sgl-project/sglang","slug":"invalid-dtype-sampling-params-dtype","errorCode":null,"errorMessage":"Invalid dtype: {sampling_params.dtype}","messagePattern":"Invalid dtype: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"python/sglang/lang/backend/runtime_endpoint.py","lineNumber":150,"sourceCode":"            sampling_params.stop = []\n\n        dtype_regex = None\n        if sampling_params.dtype in [\"int\", int]:\n\n            dtype_regex = REGEX_INT\n            sampling_params.stop.extend([\" \", \"\\n\"])\n        elif sampling_params.dtype in [\"float\", float]:\n\n            dtype_regex = REGEX_FLOAT\n            sampling_params.stop.extend([\" \", \"\\n\"])\n        elif sampling_params.dtype in [\"str\", str]:\n\n            dtype_regex = REGEX_STR\n        elif sampling_params.dtype in [\"bool\", bool]:\n\n            dtype_regex = REGEX_BOOL\n        else:\n            raise RuntimeError(f\"Invalid dtype: {sampling_params.dtype}\")\n\n        if dtype_regex is not None and sampling_params.regex is not None:\n            warnings.warn(\n                f\"Both dtype and regex are set. Only dtype will be used. dtype: {sampling_params.dtype}, regex: {sampling_params.regex}\"\n            )\n\n        sampling_params.regex = dtype_regex\n\n    def generate(\n        self,\n        s: StreamExecutor,\n        sampling_params: SglSamplingParams,\n    ):\n        self._handle_dtype_to_regex(sampling_params)\n        data = {\n            \"text\": s.text_,\n            \"sampling_params\": {\n                \"skip_special_tokens\": global_config.skip_special_tokens_in_output,","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/lang/backend/runtime_endpoint.py#L132-L168","documentation":"RuntimeEndpoint backend maps a sampling_params.dtype to an internal regex constraining output: int -> integer regex, float/number -> number, str -> string, bool -> boolean. Any other dtype reaches the else branch and raises RuntimeError('Invalid dtype: ...') before the request is sent.","triggerScenarios":"sgl.gen(..., dtype=X) on a program running against a RuntimeEndpoint where X is not in [None,'str','int','integer','float','number','bool'] — e.g. 'list', 'json', a Python type object, or a typo.","commonSituations":"Expecting JSON schema output via dtype='json' (unsupported on this path); passing Python classes (str/int types instead of their names) — note bool the CLASS is handled but e.g. list is not.","solutions":["Use one of the recognized dtype names: 'str'/'string', 'int'/'integer', 'float'/'number', 'bool', or None.","For structured JSON, use the dedicated json-schema gen support or a backend that implements it, rather than dtype.","Verify the value is a string name, not a type object (except bool which is special-cased)."],"exampleFix":"# before\ns += sgl.gen(\"out\", dtype=\"json\")\n\n# after\ns += sgl.gen(\"out\", dtype=\"str\", regex=r'\\{.*\\}')  # constrain manually","handlingStrategy":"validation","validationCode":"VALID = {None, \"str\", \"string\", \"int\", \"integer\", \"float\", \"number\", \"bool\"}\nassert sampling_params.dtype in VALID, f\"Invalid dtype {sampling_params.dtype!r}\"","typeGuard":"def is_valid_dtype(d) -> bool:\n    return d in (None, \"str\", \"string\", \"int\", \"integer\", \"float\", \"number\", \"bool\", bool)","tryCatchPattern":"try:\n    run(program)\nexcept RuntimeError as e:\n    if \"Invalid dtype\" in str(e):\n        normalize dtype to nearest valid name and rerun\n    else:\n        raise","preventionTips":["Pass dtype names as lowercase strings, not type objects.","Note both dtype and regex set -> dtype wins (library warns); pick one."],"tags":["frontend","dtype","regex","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"}