sgl-project/sglang · warning

Both dtype and regex are set. Only dtype will be used. dtype

Error message

Both dtype and regex are set. Only dtype will be used. dtype: {sampling_params.dtype}, regex: {sampling_params.regex}

What it means

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.

Source

Thrown at python/sglang/lang/backend/runtime_endpoint.py:153

        if sampling_params.dtype in ["int", int]:

            dtype_regex = REGEX_INT
            sampling_params.stop.extend([" ", "\n"])
        elif sampling_params.dtype in ["float", float]:

            dtype_regex = REGEX_FLOAT
            sampling_params.stop.extend([" ", "\n"])
        elif sampling_params.dtype in ["str", str]:

            dtype_regex = REGEX_STR
        elif sampling_params.dtype in ["bool", bool]:

            dtype_regex = REGEX_BOOL
        else:
            raise RuntimeError(f"Invalid dtype: {sampling_params.dtype}")

        if dtype_regex is not None and sampling_params.regex is not None:
            warnings.warn(
                f"Both dtype and regex are set. Only dtype will be used. dtype: {sampling_params.dtype}, regex: {sampling_params.regex}"
            )

        sampling_params.regex = dtype_regex

    def generate(
        self,
        s: StreamExecutor,
        sampling_params: SglSamplingParams,
    ):
        self._handle_dtype_to_regex(sampling_params)
        data = {
            "text": s.text_,
            "sampling_params": {
                "skip_special_tokens": global_config.skip_special_tokens_in_output,
                "spaces_between_special_tokens": global_config.spaces_between_special_tokens_in_out,
                **sampling_params.to_srt_kwargs(),
            },

View on GitHub (pinned to 0132848349)

Solutions

  1. Remove the regex and rely on dtype if a type pattern suffices
  2. Remove the dtype and keep the custom regex if you need a more specific pattern
  3. Combine the patterns manually into a single regex and drop the dtype

Example fix

# before
g = sgl.gen("x", dtype=int, regex=r"[0-9]{3}")
# after
g = sgl.gen("x", regex=r"[0-9]{3}")
Defensive patterns

Strategy: validation

Validate before calling

if sampling_params.regex is not None and sampling_params.dtype is not None:
    raise ValueError("set only one of dtype/regex")
# or merge manually into one regex and clear dtype

Type guard

def has_conflict(sp) -> bool:
    return sp.dtype is not None and sp.regex is not None

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/88be04864e38786a. Report an issue: GitHub.