sgl-project/sglang · warning

Regular expression is not supported in the VertexAI backend.

Error message

Regular expression is not supported in the VertexAI backend.

What it means

Same constraint-drop behavior as the OpenAI case, but for the VertexAI backend: to_vertexai_kwargs warns that the regex is not forwarded, so generation is unconstrained by it.

Source

Thrown at python/sglang/lang/ir.py:81

    def to_openai_kwargs(self):
        # OpenAI does not support top_k, so we drop it here
        if self.regex is not None:
            warnings.warn("Regular expression is not supported in the OpenAI backend.")
        return {
            "max_tokens": self.max_new_tokens,
            "max_completion_tokens": self.max_new_tokens,
            "n": self.n,
            "stop": self.stop or None,
            "temperature": self.temperature,
            "top_p": self.top_p,
            "frequency_penalty": self.frequency_penalty,
            "presence_penalty": self.presence_penalty,
        }

    def to_vertexai_kwargs(self):
        if self.regex is not None:
            warnings.warn(
                "Regular expression is not supported in the VertexAI backend."
            )
        return {
            "candidate_count": 1,
            "max_output_tokens": self.max_new_tokens,
            "stop_sequences": self.stop,
            "temperature": self.temperature,
            "top_p": self.top_p,
            "top_k": self.top_k if self.top_k > 0 else None,
        }

    def to_anthropic_kwargs(self):
        # Anthropic does not support frequency_penalty or presence_penalty, so we drop it here
        if self.regex is not None:
            warnings.warn(
                "Regular expression is not supported in the Anthropic backend."
            )
        return {

View on GitHub (pinned to 0132848349)

Solutions

  1. Use VertexAI-native structured output (response_schema / responseMimeType json) instead of regex
  2. Use the sglang runtime endpoint for true regex-constrained decoding
  3. Validate/retry client-side on regex mismatch

Example fix

# before
g = sgl.gen("ans", regex=r"\\d+")
# after (vertexai)
g = sgl.gen("ans", json_schema=...)  # or parse+retry locally
Defensive patterns

Strategy: validation

Validate before calling

if backend_name == "vertexai" and ir.regex is not None:
    ir.regex = None  # switch to json_schema / response_format

Prevention

When it happens

Trigger: Attaching a regex constraint via .assert_regex and generating against the VertexAI backend (generate or generate_stream).

Common situations: Cross-backend evaluation harnesses that run the same constrained program over GPT, Claude, and Gemini; assuming all sglang backends honor regex.

Related errors


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