{"record":{"id":"77778cc3ee077807","repo":"sgl-project/sglang","slug":"when-using-multiple-prompts-with-multiple-input-im","errorCode":null,"errorMessage":"When using multiple prompts with multiple input images, provide either one shared image or exactly one image per prompt.","messagePattern":"When using multiple prompts with multiple input images, provide either one shared image or exactly one image per prompt\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/entrypoints/diffusion_generator.py","lineNumber":221,"sourceCode":"                \"Please ensure the server is running.\"\n            )\n        logger.info(\n            f\"Successfully connected to remote scheduler at \"\n            f\"{self.server_args.scheduler_endpoint}.\"\n        )\n\n    @staticmethod\n    def _resolve_image_paths_per_prompt(\n        prompts: list[str], image_paths: str | list[str] | None\n    ) -> list[str | list[str] | None]:\n        if len(prompts) <= 1:\n            return [image_paths]\n\n        if not isinstance(image_paths, list) or len(image_paths) <= 1:\n            return [image_paths for _ in prompts]\n\n        if len(image_paths) != len(prompts):\n            raise ValueError(\n                \"When using multiple prompts with multiple input images, \"\n                \"provide either one shared image or exactly one image per prompt.\"\n            )\n\n        return [[image_path] for image_path in image_paths]\n\n    def generate(\n        self,\n        sampling_params_kwargs: dict | None = None,\n        external_trace_header: dict[str, str] | None = None,\n    ) -> GenerationResult | list[GenerationResult] | None:\n        \"\"\"Generate image(s)/video(s) based on the given prompt(s).\n\n        Returns a single GenerationResult for a single prompt, a list for\n        multiple prompts, or None when every request failed.\n        \"\"\"\n        # 1. prepare requests\n        prompts = self._resolve_prompts(","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/entrypoints/diffusion_generator.py#L203-L239","documentation":"Raised by DiffusionGenerator._resolve_image_paths_per_prompt when a list of more than one image path is supplied together with multiple prompts, but the image count does not match the prompt count. The API only supports either one shared image broadcast to all prompts, or a strict one-to-one image-per-prompt mapping. Any other combination is ambiguous and rejected before a request is sent.","triggerScenarios":"Calling generate(prompt=[p1,p2,p3], image_paths=[img1,img2]) (3 prompts, 2 images), or any len(image_paths)>1 list whose length differs from len(prompts).","commonSituations":"Passing a directory scan or glob of images with a differently-sized prompt list; off-by-one when building prompt/image pairs from a dataframe; assuming images are consumed round-robin across prompts.","solutions":["Make len(image_paths) exactly equal to len(prompts) (one image per prompt)","Pass a single image path (not a list) to share one image across all prompts","Pass a single-element list [img] which is also treated as shared","If you intended N images for 1 prompt, pass a single prompt and a list of N image paths"],"exampleFix":"# before\ngenerator.generate(prompt=[\"a cat\", \"a dog\", \"a bird\"], image_paths=[\"cat.png\", \"dog.png\"])\n# after\ngenerator.generate(prompt=[\"a cat\", \"a dog\", \"a bird\"], image_paths=[\"cat.png\", \"dog.png\", \"bird.png\"])\n# or share one image:\ngenerator.generate(prompt=[\"a cat\", \"a dog\", \"a bird\"], image_paths=\"ref.png\")","handlingStrategy":"validation","validationCode":"def check_images(prompts, image_paths):\n    if isinstance(image_paths, list) and len(image_paths) > 1:\n        assert len(image_paths) == len(prompts), (\n            f\"{len(image_paths)} images for {len(prompts)} prompts: \"\n            \"provide 1 shared image or exactly one per prompt\"\n        )","typeGuard":"def valid_image_arg(image_paths, n_prompts) -> bool:\n    if not isinstance(image_paths, list) or len(image_paths) <= 1:\n        return True\n    return len(image_paths) == n_prompts","tryCatchPattern":null,"preventionTips":["Validate image count vs prompt count before calling generate","Construct prompt/image pairs from the same iterable (zip) so lengths cannot diverge"],"tags":["multimodal","input-validation","image-input","diffusion"],"backgroundTag":"argument-count-mismatch","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}