{"record":{"id":"880457bbc3ebc8bd","repo":"sgl-project/sglang","slug":"regular-expression-is-not-supported-in-the-anthrop","errorCode":null,"errorMessage":"Regular expression is not supported in the Anthropic backend.","messagePattern":"Regular expression is not supported in the Anthropic backend\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"python/sglang/lang/ir.py","lineNumber":96,"sourceCode":"\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 {\n            \"max_tokens\": self.max_new_tokens,\n            \"stop_sequences\": (\n                self.stop if isinstance(self.stop, (list, tuple)) else [self.stop]\n            ),\n            \"temperature\": self.temperature,\n            \"top_p\": self.top_p,\n            \"top_k\": self.top_k,\n        }\n\n    def to_litellm_kwargs(self):\n        if self.regex is not None:\n            warnings.warn(\"Regular expression is not supported in the LiteLLM backend.\")\n        return {\n            \"max_tokens\": self.max_new_tokens,\n            \"stop\": self.stop or None,","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/lang/ir.py#L78-L114","documentation":"to_anthropic_kwargs warns that Anthropic's Messages API has no regex-guided decoding, so the constraint is dropped (along with frequency/presence penalties). Generation proceeds unconstrained.","triggerScenarios":"Attaching .assert_regex to a generation executed via the Anthropic backend (generate/generate_stream).","commonSituations":"Multi-provider benchmarking of the same constrained program; relying on regex guarantees for tool-call output parsing with Claude models.","solutions":["Use Anthropic tool use / JSON mode for structured output instead of regex","Route regex-dependent generations to the sglang runtime endpoint backend","Parse and retry on the client when output does not match the pattern"],"exampleFix":"# before\ng = sgl.gen(\"ans\", regex=r\"yes|no\")\n# after\nout = backend.generate(...);  assert out in {\"yes\",\"no\"} or retry","handlingStrategy":"validation","validationCode":"if backend_name == \"anthropic\" and ir.regex is not None:\n    ir.regex = None  # use tool-use / JSON mode","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Retry-with-reprompt loop for format violations","Prefer structured output APIs over regex on hosted providers"],"tags":["regex","anthropic","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"}