{"record":{"id":"4090e5e7bffc9f14","repo":"BerriAI/litellm","slug":"file-not-found-file-path","errorCode":null,"errorMessage":"File not found: {file_path}","messagePattern":"File not found: (.+?)","errorType":"exception","errorClass":"FileNotFoundError","httpStatus":null,"severity":"error","filePath":"litellm/ocr/main.py","lineNumber":522,"sourceCode":"\n    if isinstance(file_input, str):\n        # Bare strings are rejected here. The OCR ``document`` accepts a\n        # ``{\"type\": \"file\", \"file\": <value>}`` shape, and when this helper\n        # runs in a proxy request handler ``<value>`` is attacker-controlled.\n        # Opening it as a path is an arbitrary local file read on the proxy\n        # host, which is then base64-encoded and forwarded to the OCR\n        # provider — an exfiltration primitive.\n        raise ValueError(\n            \"OCR file input does not accept bare str values. Pass bytes, \"\n            \"a pathlib.Path, or a file-like object. To OCR a local file \"\n            \"from a path, call open(path, 'rb') yourself.\"\n        )\n    if isinstance(file_input, os.PathLike):\n        # os.PathLike (pathlib.Path and custom __fspath__ classes) is a\n        # Python-level type that HTTP form values can't fabricate.\n        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        )","sourceCodeStart":504,"sourceCodeEnd":540,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/ocr/main.py#L504-L540","documentation":"Raised by the OCR file-input helper when the supplied value is a pathlib.Path (or similar path-like) that does not exist on disk — the helper is about to open and base64-encode it for the provider request. Note this is distinct from the security guard in the same function that rejects bare strings outright; this error only fires for path objects whose target file is missing.","triggerScenarios":"Thrown at litellm/ocr/main.py:522 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the file path exists and is readable before calling.","Use an absolute path if the working directory differs."],"exampleFix":"import os; assert os.path.exists(file_path), file_path","handlingStrategy":"validation","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-14T00:17:10.932Z"}