{"record":{"id":"1f18d803c75e7c57","repo":"unslothai/unsloth","slug":"every-prompt-in-prompts-must-be-non-empty","errorCode":null,"errorMessage":"every prompt in prompts must be non-empty","messagePattern":"every prompt in prompts must be non-empty","errorType":"validation","errorClass":"ValueError","httpStatus":422,"severity":"error","filePath":"studio/backend/models/inference.py","lineNumber":2970,"sourceCode":"        max_length = 32,\n        description = \"Prompt list for batched generation: one image per prompt in a single \"\n        \"forward pass (plain text-to-image only). Overrides `prompt` for the images; \"\n        \"`prompt` is still required as the fallback/display value.\",\n    )\n    seeds: Optional[list[int]] = Field(\n        None,\n        min_length = 1,\n        max_length = 32,\n        description = \"Per-image seeds for batched generation: one image per seed (with \"\n        \"`prompts`, lengths must match; alone, every image uses `prompt`). Each image is \"\n        \"individually reproducible from its own seed.\",\n    )\n\n    @field_validator(\"prompts\")\n    @classmethod\n    def _non_empty_prompts(cls, value: Optional[list[str]]) -> Optional[list[str]]:\n        if value is not None and any(not p.strip() for p in value):\n            raise ValueError(\"every prompt in prompts must be non-empty\")\n        return value\n\n    @field_validator(\"seeds\")\n    @classmethod\n    def _seeds_json_safe(cls, value: Optional[list[int]]) -> Optional[list[int]]:\n        # Same JSON safe-integer bound as `seed`, so every per-image seed survives the gallery recipe.\n        if value is not None and any(s < 0 or s > 2**53 - 1 for s in value):\n            raise ValueError(\"every seed must be between 0 and 2**53 - 1\")\n        return value\n\n    @model_validator(mode = \"after\")\n    def _prompts_seeds_lengths_match(self) -> \"DiffusionGenerateRequest\":\n        if (\n            self.prompts is not None\n            and self.seeds is not None\n            and len(self.prompts) != len(self.seeds)\n        ):\n            raise ValueError(","sourceCodeStart":2952,"sourceCodeEnd":2988,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/models/inference.py#L2952-L2988","documentation":"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.","triggerScenarios":"POST /generate with prompts: [\"a cat\", \"\", \" \"}. Also when a batch UI submits one blank row among filled ones.","commonSituations":"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.","solutions":["Filter or reject blank prompts client-side before submitting (see validationCode).","Fix the batch source (CSV import) to skip empty rows.","If a slot is intentionally unused, remove it — prompts and seeds lengths must match anyway."],"exampleFix":"# before\npayload = {\"prompts\": prompts_raw}\n\n# after\nprompts_clean = [p for p in prompts_raw if p and p.strip()]\npayload = {\"prompts\": prompts_clean}","handlingStrategy":"validation","validationCode":"def clean_prompts(prompts: list[str] | None) -> list[str] | None:\n    if prompts is None:\n        return None\n    cleaned = [p for p in prompts if p and p.strip()]\n    if len(cleaned) != len(prompts):\n        raise ValueError('blank prompt in batch')\n    return cleaned","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Skip empty rows during CSV/spreadsheet import","Reject submit when any batch row is blank","Recompute the seeds list whenever prompts are filtered so lengths stay matched"],"tags":["pydantic","validation","diffusion","batch","empty-string"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}