infiniflow/ragflow · error · Exception

Document file is empty

Error message

Document file is empty

What it means

Raised in the DocGenerator message flow (agent/component/docs_generator.py) after a format generator returns: the produced file bytes are empty (falsy). It guards against writing an empty blob to storage and returning a broken document id. Usually a symptom of an upstream pandoc/conversion step producing nothing rather than a configuration error.

Source

Thrown at agent/component/docs_generator.py:120

                    mime_type = "application/pdf"
                elif output_format == "docx":
                    file_path, file_bytes = self._generate_docx(content)
                    mime_type = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
                elif output_format == "txt":
                    file_path, file_bytes = self._generate_txt(content)
                    mime_type = "text/plain"
                elif output_format == "markdown":
                    file_path, file_bytes = self._generate_markdown(content)
                    mime_type = "text/markdown"
                elif output_format == "html":
                    file_path, file_bytes = self._generate_html(content)
                    mime_type = "text/html"
                else:
                    raise Exception(f"Unsupported output format: {output_format}")

                filename = os.path.basename(file_path)
                if not file_bytes:
                    raise Exception("Document file is empty")

                file_size = len(file_bytes)
                file_base64 = base64.b64encode(file_bytes).decode("utf-8")
                doc_id = get_uuid()
                settings.STORAGE_IMPL.put(self._canvas.get_tenant_id(), doc_id, file_bytes)

                logging.info(
                    "Successfully generated %s: %s (Size: %s bytes)",
                    output_format.upper(),
                    filename,
                    file_size,
                )

                download_info = {
                    "doc_id": doc_id,
                    "filename": filename,
                    "mime_type": mime_type,
                    "size": file_size,

View on GitHub (pinned to 554fb1133a)

Solutions

  1. Verify the component's content input actually resolves to non-empty text at run time (log it just before generation)
  2. If content is fine, test the same markdown through pandoc directly to see whether the toolchain produces empty output, and update/replace pandoc
  3. Ensure upstream components (LLM/generate) succeeded and their output is wired into DocGenerator's content parameter

Example fix

# before
self.content = "{{gen_output}}"   # unresolved placeholder -> empty render

# after
self.content = component_input   # verified non-empty string from upstream
Defensive patterns

Strategy: try-catch

Validate before calling

content = resolve_input(param.content)
if not content or not content.strip():
    raise ValueError('DocGenerator content resolved to empty text; check upstream component wiring')

Try / catch

try:
    result = doc_generator.run(...)
except Exception as e:
    if str(e) == 'Document file is empty':
        log_upstream_content(param.content)
        raise RuntimeError('Document generation produced no bytes; verify content input and pandoc install') from e
    raise

Prevention

When it happens

Trigger: Running DocGenerator with content that converts to zero bytes (e.g. whitespace-only input combined with a template), or a pandoc invocation that silently outputs an empty file for the chosen format; also storage decorators returning empty on failure. The check is `if not file_bytes: raise Exception('Document file is empty')` after _generate_pdf/docx/txt/markdown/html.

Common situations: Content parameter resolving to an empty/unrendered template variable (e.g. a reference like {input} that produced nothing); pandoc version quirks emitting empty output for exotic markdown; edge-case formats (html with only stripped tags).

Related errors


AI-assisted analysis of infiniflow/ragflow@554fb1133a (2026-08-15). Data as JSON: /api/errors/adfc71ec016c6fa2. Report an issue: GitHub.