AUTOMATIC1111/stable-diffusion-webui · error · RuntimeError

Received a different number of prompts ({len(self.all_prompt

Error message

Received a different number of prompts ({len(self.all_prompts)}) and negative prompts ({len(self.all_negative_prompts)})

What it means

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.

Source

Thrown at modules/processing.py:432

            return self.token_merging_ratio_hr or opts.token_merging_ratio_hr or self.token_merging_ratio or opts.token_merging_ratio

        return self.token_merging_ratio or opts.token_merging_ratio

    def setup_prompts(self):
        if isinstance(self.prompt,list):
            self.all_prompts = self.prompt
        elif isinstance(self.negative_prompt, list):
            self.all_prompts = [self.prompt] * len(self.negative_prompt)
        else:
            self.all_prompts = self.batch_size * self.n_iter * [self.prompt]

        if isinstance(self.negative_prompt, list):
            self.all_negative_prompts = self.negative_prompt
        else:
            self.all_negative_prompts = [self.negative_prompt] * len(self.all_prompts)

        if len(self.all_prompts) != len(self.all_negative_prompts):
            raise RuntimeError(f"Received a different number of prompts ({len(self.all_prompts)}) and negative prompts ({len(self.all_negative_prompts)})")

        self.all_prompts = [shared.prompt_styles.apply_styles_to_prompt(x, self.styles) for x in self.all_prompts]
        self.all_negative_prompts = [shared.prompt_styles.apply_negative_styles_to_prompt(x, self.styles) for x in self.all_negative_prompts]

        self.main_prompt = self.all_prompts[0]
        self.main_negative_prompt = self.all_negative_prompts[0]

    def cached_params(self, required_prompts, steps, extra_network_data, hires_steps=None, use_old_scheduling=False):
        """Returns parameters that invalidate the cond cache if changed"""

        return (
            required_prompts,
            steps,
            hires_steps,
            use_old_scheduling,
            opts.CLIP_stop_at_last_layers,
            shared.sd_model.sd_checkpoint_info,
            extra_network_data,

View on GitHub (pinned to 82a973c043)

Solutions

  1. Make the two lists the same length: pad the shorter one with duplicates of its last entry (or empty string) before calling processing.
  2. Or pass only one side as a list and leave the other a scalar string — it will be replicated automatically.
  3. Ensure batch_size*n_iter matches len(prompt_list) when prompt is a list.

Example fix

# before
p.prompt = ['a cat', 'a dog']
p.negative_prompt = ['blurry']  # RuntimeError: 2 vs 1

# after
p.prompt = ['a cat', 'a dog']
p.negative_prompt = ['blurry', 'blurry']
Defensive patterns

Strategy: validation

Validate before calling

def align_prompt_lists(prompt, negative, batch_size, n_iter):
    if isinstance(prompt, list) and isinstance(negative, list):
        n = max(len(prompt), len(negative))
        prompt += [prompt[-1]] * (n - len(prompt))
        negative += [negative[-1]] * (n - len(negative))
    return prompt, negative

prompt, negative = align_prompt_lists(p.prompt, p.negative_prompt, p.batch_size, p.n_iter)

Try / catch

try:
    processed = process_images(p)
except RuntimeError as e:
    if 'different number of prompts' in str(e):
        # normalize lists to equal length, then retry once
        raise
    raise

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of AUTOMATIC1111/stable-diffusion-webui@82a973c043 (2026-08-14). Data as JSON: /api/errors/f4d779f9e70d4573. Report an issue: GitHub.