unslothai/unsloth · error · ValueError

every prompt in prompts must be non-empty

Error message

every prompt in prompts must be non-empty

What it means

Raised by the prompts field_validator on DiffusionGenerateRequest when any prompt in the batch list is empty or whitespace-only. Empty batch entries would generate garbage images from nothing, so they are rejected as a 422.

Source

Thrown at studio/backend/models/inference.py:2970

        max_length = 32,
        description = "Prompt list for batched generation: one image per prompt in a single "
        "forward pass (plain text-to-image only). Overrides `prompt` for the images; "
        "`prompt` is still required as the fallback/display value.",
    )
    seeds: Optional[list[int]] = Field(
        None,
        min_length = 1,
        max_length = 32,
        description = "Per-image seeds for batched generation: one image per seed (with "
        "`prompts`, lengths must match; alone, every image uses `prompt`). Each image is "
        "individually reproducible from its own seed.",
    )

    @field_validator("prompts")
    @classmethod
    def _non_empty_prompts(cls, value: Optional[list[str]]) -> Optional[list[str]]:
        if value is not None and any(not p.strip() for p in value):
            raise ValueError("every prompt in prompts must be non-empty")
        return value

    @field_validator("seeds")
    @classmethod
    def _seeds_json_safe(cls, value: Optional[list[int]]) -> Optional[list[int]]:
        # Same JSON safe-integer bound as `seed`, so every per-image seed survives the gallery recipe.
        if value is not None and any(s < 0 or s > 2**53 - 1 for s in value):
            raise ValueError("every seed must be between 0 and 2**53 - 1")
        return value

    @model_validator(mode = "after")
    def _prompts_seeds_lengths_match(self) -> "DiffusionGenerateRequest":
        if (
            self.prompts is not None
            and self.seeds is not None
            and len(self.prompts) != len(self.seeds)
        ):
            raise ValueError(

View on GitHub (pinned to 203007d190)

Solutions

  1. Filter or reject blank prompts client-side before submitting (see validationCode).
  2. Fix the batch source (CSV import) to skip empty rows.
  3. If a slot is intentionally unused, remove it — prompts and seeds lengths must match anyway.

Example fix

# before
payload = {"prompts": prompts_raw}

# after
prompts_clean = [p for p in prompts_raw if p and p.strip()]
payload = {"prompts": prompts_clean}
Defensive patterns

Strategy: validation

Validate before calling

def clean_prompts(prompts: list[str] | None) -> list[str] | None:
    if prompts is None:
        return None
    cleaned = [p for p in prompts if p and p.strip()]
    if len(cleaned) != len(prompts):
        raise ValueError('blank prompt in batch')
    return cleaned

Prevention

When it happens

Trigger: POST /generate with prompts: ["a cat", "", " "}. Also when a batch UI submits one blank row among filled ones.

Common situations: Spreadsheet/CSV-driven batch generation with blank rows; front-ends that keep placeholder empty rows in the submitted list; trailing commas in JSON arrays yielding empty strings after client-side joins.

Related errors


AI-assisted analysis of unslothai/unsloth@203007d190 (2026-08-15). Data as JSON: /api/errors/1f18d803c75e7c57. Report an issue: GitHub.