sgl-project/sglang · error · ValueError

Prompt cannot be empty

Error message

Prompt cannot be empty

What it means

generate_image validates that the prompt is non-empty before making any request, raising ValueError immediately for empty or None prompts since the backend requires a text prompt for generation or editing.

Source

Thrown at python/sglang/multimodal_gen/apps/ComfyUI_SGLDiffusion/core/server_api.py:112

            height: Image height (used if size is not provided)
            n: Number of images to generate (1-10)
            negative_prompt: Negative prompt to avoid certain elements
            guidance_scale: Classifier-free guidance scale
            num_inference_steps: Number of denoising steps
            seed: Random seed for reproducible generation
            enable_teacache: Enable TEA cache acceleration
            response_format: Response format ("b64_json" or "url")
            quality: Image quality ("auto", "standard", "hd") - only for generation
            style: Image style ("vivid" or "natural") - only for generation
            background: Background type ("auto", "transparent", "opaque")
            output_format: Output format ("png", "jpeg", "webp")
            generator_device: Device for random generator ("cuda" or "cpu")

        Returns:
            Dictionary containing the API response with generated/edited image data
        """
        if not prompt:
            raise ValueError("Prompt cannot be empty")

        # Determine size
        if size is None:
            if width is not None and height is not None:
                size = f"{width}x{height}"
            else:
                size = "1024x1024"

        # Build common parameters
        common_params = self._build_image_common_params(
            prompt=prompt,
            size=size,
            n=n,
            response_format=response_format,
            negative_prompt=negative_prompt,
            guidance_scale=guidance_scale,
            num_inference_steps=num_inference_steps,
            seed=seed,

View on GitHub (pinned to 0132848349)

Solutions

  1. Default or check the prompt before calling: prompt = prompt or fallback_text
  2. Skip empty rows in batch loops: if not prompt.strip(): continue
  3. Fix the upstream code that produces the empty prompt

Example fix

# before
client.generate_image("")

# after
prompt = prompt.strip() or "a scenic landscape"
client.generate_image(prompt)
Defensive patterns

Strategy: validation

Validate before calling

if not prompt or not prompt.strip():
    raise ValueError("prompt required")
client.generate_image(prompt.strip())

Type guard

def has_prompt(p: str | None) -> bool:
    return isinstance(p, str) and bool(p.strip())

Prevention

When it happens

Trigger: Calling generate_image("") or generate_image(None), or passing a variable that was supposed to be populated from user input/configuration but ended up empty.

Common situations: UI code forwarding an empty text box, templating bugs producing empty strings, or scripted batches where some rows have blank prompt fields.

Related errors


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