run-llama/llama_index · error · ValueError
resolve_audio returned zero bytes
Error message
resolve_audio returned zero bytes
What it means
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.
Source
Thrown at llama-index-core/llama_index/core/base/llms/types.py:505
"""
data_buffer = (
self.audio
if isinstance(self.audio, IOBase)
else resolve_binary(
raw_bytes=self.audio,
path=self.path,
url=str(self.url) if self.url else None,
as_base64=as_base64,
)
)
# 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_audio returned zero bytes")
return data_buffer
def inline_url(self) -> str:
b64 = self.resolve_audio(as_base64=True)
b64_str = b64.read().decode("utf-8")
if self.format:
mimetype = filetype.get_type(ext=self.format).mime
if mimetype:
return f"data:{mimetype};base64,{b64_str}"
return f"data:audio;base64,{b64_str}"
async def aestimate_tokens(self, *args: Any, **kwargs: Any) -> int:
"""
Use TinyTag to estimate the duration of the audio file and convert to tokens.
Gemini estimates 32 tokens per second of audio
https://ai.google.dev/gemini-api/docs/tokens?lang=python
View on GitHub (pinned to afd0fef371)
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.
Example fix
# before
block = AudioBlock(path="clip.mp3") # 0-byte file
data = block.resolve_audio(as_base64=True).read()
# after
if os.path.getsize("clip.mp3") == 0:
raise RuntimeError("empty audio file")
block = AudioBlock(path="clip.mp3") Defensive patterns
Strategy: validation
Validate before calling
import os
ok = (audio_bytes and len(audio_bytes) > 0) or (path and os.path.getsize(path) > 0)
if not ok:
raise ValueError("audio source is empty") Try / catch
try:
buf = block.resolve_audio(as_base64=True)
except ValueError as e:
if "zero bytes" in str(e):
refetch_or_skip()
else:
raise Prevention
- Check media file sizes during ingestion, not at LLM call time.
- Treat empty downloads as failures in your fetch layer.
When it happens
Trigger: AudioBlock(audio=b""), a 0-byte audio file path, or an audio URL returning an empty body; truncated uploads yielding empty files.
Common situations: Speech/audio ingestion pipelines where a fetch step wrote an empty file; expired presigned URLs returning empty 200s; test fixtures with placeholder empty audio.
Related errors
- resolve_image returned zero bytes
- resolve_video returned zero bytes
- resolve_document returned zero bytes
- LLM must be a FunctionCallingLLM
- No embeddings to aggregate
AI-assisted analysis of run-llama/llama_index@afd0fef371 (2026-08-15).
Data as JSON: /api/errors/fcce399d2351f411.
Report an issue: GitHub.