{"record":{"id":"27f53f9213c466d3","repo":"unslothai/unsloth","slug":"prompts-and-seeds-must-have-the-same-length-got-27f53f","errorCode":null,"errorMessage":"prompts and seeds must have the same length (got {len(self.prompts)} prompts, {len(self.seeds)} seeds)","messagePattern":"prompts and seeds must have the same length \\(got (.+?) prompts, (.+?) seeds\\)","errorType":"validation","errorClass":"ValueError","httpStatus":422,"severity":"error","filePath":"studio/backend/models/inference.py","lineNumber":2988,"sourceCode":"            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(\n                f\"prompts and seeds must have the same length (got {len(self.prompts)} \"\n                f\"prompts, {len(self.seeds)} seeds)\"\n            )\n        return self\n\n    # Image-conditioned workflows (base64 or data-URL): init_image alone runs img2img, init_image + mask_image runs inpaint.\n    # Cap each base64 string so one request cannot buffer a multi-GB payload; ~32 MiB fits a full 4096px image.\n    init_image: Optional[str] = Field(\n        None,\n        max_length = 32 * 1024 * 1024,\n        description = \"Base64/data-URL source image for img2img or inpaint (omit for txt2img)\",\n    )\n    mask_image: Optional[str] = Field(\n        None,\n        max_length = 32 * 1024 * 1024,\n        description = \"Base64/data-URL mask for inpaint (white = repaint, black = keep). \"\n        \"Requires init_image.\",\n    )","sourceCodeStart":2970,"sourceCodeEnd":3006,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/models/inference.py#L2970-L3006","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Regenerate/trim the seed list to len(prompts) whenever prompts change (see validationCode).","Or drop seeds entirely and pass a single seed to have all images derive from it.","Assert lengths match in a client-side pre-submit check."],"exampleFix":"# before\npayload = {\"prompts\": prompts, \"seeds\": seeds}\n\n# after\nassert len(prompts) == len(seeds), (len(prompts), len(seeds))\npayload = {\"prompts\": prompts, \"seeds\": seeds}","handlingStrategy":"validation","validationCode":"def paired(prompts: list[str] | None, seeds: list[int] | None) -> bool:\n    if prompts is None or seeds is None:\n        return True\n    return len(prompts) == len(seeds)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Derive seeds length from prompts length in one place","Regenerate the seed list whenever prompt rows are added/removed","Prefer a single seed + batch_size when per-image seeds are not required"],"tags":["pydantic","validation","diffusion","batch","length-mismatch","seeds"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}