# DOCX Parse Resilient

Extract text from DOCX files with shell-primary approach and Python zipfile fallback...

- Repository: https://github.com/HKUDS/AgentPilot (7784 stars)
- Category: Documents
- License: MIT
- Last updated: 2026-11-01
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add HKUDS/AgentPilot --skill docx-parse-resilient -g -a claude-code -y`
Codex: `npx skills add HKUDS/AgentPilot --skill docx-parse-resilient -g -a codex -y`
Cursor: `npx skills add HKUDS/AgentPilot --skill docx-parse-resilient -g -a cursor -y`
Gemini CLI: `npx skills add HKUDS/AgentPilot --skill docx-parse-resilient -g -a gemini-cli -y`

## Description

Extract text from DOCX files with shell-primary approach and Python zipfile fallback for maximum reliability

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# Resilient DOCX Text Extraction

Extract text from Microsoft Word (.docx) files using a robust two-tier approach: shell-based extraction as the primary method, with Python zipfile fallback when shell commands fail or return no output.

## When to Use

- Python environment may lack `python-docx` but `zipfile` module is available (standard library)
- Working in constrained or inconsistent environments (containers, minimal images, CI/CD)
- Shell `unzip` command returns errors or no output
- Need reliable extraction with automatic fallback

## Core Technique

DOCX files are ZIP archives containing XML files. This skill provides two extraction methods:

1. **Primary (Shell)**: `unzip -p` + `sed` for fast extraction
2. **Fallback (Python)**: `zipfile` module for reliable extraction when shell fails

## Step-by-Step Instructions

### 1. Verify the DOCX file exists

```bash
ls -la document.docx
```

### 2. Test shell extraction first (recommended)

Try the shell-based approach:

```bash
unzip -p document.docx word/document.xml 2>/dev/null | sed -e 's/<[^>]*>//g'
```

### 3. Check if shell extraction produced output

Verify the shell method returned content:

```bash
content=$(unzip -p document.docx word/document.xml 2>/dev/null | sed -e 's/<[^>]*>//g')
if [ -z "$content" ]; then
    echo "Shell extraction returned no output, trying Python fallback..."
fi
```

### 4. Use Python zipfile fallback if needed

When shell commands fail or return empty output, use Python's standard `zipfile` module:

```bash
python3 -c "
import zipfile
import sys
import re

try:
    with zipfile.ZipFile('document.docx', 'r') as z:
        content = z.read('word/document.xml').decode('utf-8')
        # Strip XML tags
        text = re.sub(r'<[^>]*>', '', content)
        # Clean whitespace
        lines = [line.strip() for line in text.split('\n') if line.strip()]
        print('\n'.join(lines))
except Exception as e:
    print(f'Error: {e}', file=sys.stderr)
    sys.exit(1)
"
```

The rest: https://github.com/HKUDS/AgentPilot/blob/HEAD/openspace/benchmarks/gdpval/skills/docx-shell-parse-enhanced/SKILL.md
