run-llama/llama_index · error · ValueError

resolve_document returned zero bytes

Error message

resolve_document returned zero bytes

What it means

Raised by DocumentBlock.resolve_document when the buffer resolved from raw data, path, or URL is empty. (Note this path always resolves with as_base64=False.) It guards against sending empty PDF/document payloads to LLM APIs.

Source

Thrown at llama-index-core/llama_index/core/base/llms/types.py:731

        Resolve a document such that it is represented by a BufferIO object.
        """
        data_buffer = (
            self.data
            if isinstance(self.data, IOBase)
            else resolve_binary(
                raw_bytes=self.data,
                path=self.path,
                url=str(self.url) if self.url else None,
                as_base64=False,
            )
        )
        # Check size by seeking to end and getting position
        data_buffer.seek(0, 2)  # Seek to end
        size = data_buffer.tell()
        data_buffer.seek(0)  # Reset to beginning

        if size == 0:
            raise ValueError("resolve_document returned zero bytes")
        return data_buffer

    def _get_b64_bytes(self, data_buffer: IOBase) -> bytes:
        """
        Get base64-encoded bytes from a IOBase buffer.
        """
        return resolve_binary(data_buffer.read(), as_base64=True).read()

    def _get_b64_string(self, data_buffer: IOBase) -> str:
        """
        Get base64-encoded string from a IOBase buffer.
        """
        return self._get_b64_bytes(data_buffer).decode("utf-8")

    def inline_url(self) -> str:
        b64_str = self._get_b64_string(data_buffer=self.resolve_document())
        if self.document_mimetype:
            return f"data:{self.document_mimetype};base64,{b64_str}"

View on GitHub (pinned to afd0fef371)

Solutions

  1. Validate before construction: check file size or len(data) > 0.
  2. For URLs, fetch and verify non-empty content before creating the block (or wrap resolve in try/except and re-download).
  3. Fix the document-generation/download step producing empty files.

Example fix

# before
block = DocumentBlock(path="report.pdf")  # 0-byte PDF
buf = block.resolve_document()

# after
if os.path.getsize("report.pdf") == 0:
    raise RuntimeError("empty pdf")
block = DocumentBlock(path="report.pdf")
buf = block.resolve_document()
Defensive patterns

Strategy: validation

Validate before calling

import os
ok = (data and len(data) > 0) or (path and os.path.getsize(path) > 0)
if not ok:
    raise ValueError("document source is empty")

Try / catch

try:
    buf = block.resolve_document()
except ValueError as e:
    if "zero bytes" in str(e):
        regenerate_or_skip()
    else:
        raise

Prevention

When it happens

Trigger: DocumentBlock(data=b""), a 0-byte PDF path, or a document URL returning an empty body.

Common situations: PDF pipelines where generation or download failed silently leaving 0-byte files; empty blobs from object storage keys; placeholder documents in datasets.

Related errors


AI-assisted analysis of run-llama/llama_index@afd0fef371 (2026-08-15). Data as JSON: /api/errors/c5895b4bb6f7ca2c. Report an issue: GitHub.