unslothai/unsloth · error · ValueError

prompts and seeds must have the same length (got {len(self.p

Error message

prompts and seeds must have the same length (got {len(self.prompts)} prompts, {len(self.seeds)} seeds)

What it means

Raised by a model_validator on DiffusionGenerateRequest when both prompts and seeds are provided but their lengths differ. The API generates one image per seed (paired with prompts), so a mismatch is ambiguous about which prompt goes with which seed.

Source

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

            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(
                f"prompts and seeds must have the same length (got {len(self.prompts)} "
                f"prompts, {len(self.seeds)} seeds)"
            )
        return self

    # Image-conditioned workflows (base64 or data-URL): init_image alone runs img2img, init_image + mask_image runs inpaint.
    # Cap each base64 string so one request cannot buffer a multi-GB payload; ~32 MiB fits a full 4096px image.
    init_image: Optional[str] = Field(
        None,
        max_length = 32 * 1024 * 1024,
        description = "Base64/data-URL source image for img2img or inpaint (omit for txt2img)",
    )
    mask_image: Optional[str] = Field(
        None,
        max_length = 32 * 1024 * 1024,
        description = "Base64/data-URL mask for inpaint (white = repaint, black = keep). "
        "Requires init_image.",
    )

View on GitHub (pinned to 203007d190)

Solutions

  1. Regenerate/trim the seed list to len(prompts) whenever prompts change (see validationCode).
  2. Or drop seeds entirely and pass a single seed to have all images derive from it.
  3. Assert lengths match in a client-side pre-submit check.

Example fix

# before
payload = {"prompts": prompts, "seeds": seeds}

# after
assert len(prompts) == len(seeds), (len(prompts), len(seeds))
payload = {"prompts": prompts, "seeds": seeds}
Defensive patterns

Strategy: validation

Validate before calling

def paired(prompts: list[str] | None, seeds: list[int] | None) -> bool:
    if prompts is None or seeds is None:
        return True
    return len(prompts) == len(seeds)

Prevention

When it happens

Trigger: POST /generate with 3 prompts and 2 seeds (or vice versa). Happens when the seed list is generated with a stale count after prompts are edited.

Common situations: UIs that add/remove prompt rows without regenerating the seed list; batch code computing seeds = make_seeds(len(old_prompts)); copying an example payload and editing only one array.

Related errors


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