{"record":{"id":"c5895b4bb6f7ca2c","repo":"run-llama/llama_index","slug":"resolve-document-returned-zero-bytes","errorCode":null,"errorMessage":"resolve_document returned zero bytes","messagePattern":"resolve_document returned zero bytes","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/base/llms/types.py","lineNumber":731,"sourceCode":"        Resolve a document such that it is represented by a BufferIO object.\n        \"\"\"\n        data_buffer = (\n            self.data\n            if isinstance(self.data, IOBase)\n            else resolve_binary(\n                raw_bytes=self.data,\n                path=self.path,\n                url=str(self.url) if self.url else None,\n                as_base64=False,\n            )\n        )\n        # Check size by seeking to end and getting position\n        data_buffer.seek(0, 2)  # Seek to end\n        size = data_buffer.tell()\n        data_buffer.seek(0)  # Reset to beginning\n\n        if size == 0:\n            raise ValueError(\"resolve_document returned zero bytes\")\n        return data_buffer\n\n    def _get_b64_bytes(self, data_buffer: IOBase) -> bytes:\n        \"\"\"\n        Get base64-encoded bytes from a IOBase buffer.\n        \"\"\"\n        return resolve_binary(data_buffer.read(), as_base64=True).read()\n\n    def _get_b64_string(self, data_buffer: IOBase) -> str:\n        \"\"\"\n        Get base64-encoded string from a IOBase buffer.\n        \"\"\"\n        return self._get_b64_bytes(data_buffer).decode(\"utf-8\")\n\n    def inline_url(self) -> str:\n        b64_str = self._get_b64_string(data_buffer=self.resolve_document())\n        if self.document_mimetype:\n            return f\"data:{self.document_mimetype};base64,{b64_str}\"","sourceCodeStart":713,"sourceCodeEnd":749,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/base/llms/types.py#L713-L749","documentation":"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.","triggerScenarios":"DocumentBlock(data=b\"\"), a 0-byte PDF path, or a document URL returning an empty body.","commonSituations":"PDF pipelines where generation or download failed silently leaving 0-byte files; empty blobs from object storage keys; placeholder documents in datasets.","solutions":["Validate before construction: check file size or len(data) > 0.","For URLs, fetch and verify non-empty content before creating the block (or wrap resolve in try/except and re-download).","Fix the document-generation/download step producing empty files."],"exampleFix":"# before\nblock = DocumentBlock(path=\"report.pdf\")  # 0-byte PDF\nbuf = block.resolve_document()\n\n# after\nif os.path.getsize(\"report.pdf\") == 0:\n    raise RuntimeError(\"empty pdf\")\nblock = DocumentBlock(path=\"report.pdf\")\nbuf = block.resolve_document()","handlingStrategy":"validation","validationCode":"import os\nok = (data and len(data) > 0) or (path and os.path.getsize(path) > 0)\nif not ok:\n    raise ValueError(\"document source is empty\")","typeGuard":null,"tryCatchPattern":"try:\n    buf = block.resolve_document()\nexcept ValueError as e:\n    if \"zero bytes\" in str(e):\n        regenerate_or_skip()\n    else:\n        raise","preventionTips":["Reject empty PDFs at document-parser output.","Verify object-store blobs have non-zero size before referencing them."],"tags":["llama-index","document","pdf","empty-input","multimodal"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}