BerriAI/litellm · error · ValueError

Uploaded file is empty

Error message

Uploaded file is empty

What it means

ValueError raised in OCR multipart parsing: a 'file' field was provided but the uploaded file has zero size (empty UploadFile), so there is no document content to process. The client must attach a non-empty file.

Source

Thrown at litellm/proxy/ocr_endpoints/endpoints.py:76

            f"Failed to parse multipart form data: {e}. "
            "When using curl with --form/-F, do NOT set the Content-Type header "
            "manually — curl will set it automatically with the required boundary."
        )

    uploaded_file = form.get("file")
    # request.form() may return either a FastAPI or Starlette UploadFile
    # depending on middleware; check both via isinstance (FastAPI's UploadFile
    # is a subclass of Starlette's) and fall back to duck-type check.
    if uploaded_file is None or (not isinstance(uploaded_file, UploadFile) and not hasattr(uploaded_file, "read")):
        raise ValueError("Multipart OCR request must include a 'file' field with the document to process")

    uploaded_file = cast(UploadFile, uploaded_file)

    # Seek to start in case the file was already partially read by middleware
    await uploaded_file.seek(0)
    file_content: Final = await uploaded_file.read()
    if not file_content:
        raise ValueError("Uploaded file is empty")

    document: Final = _build_document_from_upload(
        file_content=file_content,
        filename=uploaded_file.filename,
        content_type=uploaded_file.content_type,
    )

    data: Final[dict[str, Any]] = {"document": document}

    for field_name, field_value in form.items():
        if field_name in ("file", "document"):
            continue
        # Try to parse JSON values (e.g. pages=[0,1,2])
        if isinstance(field_value, str):
            try:
                data[field_name] = json.loads(field_value)
            except (json.JSONDecodeError, ValueError):
                data[field_name] = field_value

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Upload a non-empty file.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at litellm/proxy/ocr_endpoints/endpoints.py:76 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/401084a67e15053a. Report an issue: GitHub.