{"record":{"id":"69973142a5ff2f05","repo":"sgl-project/sglang","slug":"regular-expression-is-not-supported-in-the-vertexa","errorCode":null,"errorMessage":"Regular expression is not supported in the VertexAI backend.","messagePattern":"Regular expression is not supported in the VertexAI backend\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"python/sglang/lang/ir.py","lineNumber":81,"sourceCode":"\n    def to_openai_kwargs(self):\n        # OpenAI does not support top_k, so we drop it here\n        if self.regex is not None:\n            warnings.warn(\"Regular expression is not supported in the OpenAI backend.\")\n        return {\n            \"max_tokens\": self.max_new_tokens,\n            \"max_completion_tokens\": self.max_new_tokens,\n            \"n\": self.n,\n            \"stop\": self.stop or None,\n            \"temperature\": self.temperature,\n            \"top_p\": self.top_p,\n            \"frequency_penalty\": self.frequency_penalty,\n            \"presence_penalty\": self.presence_penalty,\n        }\n\n    def to_vertexai_kwargs(self):\n        if self.regex is not None:\n            warnings.warn(\n                \"Regular expression is not supported in the VertexAI backend.\"\n            )\n        return {\n            \"candidate_count\": 1,\n            \"max_output_tokens\": self.max_new_tokens,\n            \"stop_sequences\": self.stop,\n            \"temperature\": self.temperature,\n            \"top_p\": self.top_p,\n            \"top_k\": self.top_k if self.top_k > 0 else None,\n        }\n\n    def to_anthropic_kwargs(self):\n        # Anthropic does not support frequency_penalty or presence_penalty, so we drop it here\n        if self.regex is not None:\n            warnings.warn(\n                \"Regular expression is not supported in the Anthropic backend.\"\n            )\n        return {","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/lang/ir.py#L63-L99","documentation":"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.","triggerScenarios":"Attaching a regex constraint via .assert_regex and generating against the VertexAI backend (generate or generate_stream).","commonSituations":"Cross-backend evaluation harnesses that run the same constrained program over GPT, Claude, and Gemini; assuming all sglang backends honor regex.","solutions":["Use VertexAI-native structured output (response_schema / responseMimeType json) instead of regex","Use the sglang runtime endpoint for true regex-constrained decoding","Validate/retry client-side on regex mismatch"],"exampleFix":"# before\ng = sgl.gen(\"ans\", regex=r\"\\\\d+\")\n# after (vertexai)\ng = sgl.gen(\"ans\", json_schema=...)  # or parse+retry locally","handlingStrategy":"validation","validationCode":"if backend_name == \"vertexai\" and ir.regex is not None:\n    ir.regex = None  # switch to json_schema / response_format","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Map constraints to provider-native structured-output features","Fail fast in dev when constraints are silently dropped"],"tags":["regex","vertexai","structured-output","constraint-dropped","warning"],"backgroundTag":"unsupported-feature-warning","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}