{"record":{"id":"987339934f903d62","repo":"invoke-ai/InvokeAI","slug":"len-images-images-were-provided-as-input-to-the","errorCode":null,"errorMessage":"{len(images)} images were provided as input to the LLaVA OneVision model. Pass <=3 images for good performance.","messagePattern":"(.+?) images were provided as input to the LLaVA OneVision model\\. Pass <=3 images for good performance\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"warning","filePath":"invokeai/backend/llava_onevision_pipeline.py","lineNumber":44,"sourceCode":"class LlavaOnevisionPipeline:\n    \"\"\"A wrapper for a LLaVA Onevision model + processor.\"\"\"\n\n    def __init__(self, vllm_model: LlavaOnevisionForConditionalGeneration, processor: LlavaOnevisionProcessor):\n        self._vllm_model = vllm_model\n        self._processor = processor\n\n    def run(\n        self,\n        prompt: str,\n        images: list[Image],\n        device: torch.device,\n        dtype: torch.dtype,\n        max_new_tokens: int = 400,\n        progress_callback: ProgressCallback | None = None,\n    ) -> str:\n        # TODO(ryand): Tune the max number of images that are useful for the model.\n        if len(images) > 3:\n            raise ValueError(\n                f\"{len(images)} images were provided as input to the LLaVA OneVision model. \"\n                \"Pass <=3 images for good performance.\"\n            )\n\n        # Define a chat history and use `apply_chat_template` to get correctly formatted prompt.\n        # \"content\" is a list of dicts with types \"text\" or \"image\".\n        content = [{\"type\": \"text\", \"text\": prompt}]\n        for _ in images:\n            content.append({\"type\": \"image\"})\n\n        conversation = [{\"role\": \"user\", \"content\": content}]\n        formatted_prompt = self._processor.apply_chat_template(conversation, add_generation_prompt=True)\n        inputs = self._processor(images=images or None, text=formatted_prompt, return_tensors=\"pt\").to(\n            device=device, dtype=dtype\n        )\n\n        tokenizer = self._processor.tokenizer\n        streamer = TextIteratorStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True, timeout=STREAM_TIMEOUT)","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/backend/llava_onevision_pipeline.py#L26-L62","documentation":"run() of the LLaVA OneVision image-to-prompt pipeline enforces a soft limit of 3 input images per call; beyond that, multi-image performance (and prompt formatting) degrades badly, so it raises ValueError up front instead of producing poor output.","triggerScenarios":"Calling run(images=[...]) with more than 3 PIL/torch images, e.g. batching a whole folder of images into one image-to-prompt request.","commonSituations":"Processing directories of images in a single call instead of iterating; a UI that accumulates attached images without capping; misreading run() as accepting batches.","solutions":["Split the input into chunks of at most 3 images and call run() once per chunk (or once per image).","Cap the number of images at the UI/batch layer before invoking the pipeline.","If you need many images described, run them sequentially and merge the prompts.","Use a dedicated multi-image model/batch API if >3 images per inference is a hard requirement."],"exampleFix":"// before\nprompt = pipeline.run(images=all_12_images, ...)\n// after\nprompts = [pipeline.run(images=all_12_images[i:i+3], ...) for i in range(0, len(all_12_images), 3)]","handlingStrategy":"validation","validationCode":"if len(images) > 3:\n    raise ValueError(f'{len(images)} images given; LLaVA OneVision pipeline accepts at most 3 per run() call')","typeGuard":"def is_valid_image_batch(images) -> bool:\n    return isinstance(images, (list, tuple)) and 0 < len(images) <= 3","tryCatchPattern":"try:\n    prompt = pipeline.run(images, dtype=dtype)\nexcept ValueError as e:\n    if 'Pass <=3 images' in str(e):\n        prompts = [pipeline.run(images[i:i+3], dtype=dtype) for i in range(0, len(images), 3)]\n        prompt = '\\n'.join(prompts)\n    else:\n        raise","preventionTips":["Chunk image lists to <=3 before calling run()","Enforce an image-attachment cap in UI/batch code","Treat run() as a single-few-image call, not a batch API","Iterate per image if independent prompts are needed"],"tags":["llava-onevision","input-validation","image-count-limit"],"backgroundTag":"input-limit-exceeded","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}