{"record":{"id":"ac3e191963b9d7fe","repo":"unslothai/unsloth","slug":"prompts-must-be-a-non-empty-list-of-non-empty-stri","errorCode":null,"errorMessage":"prompts must be a non-empty list of non-empty strings","messagePattern":"prompts must be a non-empty list of non-empty strings","errorType":"validation","errorClass":"ValueError","httpStatus":400,"severity":"error","filePath":"studio/backend/core/inference/diffusion_batched.py","lineNumber":62,"sourceCode":"    seed: Optional[int],\n    seeds: Optional[list[int]],\n    batch_size: int,\n    draw_seed: Callable[[], int],\n) -> tuple[list[tuple[str, int]], int]:\n    \"\"\"The per-image ``(prompt, seed)`` jobs plus the base seed for this call.\n\n    - ``prompts`` (list): one image per prompt. With ``seeds`` too, lengths must\n      match (seed i drives prompt i); without, seeds derive from the base.\n    - ``seeds`` (list) alone: one image per seed, all with ``prompt``.\n    - neither: ``batch_size`` images of ``prompt`` with derived seeds\n      base..base+batch_size-1 (each masked JSON-safe).\n\n    ``draw_seed`` supplies a fresh random base when the caller sent none (the\n    engine passes a ``torch.Generator`` draw). Raises ``ValueError`` on empty /\n    oversized lists, a length mismatch, or an out-of-range seed.\"\"\"\n    if prompts is not None:\n        if not prompts or not all(isinstance(p, str) and p.strip() for p in prompts):\n            raise ValueError(\"prompts must be a non-empty list of non-empty strings\")\n        if len(prompts) > MAX_BATCH_IMAGES:\n            raise ValueError(f\"prompts supports at most {MAX_BATCH_IMAGES} entries per call\")\n    if seeds is not None:\n        if not seeds:\n            raise ValueError(\"seeds must be a non-empty list of integers\")\n        if len(seeds) > MAX_BATCH_IMAGES:\n            raise ValueError(f\"seeds supports at most {MAX_BATCH_IMAGES} entries per call\")\n        seeds = [int(s) for s in seeds]\n        if any(s < 0 or s > SEED_MASK for s in seeds):\n            raise ValueError(\"every seed must be between 0 and 2**53 - 1 (JSON-safe)\")\n        if prompts is not None and len(seeds) != len(prompts):\n            raise ValueError(\n                f\"prompts and seeds must have the same length \"\n                f\"(got {len(prompts)} prompts, {len(seeds)} seeds)\"\n            )\n\n    if prompts is not None:\n        count = len(prompts)","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/core/inference/diffusion_batched.py#L44-L80","documentation":"Batch-spec validation in diffusion_batched: when a prompts list is supplied it must be non-empty and every element must be a non-empty (after strip) string. Empty lists, lists containing empty/whitespace-only strings, or lists containing non-string values (None, numbers) are rejected up front, before any generation work. The docstring contract: seed i drives prompt i when seeds are also given.","triggerScenarios":"Calling generate with prompts=[] (empty list — note None means 'not provided' and is fine), prompts=[\"\"], prompts=[\"  \"], or prompts=[\"valid\", None].","commonSituations":"Programmatically building prompt lists where a filter step removes every element; JSON payloads with null entries; trailing empty strings from template concatenation.","solutions":["Ensure every prompt is a non-empty trimmed string: [p for p in prompts if isinstance(p, str) and p.strip()].","If the list can legitimately be empty after filtering, send prompt (singular) or omit prompts instead of an empty list.","Validate client-side before the call to save a round trip."],"exampleFix":"# before\nengine.generate(prompts=[\"a cat\", \"\", \"a dog\"])\n# after\nprompts = [p for p in [\"a cat\", \"\", \"a dog\"] if p.strip()]\nengine.generate(prompts=prompts)","handlingStrategy":"validation","validationCode":"def valid_prompts(prompts) -> bool:\n    return prompts is None or (\n        isinstance(prompts, list)\n        and len(prompts) > 0\n        and all(isinstance(p, str) and p.strip() for p in prompts)\n    )","typeGuard":"from typing import Any\n\ndef is_valid_prompt_list(v: Any) -> bool:\n    return isinstance(v, list) and bool(v) and all(isinstance(p, str) and p.strip() for p in v)","tryCatchPattern":"try:\n    out = engine.generate(prompts=prompts)\nexcept ValueError as e:\n    if \"prompts must be a non-empty list\" in str(e):\n        prompts = [p.strip() for p in prompts if isinstance(p, str) and p.strip()]\n        out = engine.generate(prompts=prompts) if prompts else engine.generate(prompt=default_prompt)\n    else:\n        raise","preventionTips":["Filter/trim prompt lists client-side: drop non-strings and empty entries before sending.","Distinguish 'no prompts' (send null / singular prompt) from 'empty list' (invalid)."],"tags":["diffusion","batching","validation","prompts"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}