sgl-project/sglang · error · ValueError

Provide either `prompt` or `prompt_embeds`. Cannot leave bot

Error message

Provide either `prompt` or `prompt_embeds`. Cannot leave both `prompt` and `prompt_embeds` undefined.

What it means

The counterpart to the both-provided check: the pipeline requires at least one of prompt or prompt_embeds. When both are None there is no conditioning signal at all, so generation cannot proceed and ValueError is raised.

Source

Thrown at python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/glm_image.py:1106

            logger.warning(
                f"`height` and `width` have to be divisible by {self.vae_scale_factor * 2} but are {height} and {width}. Dimensions will be resized accordingly"
            )

        if callback_on_step_end_tensor_inputs is not None and not all(
            k in self._callback_tensor_inputs
            for k in callback_on_step_end_tensor_inputs
        ):
            raise ValueError(
                f"`callback_on_step_end_tensor_inputs` has to be in {self._callback_tensor_inputs}, but found {[k for k in callback_on_step_end_tensor_inputs if k not in self._callback_tensor_inputs]}"
            )

        if prompt is not None and prompt_embeds is not None:
            raise ValueError(
                f"Cannot forward both `prompt`: {prompt} and `prompt_embeds`: {prompt_embeds}. Please make sure to"
                " only forward one of the two."
            )
        elif prompt is None and prompt_embeds is None:
            raise ValueError(
                "Provide either `prompt` or `prompt_embeds`. Cannot leave both `prompt` and `prompt_embeds` undefined."
            )
        elif prompt is not None and (
            not isinstance(prompt, str) and not isinstance(prompt, list)
        ):
            raise ValueError(
                f"`prompt` has to be of type `str` or `list` but is {type(prompt)}"
            )

    @property
    def guidance_scale(self):
        return self._guidance_scale

    @property
    def do_classifier_free_guidance(self):
        return self._guidance_scale > 1

    @property

View on GitHub (pinned to 0132848349)

Solutions

  1. Pass a non-empty prompt string, or supply prompt_embeds computed from your text encoder
  2. Fix wrapper signatures so omitted arguments still resolve to a default prompt
  3. Add a caller-side assert that at least one of the two is provided

Example fix

# before
pipe(prompt=None, prompt_embeds=None)

# after
pipe(prompt="a cat")  # or pipe(prompt_embeds=encode("a cat"))
Defensive patterns

Strategy: validation

Validate before calling

if prompt is None and prompt_embeds is None:
    raise ValueError("provide prompt or prompt_embeds before calling the pipeline")

Type guard

def has_conditioning(prompt, prompt_embeds) -> bool:
    return prompt is not None or prompt_embeds is not None

Try / catch

except ValueError as e:
    if "Cannot leave both" in str(e):
        pipe(prompt=default_prompt)
    else:
        raise

Prevention

When it happens

Trigger: Calling forward()/check_inputs with prompt=None and prompt_embeds=None, e.g. defaulting both to None in a wrapper and forgetting to populate either.

Common situations: Generic wrapper code that accepts optional prompt and embeds but forwards Nones; negative-prompt-only invocations where the positive prompt kwarg was accidentally dropped; refactors that renamed the prompt argument.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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