Validate PowerPoint files using python-pptx when read_file fails
Use this skill when read_file fails to properly read or validate PowerPoint (.pptx) files. This provides a reliable alternative for verifying presentation contents including slide count, titles, and structure.
If read_file with filetype pptx returns errors, incomplete content, or cannot extract slide information, proceed to the fallback method.
Execute Python code via run_shell using the python-pptx library to inspect the presentation:
from pptx import Presentation
# Load the presentation
prs = Presentation('path/to/file.pptx')
# Get basic info
slide_count = len(prs.slides)
print(f"Total slides: {slide_count}")
# Extract slide titles
for i, slide in enumerate(prs.slides):
if slide.shapes.title:
title = slide.shapes.title.text
print(f"Slide {i+1}: {title}")
else:
print(f"Slide {i+1}: [No title]")
Check that the presentation meets expected requirements:
from pptx import Presentation
prs = Presentation('path/to/file.pptx')
# Validation checks
expected_slides = 10 # Adjust based on requirements
actual_slides = len(prs.slides)
if actual_slides >= expected_slides:
print(f"✓ Slide count OK: {actual_slides} slides")