{"record":{"id":"235d223706f687c3","repo":"BerriAI/litellm","slug":"unsupported-file-input-type-type-file-input-e","errorCode":null,"errorMessage":"Unsupported file input type: {type(file_input)}. Expected pathlib.Path, bytes, or a file-like object.","messagePattern":"Unsupported file input type: (.+?)\\. Expected pathlib\\.Path, bytes, or a file-like object\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/ocr/main.py","lineNumber":538,"sourceCode":"        file_path: Final = str(file_input)\n        if not os.path.isfile(file_path):\n            raise FileNotFoundError(f\"File not found: {file_path}\")\n        mime_type = get_mime_type(file_path)\n        file_name = os.path.basename(file_path)\n        with open(file_path, \"rb\") as f:\n            file_bytes = f.read()\n    elif isinstance(file_input, bytes):\n        file_bytes = file_input\n    elif isinstance(file_input, IOBase) or hasattr(file_input, \"read\"):\n        if hasattr(file_input, \"name\"):\n            file_name = getattr(file_input, \"name\", None)\n            if file_name:\n                mime_type = get_mime_type(file_name)\n        file_bytes = file_input.read()\n        if isinstance(file_bytes, str):\n            file_bytes = file_bytes.encode(\"utf-8\")\n    else:\n        raise ValueError(\n            f\"Unsupported file input type: {type(file_input)}. Expected pathlib.Path, bytes, or a file-like object.\"\n        )\n\n    if not file_bytes:\n        raise ValueError(\"File is empty or could not be read\")\n\n    if \"mime_type\" in document:\n        mime_type = document[\"mime_type\"]\n\n    if not _MIME_PATTERN.match(mime_type):\n        raise ValueError(f\"Invalid MIME type: {mime_type}\")\n\n    base64_data: Final = base64.b64encode(file_bytes).decode(\"utf-8\")\n    data_uri: Final = f\"data:{mime_type};base64,{base64_data}\"\n\n    if mime_type.startswith(\"image/\"):\n        verbose_logger.debug(\n            \"OCR file input: Converted file to image_url data URI (mime=%s, size=%s bytes, name=%s)\",","sourceCodeStart":520,"sourceCodeEnd":556,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/ocr/main.py#L520-L556","documentation":"Type guard at the end of the OCR file-input chain: the value is neither Path, bytes, nor a readable file-like object, so its bytes cannot be obtained. The received type is listed alongside the accepted shapes.","triggerScenarios":"Thrown at litellm/ocr/main.py:538 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Convert the input to pathlib.Path, bytes, or a file-like object before passing it."],"exampleFix":"from pathlib import Path; file_input = Path('doc.pdf')","handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}