{"record":{"id":"f4d779f9e70d4573","repo":"AUTOMATIC1111/stable-diffusion-webui","slug":"received-a-different-number-of-prompts-len-self","errorCode":null,"errorMessage":"Received a different number of prompts ({len(self.all_prompts)}) and negative prompts ({len(self.all_negative_prompts)})","messagePattern":"Received a different number of prompts \\((.+?)\\) and negative prompts \\((.+?)\\)","errorType":"validation","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"modules/processing.py","lineNumber":432,"sourceCode":"            return self.token_merging_ratio_hr or opts.token_merging_ratio_hr or self.token_merging_ratio or opts.token_merging_ratio\r\n\r\n        return self.token_merging_ratio or opts.token_merging_ratio\r\n\r\n    def setup_prompts(self):\r\n        if isinstance(self.prompt,list):\r\n            self.all_prompts = self.prompt\r\n        elif isinstance(self.negative_prompt, list):\r\n            self.all_prompts = [self.prompt] * len(self.negative_prompt)\r\n        else:\r\n            self.all_prompts = self.batch_size * self.n_iter * [self.prompt]\r\n\r\n        if isinstance(self.negative_prompt, list):\r\n            self.all_negative_prompts = self.negative_prompt\r\n        else:\r\n            self.all_negative_prompts = [self.negative_prompt] * len(self.all_prompts)\r\n\r\n        if len(self.all_prompts) != len(self.all_negative_prompts):\r\n            raise RuntimeError(f\"Received a different number of prompts ({len(self.all_prompts)}) and negative prompts ({len(self.all_negative_prompts)})\")\r\n\r\n        self.all_prompts = [shared.prompt_styles.apply_styles_to_prompt(x, self.styles) for x in self.all_prompts]\r\n        self.all_negative_prompts = [shared.prompt_styles.apply_negative_styles_to_prompt(x, self.styles) for x in self.all_negative_prompts]\r\n\r\n        self.main_prompt = self.all_prompts[0]\r\n        self.main_negative_prompt = self.all_negative_prompts[0]\r\n\r\n    def cached_params(self, required_prompts, steps, extra_network_data, hires_steps=None, use_old_scheduling=False):\r\n        \"\"\"Returns parameters that invalidate the cond cache if changed\"\"\"\r\n\r\n        return (\r\n            required_prompts,\r\n            steps,\r\n            hires_steps,\r\n            use_old_scheduling,\r\n            opts.CLIP_stop_at_last_layers,\r\n            shared.sd_model.sd_checkpoint_info,\r\n            extra_network_data,\r","sourceCodeStart":414,"sourceCodeEnd":450,"githubUrl":"https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/82a973c04367123ae98bd9abdf80d9eda9b910e2/modules/processing.py#L414-L450","documentation":"In Processing.init_all_prompts, prompts are expanded into per-image lists: a list prompt sets all_prompts directly (or replicates to match negative prompts), a scalar prompt becomes batch_size*n_iter copies; the same for negative prompts. If the resulting lists differ in length (typically a list prompt and a list negative prompt of unequal lengths), this RuntimeError is raised before generation starts.","triggerScenarios":"Passing a list for prompt and a list for negative_prompt with different lengths via the API; or a list negative_prompt longer than batch_size*n_iter produced by scalar prompts so replication counts mismatch.","commonSituations":"Scripted/batched generation where a wildcard or prompt-expansion extension yields N prompts but the negative list was sized for a different batch; API payloads built by looping over a dataset that fills prompt and negative_prompt arrays from different sources.","solutions":["Make the two lists the same length: pad the shorter one with duplicates of its last entry (or empty string) before calling processing.","Or pass only one side as a list and leave the other a scalar string — it will be replicated automatically.","Ensure batch_size*n_iter matches len(prompt_list) when prompt is a list."],"exampleFix":"# before\np.prompt = ['a cat', 'a dog']\np.negative_prompt = ['blurry']  # RuntimeError: 2 vs 1\n\n# after\np.prompt = ['a cat', 'a dog']\np.negative_prompt = ['blurry', 'blurry']","handlingStrategy":"validation","validationCode":"def align_prompt_lists(prompt, negative, batch_size, n_iter):\n    if isinstance(prompt, list) and isinstance(negative, list):\n        n = max(len(prompt), len(negative))\n        prompt += [prompt[-1]] * (n - len(prompt))\n        negative += [negative[-1]] * (n - len(negative))\n    return prompt, negative\n\nprompt, negative = align_prompt_lists(p.prompt, p.negative_prompt, p.batch_size, p.n_iter)","typeGuard":null,"tryCatchPattern":"try:\n    processed = process_images(p)\nexcept RuntimeError as e:\n    if 'different number of prompts' in str(e):\n        # normalize lists to equal length, then retry once\n        raise\n    raise","preventionTips":["When prompt is a list, size it exactly batch_size*n_iter and mirror that size for negative prompts.","In API payloads, prefer scalar negative_prompt when only the positive side varies."],"tags":["processing","prompts","batch","validation","api"],"backgroundTag":null,"analyzedSha":"82a973c04367123ae98bd9abdf80d9eda9b910e2","analyzedAt":"2026-08-14T16:46:43.225Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}