{"record":{"id":"2cfe0ca75908daa8","repo":"BerriAI/litellm","slug":"ollama-image-conversion-failed-please-run-pip-ins","errorCode":null,"errorMessage":"ollama image conversion failed please run `pip install Pillow`","messagePattern":"ollama image conversion failed please run `pip install Pillow`","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"litellm/llms/ollama/common_utils.py","lineNumber":28,"sourceCode":"    def __init__(self, status_code: int, message: str, headers: dict | httpx.Headers):\n        super().__init__(status_code=status_code, message=message, headers=headers)\n\n\ndef _convert_image(image):\n    \"\"\"\n    Convert image to base64 encoded image if not already in base64 format\n\n    If image is already in base64 format AND is a jpeg/png, return it\n\n    If image is not JPEG/PNG, convert it to JPEG base64 format\n    \"\"\"\n    import base64\n    import io\n\n    try:\n        from PIL import Image\n    except Exception:\n        raise Exception(\"ollama image conversion failed please run `pip install Pillow`\")\n\n    orig: Final = image\n    if image.startswith(\"data:\"):\n        image = image.split(\",\")[-1]\n    try:\n        image_data: Final = Image.open(io.BytesIO(base64.b64decode(image)))\n        if image_data.format in [\"JPEG\", \"PNG\"]:\n            return image\n    except Exception:\n        return orig\n    jpeg_image: Final = io.BytesIO()\n    image_data.convert(\"RGB\").save(jpeg_image, \"JPEG\")\n    jpeg_image.seek(0)\n    return base64.b64encode(jpeg_image.getvalue()).decode(\"utf-8\")\n\n\nfrom litellm.llms.base_llm.base_utils import BaseLLMModelInfo\n","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/ollama/common_utils.py#L10-L46","documentation":"Ollama image conversion in litellm/llms/ollama/common_utils.py needs Pillow to re-encode non-JPEG/PNG images (e.g. WebP) to JPEG base64. It tries `from PIL import Image`; if the import fails, this generic Exception is raised telling you to install Pillow.","triggerScenarios":"Calling `litellm.completion(model='ollama/llava', messages=[{'role':'user','content':[{'type':'image_url','image_url':{'url':'data:image/webp;base64,...'}}]}])` in an environment where Pillow is not installed — LiteLLM does not depend on Pillow by default.","commonSituations":"Fresh venvs with a minimal `pip install litellm`, slim Docker images, or WebP/other-format images (JPEG/PNG pass through without Pillow only when already base64-decodable; conversion paths need it).","solutions":["Install Pillow in the environment running LiteLLM: `pip install Pillow`.","Or pre-convert images to JPEG/PNG base64 yourself before passing them, avoiding the conversion path.","Add Pillow to your project's dependency list so it survives fresh installs."],"exampleFix":"# before\n# images fail with \"ollama image conversion failed please run `pip install Pillow`\"\n\n# after\npip install Pillow\n# or pre-convert:\nfrom PIL import Image\nimport io, base64\nbuf = io.BytesIO()\nImage.open(\"cat.webp\").convert(\"RGB\").save(buf, \"JPEG\")\nb64 = base64.b64encode(buf.getvalue()).decode()","handlingStrategy":"validation","validationCode":"def pillow_available() -> bool:\n    try:\n        from PIL import Image  # noqa: F401\n        return True\n    except ImportError:\n        return False\n\nif not pillow_available() and any_image_inputs(messages):\n    raise RuntimeError(\"Install Pillow or pre-convert images to JPEG/PNG base64\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Add Pillow to project dependencies when using vision models","Pre-convert images to JPEG/PNG base64 in your ingestion step","Fail fast at startup on missing optional deps instead of mid-request"],"tags":["ollama","vision","pillow","dependencies","images"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}