{"record":{"id":"fcce399d2351f411","repo":"run-llama/llama_index","slug":"resolve-audio-returned-zero-bytes","errorCode":null,"errorMessage":"resolve_audio returned zero bytes","messagePattern":"resolve_audio returned zero bytes","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/base/llms/types.py","lineNumber":505,"sourceCode":"\n        \"\"\"\n        data_buffer = (\n            self.audio\n            if isinstance(self.audio, IOBase)\n            else resolve_binary(\n                raw_bytes=self.audio,\n                path=self.path,\n                url=str(self.url) if self.url else None,\n                as_base64=as_base64,\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_audio returned zero bytes\")\n        return data_buffer\n\n    def inline_url(self) -> str:\n        b64 = self.resolve_audio(as_base64=True)\n        b64_str = b64.read().decode(\"utf-8\")\n        if self.format:\n            mimetype = filetype.get_type(ext=self.format).mime\n            if mimetype:\n                return f\"data:{mimetype};base64,{b64_str}\"\n        return f\"data:audio;base64,{b64_str}\"\n\n    async def aestimate_tokens(self, *args: Any, **kwargs: Any) -> int:\n        \"\"\"\n        Use TinyTag to estimate the duration of the audio file and convert to tokens.\n\n        Gemini estimates 32 tokens per second of audio\n        https://ai.google.dev/gemini-api/docs/tokens?lang=python\n","sourceCodeStart":487,"sourceCodeEnd":523,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/base/llms/types.py#L487-L523","documentation":"Raised by AudioBlock.resolve_audio when the resolved buffer (from raw bytes, path, or URL) has zero bytes. Same guard pattern as ImageBlock.resolve_image: it prevents empty audio payloads from reaching provider APIs.","triggerScenarios":"AudioBlock(audio=b\"\"), a 0-byte audio file path, or an audio URL returning an empty body; truncated uploads yielding empty files.","commonSituations":"Speech/audio ingestion pipelines where a fetch step wrote an empty file; expired presigned URLs returning empty 200s; test fixtures with placeholder empty audio.","solutions":["Validate the source before constructing: len(audio_bytes) > 0 or os.path.getsize(path) > 0.","On URL-based blocks, verify the download (content-length, first bytes) before assignment and retry failures.","Repair the upstream fetch/upload that produced empty audio."],"exampleFix":"# before\nblock = AudioBlock(path=\"clip.mp3\")  # 0-byte file\ndata = block.resolve_audio(as_base64=True).read()\n\n# after\nif os.path.getsize(\"clip.mp3\") == 0:\n    raise RuntimeError(\"empty audio file\")\nblock = AudioBlock(path=\"clip.mp3\")","handlingStrategy":"validation","validationCode":"import os\nok = (audio_bytes and len(audio_bytes) > 0) or (path and os.path.getsize(path) > 0)\nif not ok:\n    raise ValueError(\"audio source is empty\")","typeGuard":null,"tryCatchPattern":"try:\n    buf = block.resolve_audio(as_base64=True)\nexcept ValueError as e:\n    if \"zero bytes\" in str(e):\n        refetch_or_skip()\n    else:\n        raise","preventionTips":["Check media file sizes during ingestion, not at LLM call time.","Treat empty downloads as failures in your fetch layer."],"tags":["llama-index","audio","empty-input","multimodal"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}