BerriAI/litellm · error · ValueError
OCR file input does not accept bare str values. Pass bytes,
Error message
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.
What it means
Security guard in the OCR file helper: file was supplied as a bare string. Because proxy request handlers pass user-controlled values, opening a str path would be an arbitrary-file-read/exfiltration primitive, so strings are refused and callers must pass bytes/Path/file objects themselves.
Source
Thrown at litellm/ocr/main.py:512
file_input: Final = document.get("file")
if file_input is None:
raise ValueError(
"document with type='file' must include a 'file' field containing "
"a pathlib.Path, file-like object, or bytes"
)
file_bytes: bytes
mime_type: str = "application/octet-stream"
file_name: str | None = None
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"):View on GitHub (pinned to 77b7c6c40c)
Solutions
- Do not pass a raw path string; open the file yourself and pass bytes, a Path, or a file-like object.
Example fix
file=open('/path/to/file.pdf','rb') # then pass this instead of '/path/to/file.pdf' Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at litellm/ocr/main.py:512 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/4ed1f95c9fd47fae.
Report an issue: GitHub.