{"record":{"id":"88be04864e38786a","repo":"sgl-project/sglang","slug":"both-dtype-and-regex-are-set-only-dtype-will-be-u","errorCode":null,"errorMessage":"Both dtype and regex are set. Only dtype will be used. dtype: {sampling_params.dtype}, regex: {sampling_params.regex}","messagePattern":"Both dtype and regex are set\\. Only dtype will be used\\. dtype: (.+?), regex: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"python/sglang/lang/backend/runtime_endpoint.py","lineNumber":153,"sourceCode":"        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,\n                \"spaces_between_special_tokens\": global_config.spaces_between_special_tokens_in_out,\n                **sampling_params.to_srt_kwargs(),\n            },","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/lang/backend/runtime_endpoint.py#L135-L171","documentation":"SGLang's runtime_endpoint backend converts a declared dtype (bool/int/float/str) into an equivalent regex for constrained decoding. If the sampling params already carry a user-supplied regex, the dtype-derived regex silently overwrites it and this warning is printed. Output follows the dtype's pattern, not your custom regex.","triggerScenarios":"Setting both .assert_dtype(...) (or sampling_params.dtype) and .assert_regex(...) / sampling_params.regex on the same sgl.gen call against a runtime endpoint backend.","commonSituations":"Building structured-output prompts where a type declaration and a hand-written regex are both attached; layering helper functions that each add constraints to the same generation call.","solutions":["Remove the regex and rely on dtype if a type pattern suffices","Remove the dtype and keep the custom regex if you need a more specific pattern","Combine the patterns manually into a single regex and drop the dtype"],"exampleFix":"# before\ng = sgl.gen(\"x\", dtype=int, regex=r\"[0-9]{3}\")\n# after\ng = sgl.gen(\"x\", regex=r\"[0-9]{3}\")","handlingStrategy":"validation","validationCode":"if sampling_params.regex is not None and sampling_params.dtype is not None:\n    raise ValueError(\"set only one of dtype/regex\")\n# or merge manually into one regex and clear dtype","typeGuard":"def has_conflict(sp) -> bool:\n    return sp.dtype is not None and sp.regex is not None","tryCatchPattern":null,"preventionTips":["Enforce single-constraint invariant in wrapper functions","Unit-test constraint setters for mutual exclusion"],"tags":["dtype","regex","structured-output","conflict","sampling-params"],"backgroundTag":"conflicting-options-warning","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}