BerriAI/litellm · error · FileNotFoundError

File not found: {file_path}

Error message

File not found: {file_path}

What it means

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.

Source

Thrown at litellm/ocr/main.py:522

    if isinstance(file_input, str):
        # Bare strings are rejected here. The OCR ``document`` accepts a
        # ``{"type": "file", "file": <value>}`` shape, and when this helper
        # runs in a proxy request handler ``<value>`` is attacker-controlled.
        # Opening it as a path is an arbitrary local file read on the proxy
        # host, which is then base64-encoded and forwarded to the OCR
        # provider — an exfiltration primitive.
        raise ValueError(
            "OCR file input does not accept bare str values. Pass bytes, "
            "a pathlib.Path, or a file-like object. To OCR a local file "
            "from a path, call open(path, 'rb') yourself."
        )
    if isinstance(file_input, os.PathLike):
        # os.PathLike (pathlib.Path and custom __fspath__ classes) is a
        # Python-level type that HTTP form values can't fabricate.
        file_path: Final = str(file_input)
        if not os.path.isfile(file_path):
            raise FileNotFoundError(f"File not found: {file_path}")
        mime_type = get_mime_type(file_path)
        file_name = os.path.basename(file_path)
        with open(file_path, "rb") as f:
            file_bytes = f.read()
    elif isinstance(file_input, bytes):
        file_bytes = file_input
    elif isinstance(file_input, IOBase) or hasattr(file_input, "read"):
        if hasattr(file_input, "name"):
            file_name = getattr(file_input, "name", None)
            if file_name:
                mime_type = get_mime_type(file_name)
        file_bytes = file_input.read()
        if isinstance(file_bytes, str):
            file_bytes = file_bytes.encode("utf-8")
    else:
        raise ValueError(
            f"Unsupported file input type: {type(file_input)}. Expected pathlib.Path, bytes, or a file-like object."
        )

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Verify the file path exists and is readable before calling.
  2. Use an absolute path if the working directory differs.

Example fix

import os; assert os.path.exists(file_path), file_path
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at litellm/ocr/main.py:522 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/4090e5e7bffc9f14. Report an issue: GitHub.