sgl-project/sglang · info

EBNF is not officially supported by OpenAI endpoints. Ignori

Error message

EBNF is not officially supported by OpenAI endpoints. Ignoring.

What it means

This warning is emitted by sglang's OpenAI backend wrapper when the sampling/request kwargs contain an 'ebnf' key. OpenAI's completion/chat APIs have no EBNF grammar parameter, so sglang strips the option and proceeds without grammar-constrained decoding. It is informational: the request still runs, just unconstrained.

Source

Thrown at python/sglang/lang/backend/openai.py:388

            assert hit

            if np.sum(valid) <= 1:
                break

            prompt_tokens.append(ret_token)

        return ChoicesDecision(
            decision=choices[np.argmax(scores)],
            meta_info={"scores": scores},
        )


def openai_completion(
    client, token_usage, is_chat=None, retries=3, prompt=None, **kwargs
) -> Union[str, List[str]]:
    # if "ebnf" is in kwargs, warn and remove
    if "ebnf" in kwargs:
        warnings.warn("EBNF is not officially supported by OpenAI endpoints. Ignoring.")
        del kwargs["ebnf"]

    for attempt in range(retries):
        try:
            if is_chat:
                if "stop" in kwargs and kwargs["stop"] is None:
                    kwargs.pop("stop")
                ret = client.chat.completions.create(messages=prompt, **kwargs)
                if len(ret.choices) == 1:
                    comp = ret.choices[0].message.content
                else:
                    comp = [c.message.content for c in ret.choices]
            else:
                ret = client.completions.create(prompt=prompt, **kwargs)
                if isinstance(prompt, (list, tuple)):
                    comp = [c.text for c in ret.choices]
                else:
                    comp = ret.choices[0].text

View on GitHub (pinned to 0132848349)

Solutions

  1. Remove or clear the EBNF/grammar constraint before routing the request to the OpenAI backend (set regex/ebnf to None)
  2. If grammar-constrained generation is required, route the request to an sglang runtime endpoint backend which supports EBNF natively
  3. Suppress the warning with warnings.filterwarnings if the behavior is acceptable

Example fix

# before
gen = sgl.gen("answer", ebnf=grammar)
# after (OpenAI backend)
gen = sgl.gen("answer")
Defensive patterns

Strategy: validation

Validate before calling

kwargs.pop("ebnf", None)
# or before building the request:
if backend_name == "openai" and grammar is not None:
    grammar = None

Prevention

When it happens

Trigger: Calling sgl_gen/generate through the OpenAI backend with an EBNF grammar set on the SGLang IR or sampling params (e.g. setting .assert_regex/grammar on a program routed to an OpenAI model, or passing ebnf=... kwargs that reach openai_completion).

Common situations: Writing a frontend-agnostic SGLang program with grammar constraints and then switching the backend to OpenAI (gpt-4o etc.); porting code from the local runtime endpoint to the hosted API; passing a dict of sampling params wholesale to the OpenAI client.

Related errors


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