{"record":{"id":"4aa4946d677d7dfe","repo":"BerriAI/litellm","slug":"image-conversion-failed-please-run-pip-install-pi","errorCode":null,"errorMessage":"image conversion failed please run `pip install Pillow`","messagePattern":"image conversion failed please run `pip install Pillow`","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"litellm/litellm_core_utils/prompt_templates/factory.py","lineNumber":3178,"sourceCode":"    for idx, message in enumerate(messages):\n        if message[\"role\"] == \"user\":\n            prompt += f\"{AmazonTitanConstants.HUMAN_PROMPT.value}{message['content']}\"\n        elif message[\"role\"] == \"system\":\n            prompt += f\"{AmazonTitanConstants.HUMAN_PROMPT.value}<admin>{message['content']}</admin>\"\n        else:\n            prompt += f\"{AmazonTitanConstants.AI_PROMPT.value}{message['content']}\"\n        if idx == 0 and message[\"role\"] == \"assistant\":  # ensure the prompt always starts with `\\n\\nHuman: `\n            prompt = f\"{AmazonTitanConstants.HUMAN_PROMPT.value}\" + prompt\n    if messages[-1][\"role\"] != \"assistant\":\n        prompt += f\"{AmazonTitanConstants.AI_PROMPT.value}\"\n    return prompt\n\n\ndef _load_image_from_url(image_url):\n    try:\n        from PIL import Image\n    except Exception:\n        raise Exception(\"image conversion failed please run `pip install Pillow`\")\n    from io import BytesIO\n\n    try:\n        # Send a GET request to the image URL\n        client: Final = HTTPHandler(concurrent_limit=1)\n        response: Final[httpx.Response] = safe_get(client, image_url)\n        response.raise_for_status()  # Raise an exception for HTTP errors\n\n        # Check the response's content type to ensure it is an image\n        content_type: Final = response.headers.get(\"content-type\")\n        if not content_type or \"image\" not in content_type:\n            raise ValueError(f\"URL does not point to a valid image (content-type: {content_type})\")\n\n        # Load the image from the response content\n        return Image.open(BytesIO(response.content))\n\n    except Exception as e:\n        raise e","sourceCodeStart":3160,"sourceCodeEnd":3196,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/litellm_core_utils/prompt_templates/factory.py#L3160-L3196","documentation":"litellm tried to import PIL (Pillow) to open an image and the import failed, so it raises this dependency-missing error instead of an opaque ImportError. Nothing about the request is wrong - the runtime simply lacks the optional imaging dependency.","triggerScenarios":"Calling a vision path that uses _load_image_from_url (e.g. Amazon/Gemini image handling) in an environment where Pillow is not installed, e.g. slim Docker images or a minimal pip install of litellm.","commonSituations":"Slim/production Docker images; litellm installed without extras; virtualenv or multiple-Python mismatches where Pillow exists in one interpreter but the app runs another.","solutions":["pip install Pillow in the environment that runs litellm","Add Pillow to your requirements.txt/pyproject.toml","Rebuild the Docker image with Pillow included"],"exampleFix":"# before: Pillow absent -> Exception('image conversion failed please run `pip install Pillow`')\n\n# after\npip install Pillow","handlingStrategy":"validation","validationCode":"def pillow_available() -> bool:\n    try:\n        import PIL  # noqa: F401\n        return True\n    except ImportError:\n        return False\n\n# at startup:\n# if using vision features and not pillow_available(): fail fast with a clear message","typeGuard":null,"tryCatchPattern":"try:\n    litellm.completion(model=model, messages=messages)  # vision path\nexcept Exception as e:\n    if \"pip install Pillow\" in str(e):\n        raise RuntimeError(\"Pillow missing in this environment - add it to the image\") from e\n    raise","preventionTips":["Add Pillow to requirements.txt/pyproject next to litellm when using vision","Include a startup dependency check that fails fast before serving traffic","Build Docker images with Pillow; slim base images do not include it"],"tags":["dependency","pillow","image"],"backgroundTag":"missing-dependency","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}