mcpField
D
document-docx

document-docx

github.com/vasilyu1983Documents475 installs
Repository

About document-docx

A DOCX skill for document automation and processing, covering template generation, structural edits, content extraction, and quality checks. It highlights file-safety concerns, format limitations, and pre-release validation.

Key features

  1. 01Template filling and batch generation with docxtpl
  2. 02Structural edits with python-docx
  3. 03Extracting DOCX text and structured content
  4. 04Inspecting revisions, comments, and OOXML
  5. 05Quality gates and format conversion

Use cases

  1. 01Generating DOCX files in batches from Word templates
  2. 02Extracting DOCX content for RAG
  3. 03Checking revisions and comments in reviewed files
  4. 04Validating documents and converting them to PDF before release

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/vasilyu1983/ai-agents-public --skill document-docx

After installing, type/document-docxin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

learnings.consolidated.md
learnings.md
agents/
openai.yaml
assets/
docx-template-authoring-checklist.md
data/
sources.json
references/
accessibility-compliance.md
cross-platform-compatibility.md
document-automation-pipelines.md
docx-extraction-failure-modes.md
docx-patterns.md
llm-extraction-workflows.md
review-comments-workflows.md
template-workflows.md
tracked-changes.md
scripts/
docx_extract.py
docx_inspect_ooxml.py
docx_quality_gate.py
docx_render_template.py
docx_to_html.mjs
test_docx_inspect_ooxml.py
test_docx_quality_gate.py
test_docx_to_html.mjs

Details

From the project README

Document DOCX Skill - Quick Reference

This skill covers the specialist .docx lanes: docxtpl template pipelines, python-docx structural edits and extraction, LLM/RAG ingestion, and accessibility/EAA compliance.

Boundary: when the official Anthropic docx skill is available, prefer it for plain create/edit (docx-js), tracked-change (redline) authoring via <w:ins>/<w:del> with validate.py, and comment authoring. When the user asks for "a document" without naming a format and a document connector or artifact type is available, prefer that over generating a .docx.

Core Decision Rules

  • Non-developers own the layout in Word, and code supplies data: docxtpl. Code decides the structure: python-docx (Python) or docx (Node).
  • Render templates fail-closed. docxtpl's defaults render a missing variable as blank and insert &/< unescaped, so the file opens fine and passes a tag scan. Use scripts/docx_render_template.py (StrictUndefined + autoescape); see references/template-workflows.md.
  • Tracked changes: never promise high-level library support, and never fake redlines with colour or strikethrough. Route authoring to the official docx skill's OOXML workflow. See references/tracked-changes.md.
  • Semantic HTML from a trusted file: mammoth, then sanitise (it does no sanitisation). Markdown/JSON for RAG: a Markdown converter or scripts/docx_extract.py; see references/llm-extraction-workflows.md.
  • DOCX feeding a KB or index: tables inside content controls are silently missing from Document.tables, tables pasted as images have no text, tracked changes need an explicit accept/original policy, and filenames can lie. Run the table-count detection check in references/docx-extraction-failure-modes.md before indexing any file (load it whenever DOCX is ingestion input).
  • PDF output: Word automation for the highest fidelity; LibreOffice headless for CI and batch.
  • .doc: convert to .docx first. .docm/.dotm: treat the macros as untrusted and never execute them.
  • .docx is the editable source; PDF is the release artifact.

Quick Reference

TaskToolWhen
Template fill, mail mergedocxtpl + scripts/docx_render_template.pyWord-authored templates, batch documents
Structural edits in Pythonpython-docx (references/docx-patterns.md)Styles, tables, sections, fields, hyperlinks
Commentspython-docx add_comment (version-gated) or the official docx skillReview notes without revisions
DOCX to HTMLmammoth via scripts/docx_to_html.mjsTrusted documents, semantic HTML
DOCX to JSON/Markdownscripts/docx_extract.py, Markdown convertersAutomation, RAG ingestion
Inspect revisions/commentsscripts/docx_inspect_ooxml.pyBefore editing any reviewed document
Release gatescripts/docx_quality_gate.pyEvery generated or edited file
DOCX to PDFWord automation / LibreOffice headlessRelease artifacts, CI smoke tests

Format And Safety Caveats

  • python-docx comments: main body only, no anchors in headers or footers, no threaded replies or resolved state, and anchors are whole runs.
  • python-docx has no tracked-change authoring, no alt-text property, no field API and no public hyperlink authoring API. The workarounds in the references use private attributes; re-verify them after upgrades.
  • A TOC and other Word fields stay empty or stale until updated in Word or rendered by LibreOffice.
  • New python-docx documents can inherit author, date and comments from the default template. Inspect core properties before distribution.

Version-Gate Before Promising A Feature

Do not assume the environment has a current library:

  • Document.add_comment() is a recent python-docx addition and raises AttributeError on older pins. Check hasattr(docx.document.Document, "add_comment") before promising comment support.
  • If a user asks for something flagged unsupported here (tracked-change authoring in python-docx, threaded replies, resolved comments), say so plainly and route to the official docx skill. Do not approximate it with formatting.

Default Workflow

  1. Identify the file type and trust level: .docx/.dotx, .docm/.dotm, or legacy .doc.
  2. If the document may carry review metadata, run scripts/docx_inspect_ooxml.py --json first.
  3. Generate or modify: docxtpl through docx_render_template.py, or python-docx/docx for structure.
  4. For a newly generated output, set doc.core_properties to the intended author, clear template comments, and set created/modified to datetime.now(timezone.utc).replace(tzinfo=None) (python-docx expects naive UTC). For edits to an existing file, preserve provenance unless the user requested a metadata reset.
  5. Run scripts/docx_quality_gate.py. It exits 2 on any issue, including a requested --check-libreoffice that could not run.
  6. Render to images and look at every page before shipping: soffice --headless --convert-to pdf out.docx && pdftoppm -png -r 80 out.pdf page, then open the page-*.png files. For external distribution, also check in Word and apply the accessibility checklist.
python3 scripts/docx_render_template.py template.docx context.json out.docx   # exit 2 on missing vars
python3 scripts/docx_quality_gate.py out.docx --json                          # exit 2 on any issue
python3 scripts/docx_extract.py in.docx --include headers footers comments --out extracted.json
node scripts/docx_to_html.mjs in.docx out.html --style-map map.txt --extract-images-dir assets/

Round-Trip Release Proof

  • Capture the expected counts of sections, tables, images, hyperlinks, comments and tracked changes before the final save.
  • Reopen the saved DOCX and compare the counts.
  • Render a copy and inspect page breaks, numbering, table overflow, missing fonts and unresolved tags.

A successful OOXML parse or text extraction does not prove layout fidelity. A visually correct PDF does not prove that comments, hyperlinks, fields or accessibility metadata survived in the editable DOCX. Record which viewer did the primary review and which secondary viewer was checked.

Navigation

Resources

Scripts

  • scripts/docx_inspect_ooxml.py - Dependency-free OOXML inspection for tracked changes and comments
  • scripts/docx_extract.py - Extract text, tables, metadata, and optional headers/footers/hyperlinks/comments/images to JSON
  • scripts/docx_render_template.py - Render a docxtpl template from JSON, failing on missing variables (--allow-missing for drafts)
  • scripts/docx_to_html.mjs - Convert trusted .docx to HTML with style maps and optional image extraction
  • scripts/docx_quality_gate.py - Validate parseability, unresolved template tags, tracked-change/comment signals, and optional LibreOffice conversion; exits 2 on any issue

Templates

Related Skills

Learnings Loop

When prior decisions or pitfalls are relevant, consult learnings.consolidated.md if present; use learnings.md only for needed history or as the available fallback. Otherwise skip both.

After applying it, if you encountered a pattern worth remembering, a mistake worth preventing, or a domain fact that surprised you, append one dated bullet to learnings.md via agents-skills-feedback-loop/scripts/append_learning.py. Do not modify SKILL.md itself.

Comments

Markdown supported