sgl-project/sglang · error · ValueError

No prompts found in file

Error message

No prompts found in file: {path}

What it means

The prompt file given to DiffusionGenerator.generate exists and was opened successfully, but contains no non-blank lines after stripping, so no prompts could be extracted. Rather than sending an empty batch, the loader raises this ValueError.

Solutions

  1. Open the file and confirm it has at least one non-empty line
  2. Regenerate the prompt file if it was truncated by an upstream step
  3. Guard your pipeline: skip generation when the prompt file is empty
  4. Check the file encoding is UTF-8 text and not, e.g., binary or UTF-16 read as one line

Example fix

# before
open("prompts.txt","w").close()  # accidentally empty
generator.generate(prompt_path="prompts.txt")
# after
with open("prompts.txt","w") as f:
    f.write("a red panda\n")
generator.generate(prompt_path="prompts.txt")
Defensive patterns

Strategy: validation

Validate before calling

def load_prompts(path):
    lines = [l.strip() for l in open(path, encoding="utf-8") if l.strip()]
    if not lines:
        raise SystemExit(f"prompt file {path} has no prompts")
    return lines

Type guard

def has_prompts(path) -> bool:
    return any(l.strip() for l in open(path, encoding="utf-8"))

Prevention

When it happens

Trigger: generate(prompt_path=...) where the file is empty, contains only whitespace/newlines, or only blank lines; a server launched with --prompt-file-path pointing at a truncated/placeholder file.

Common situations: Downstream step of a pipeline wrote an empty prompt file; encoding mismatch making every line unreadable; placeholder file committed by mistake; file truncated by a previous crash.

Related errors


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

Appendix: source

Thrown at python/sglang/multimodal_gen/runtime/entrypoints/diffusion_generator.py:489

            raise RuntimeError(output_batch.error)
        if output_batch.output is None:
            raise RuntimeError("action policy returned no output")
        return output_batch.output[0]

    def _resolve_prompts(
        self,
        prompt: str | list[str] | None,
        prompt_path: str | None = None,
    ) -> list[str]:
        """Collect prompts from the argument or from a prompt file."""
        path = prompt_path or self.server_args.prompt_file_path
        if path is not None:
            if not os.path.exists(path):
                raise FileNotFoundError(f"Prompt text file not found: {path}")
            with open(path, encoding="utf-8") as f:
                prompts = [line.strip() for line in f if line.strip()]
            if not prompts:
                raise ValueError(f"No prompts found in file: {path}")
            logger.info("Found %d prompts in %s", len(prompts), path)
            return prompts

        if prompt is None:
            return [" "]
        if isinstance(prompt, str):
            return [prompt]
        return list(prompt)

    def _log_summary(self, results: list[GenerationResult]) -> None:
        if not results:
            return
        if self.server_args.warmup_mode != "off":
            total_duration_ms = results[0].metrics.get("total_duration_ms", 0)
            logger.info(
                f"Warmed-up request processed in {GREEN}%.2f{RESET} seconds (with warmup excluded)",
                total_duration_ms / 1000.0,
            )

View on GitHub (pinned to 0132848349)