sgl-project/sglang · warning
Regular expression is not supported in the Anthropic…
Error message
Regular expression is not supported in the Anthropic backend.
What it means
SGLang IR/frontend error: a regex constraint (sgl.gen(..., regex=...)) was used with the Anthropic backend, which does not support regex-constrained decoding. Remove the regex or use a backend that supports it.
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
Example fix
# before
g = sgl.gen("ans", regex=r"yes|no")
# after
out = backend.generate(...); assert out in {"yes","no"} or retry Defensive patterns
Strategy: validation
Validate before calling
if backend_name == "anthropic" and ir.regex is not None:
ir.regex = None # use tool-use / JSON mode Prevention
- Retry-with-reprompt loop for format violations
- Prefer structured output APIs over regex on hosted providers
When it happens
Trigger: Attaching .assert_regex to a generation executed via the Anthropic backend (generate/generate_stream).
Common situations: Multi-provider benchmarking of the same constrained program; relying on regex guarantees for tool-call output parsing with Claude models.
Related errors
- Regular expression is not supported in the LiteLLM backend.
- Regular expression is not supported in the OpenAI backend.
- Regular expression is not supported in the VertexAI backend.
- Both dtype and regex are set. Only dtype will be used. dtype
- Anthropic redacted_thinking history is not supported
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/880457bbc3ebc8bd.
Report an issue: GitHub.
Appendix: source
Thrown at python/sglang/lang/ir.py:96
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 {
"max_tokens": self.max_new_tokens,
"stop_sequences": (
self.stop if isinstance(self.stop, (list, tuple)) else [self.stop]
),
"temperature": self.temperature,
"top_p": self.top_p,
"top_k": self.top_k,
}
def to_litellm_kwargs(self):
if self.regex is not None:
warnings.warn("Regular expression is not supported in the LiteLLM backend.")
return {
"max_tokens": self.max_new_tokens,
"stop": self.stop or None,View on GitHub (pinned to 0132848349)