{"record":{"id":"e71b86878ab792ec","repo":"BerriAI/litellm","slug":"document-with-type-file-must-include-a-file-fi","errorCode":null,"errorMessage":"document with type='file' must include a 'file' field containing a pathlib.Path, file-like object, or bytes","messagePattern":"document with type='file' must include a 'file' field containing a pathlib\\.Path, file-like object, or bytes","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/ocr/main.py","lineNumber":496,"sourceCode":"    \"\"\"\n    Convert a file-type document dict to a document_url-type document dict\n    with an inline base64 data URI.\n\n    Accepts document dicts like:\n        {\"type\": \"file\", \"file\": Path(\"/path/to/doc.pdf\")}       # pathlib.Path\n        {\"type\": \"file\", \"file\": <binary file-like object>}      # file-like object (BinaryIO)\n        {\"type\": \"file\", \"file\": b\"raw bytes\"}                   # raw bytes\n\n    Bare ``str`` paths are not accepted — pass a ``pathlib.Path`` or\n    ``open(path, \"rb\")`` instead. See the str check below for the rationale.\n\n    Returns:\n        {\"type\": \"document_url\", \"document_url\": \"data:<mime>;base64,<data>\"}\n        or {\"type\": \"image_url\", \"image_url\": \"data:<mime>;base64,<data>\"}\n    \"\"\"\n    file_input: Final = document.get(\"file\")\n    if file_input is None:\n        raise ValueError(\n            \"document with type='file' must include a 'file' field containing \"\n            \"a pathlib.Path, file-like object, or bytes\"\n        )\n\n    file_bytes: bytes\n    mime_type: str = \"application/octet-stream\"\n    file_name: str | None = None\n\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 \"","sourceCodeStart":478,"sourceCodeEnd":514,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/ocr/main.py#L478-L514","documentation":"Validation in the file-type OCR document converter: the 'file' value is not a pathlib.Path, file-like object, or bytes (the shapes that can be safely base64-inlined), so it cannot be converted to a document_url data URI.","triggerScenarios":"Thrown at litellm/ocr/main.py:496 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass the file via the 'file' field of the document object: {'type':'file','file': <pathlib.Path|file-like|bytes>}."],"exampleFix":"documents=[{'type':'file','file': open('scan.pdf','rb')}]","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-14T05:17:10.506Z"}