agentscope-ai/agentscope · error · ValueError

Failed to parse {filename!r} as PPTX: {e}

Error message

Failed to parse {filename!r} as PPTX: {e}

What it means

The PPTX parser wraps python-pptx's Presentation() failure: the provided bytes/path could not be loaded as a valid PowerPoint file. It is a ValueError raised during parse() when the underlying library throws any exception while opening the file.

Source

Thrown at src/agentscope/rag/_parser/_ppt.py:212

        """
        if isinstance(file, str):
            with open(file, "rb") as fp:
                file = fp.read()

        try:
            from pptx import Presentation
        except ImportError as e:
            raise ImportError(
                "Please install python-pptx to use the PowerPoint "
                "parser. You can install it by "
                "`pip install python-pptx` (or "
                "`pip install agentscope[rag]`).",
            ) from e

        try:
            prs = Presentation(io.BytesIO(file))
        except Exception as e:  # pylint: disable=broad-except
            raise ValueError(
                f"Failed to parse {filename!r} as PPTX: {e}",
            ) from e

        sections: list[Section] = []
        for slide_idx, slide in enumerate(prs.slides):
            sections.extend(
                self._parse_slide(slide, slide_idx, filename),
            )
        return sections

    # ------------------------------------------------------------------
    # Slide-level parsing
    # ------------------------------------------------------------------

    def _parse_slide(
        self,
        slide: Any,
        slide_idx: int,

View on GitHub (pinned to e90f1c7592)

Solutions

  1. Verify the file is actually OOXML .pptx (unzip -l file.pptx should show ppt/slides/)
  2. Filter or convert legacy .ppt files before parsing (e.g. with LibreOffice: soffice --convert-to pptx)
  3. Validate the magic bytes (PK\x03\x04 zip signature) before calling parse
  4. Install rag extras: pip install 'agentscope[rag]'

Example fix

// before
sections = ppt_parser.parse(path)  # raises for legacy .ppt
// after
if open(path,'rb').read(4) != b'PK\x03\x04':
    raise SkipFile(path)
sections = ppt_parser.parse(path)
Defensive patterns

Strategy: validation

Validate before calling

import zipfile
path = 'deck.pptx'
valid = zipfile.is_zipfile(path) and zipfile.ZipFile(path).namelist().count('[Content_Types].xml') >= 0 and any(n.startswith('ppt/slides/') for n in zipfile.ZipFile(path).namelist())

Type guard

def is_pptx(path: str) -> bool:
    return zipfile.is_zipfile(path)

Try / catch

try:
    sections = parser.parse(path)
except ValueError as e:
    if 'as PPTX' in str(e): logger.warning('skipping invalid pptx %s', path)
    else: raise

Prevention

When it happens

Trigger: Calling PPTParser.parse() (directly or via build_index) with a file that is not a valid .pptx — e.g. a .ppt (legacy binary), a .docx, a zero-byte/corrupt file, or a password-protected presentation.

Common situations: Users pointing a RAG pipeline at an Office directory containing legacy .ppt files, files downloaded incompletely, or renamed non-PPTX files; missing python-pptx install also surfaces nearby.

Understand the failure class

Related errors


AI-assisted analysis of agentscope-ai/agentscope@e90f1c7592 (2026-08-28). Data as JSON: /api/errors/7b363de4c0365ed2. Report an issue: GitHub.