Document Docx
Create/edit .docx files with styles, templates, comments, and extraction workflows. Use when asked to generate Word reports, contracts, proposals, or convert Word content.
Specification
- Skill ID
- vasilyu1983/ai-agents-public/document-docx
- Publisher
- vasilyu1983
- Repository
- ai-agents-public
- Installs
- 0
- Files
- 23
- Requires
- Claude Code + Codex. Uses runtime-specific allowed-tools / argument-hint fields.
- Synced
- Sep 23, 2026
How to use it
Open any RiverX project, open the Skills panel in the chat, and search for this identifier. The files are fetched from the source repository at install time.
vasilyu1983/ai-agents-public/document-docxInstalls these files- SKILL.md
- agents/openai.yaml
- assets/contract-template.md
- assets/doc-template-pack.md
- assets/docx-template-authoring-checklist.md
- assets/report-template.md
- data/sources.json
- learnings.consolidated.md
- learnings.md
- references/accessibility-compliance.md
- references/cross-platform-compatibility.md
- references/document-automation-pipelines.md
- references/docx-patterns.md
- references/extraction-stack.md
- references/llm-extraction-workflows.md
- references/review-comments-workflows.md
- references/template-workflows.md
- references/tracked-changes.md
- scripts/docx_extract.py
- scripts/docx_inspect_ooxml.py
- scripts/docx_quality_gate.py
- scripts/docx_render_template.py
- scripts/docx_to_html.mjs
What this skill tells the agent
Document DOCX Skill - Quick Reference
This skill covers creation, editing, review, extraction, and release workflows for .docx documents.
Modern best practices (Jul 2026):
- Treat
.docxas the editable source and PDF as a release artifact. - Prefer templates and built-in styles over manual formatting.
- Use comments for review notes; use Word Compare for true redlines.
- For LLM/RAG extraction, optimize for structure, trust level, and sanitization rather than visual fidelity.
- Treat macro-enabled Office files (
.docm,.dotm) as untrusted by default. - Before promising a feature (comments, alt text, tracked changes), check the installed library version — several of these APIs are recent additions and silently absent on older pins. See "Version-Gate Before Promising A Feature" below.
Core Decision Rules (2026)
- If non-developers need to own layout/design, prefer
docxtplwith a Word-authored template. - If the stack is Python and edits are structural, prefer
python-docx. - If the stack is TypeScript/Node and the output is generated server-side, prefer
docx. - If you need semantic HTML from a trusted document, prefer
mammoth, then sanitize before rendering or storing the output. - If you need Markdown/JSON for search, indexing, or RAG, prefer
MarkItDownorDocling. - If the user asks for tracked changes, do not promise high-level library support. Generate a revised
.docxand use Word Compare, or switch to OOXML-specialized tooling. - If the user asks for PDF output, prefer Word automation for highest fidelity and LibreOffice headless for cross-platform batch workflows.
- If the input is
.doc, convert to.docxfirst. If it is.docmor.dotm, do not trust embedded macros.
Quick Reference
| Task | Tool/Library | Language | When to Use |
|---|---|---|---|
| Create/edit DOCX | python-docx | Python | Structural edits, reports, contracts, section/table/image work |
| Create/edit DOCX | docx | Node.js | Server-side generation in TypeScript-heavy stacks |
| Template fill | docxtpl | Python | Word-authored templates, mail merge, batch documents |
| Add/access comments | python-docx + Word review workflow | Python / Word | Review notes without tracked revisions |
| Convert DOCX to HTML | mammoth | Node.js | Semantic HTML from trusted documents |
| Convert DOCX to Markdown | MarkItDown | Python | LLM/RAG ingestion where Markdown is preferred |
| Convert DOCX to Markdown/HTML/JSON | Docling | Python / CLI | Multi-format ingestion, structured extraction, batch conversion |
| Parse text/tables/metadata | python-docx + OOXML inspection | Python | Extraction, audits, migration tooling |
| Parse tracked changes/comments | OOXML, Open XML SDK, docx4j, Aspose.Words | Python / .NET / Java | Revision-heavy workflows and interoperability edge cases |
| Convert DOCX to PDF | Word automation / LibreOffice headless | OS tooling | Release artifacts and cross-platform smoke checks |
Selection Guide
- Prefer
docxtplwhen a legal, ops, or business user needs to maintain the template in Word. - Prefer
python-docxfor moderate formatting complexity where you control the document structure in code. - Prefer
docxwhen the surrounding service and tests already live in Node.js. - Prefer
mammothfor trusted, text-first conversion to HTML; it is not a fidelity-preserving renderer. - Prefer
MarkItDownfor simple DOCX-to-Markdown pipelines. - Prefer
Doclingwhen DOCX is only one input among many formats or you need HTML/JSON/Markdown/text output from a unified pipeline.
ASCII Flow
DOCX request
|
v
Classify file + trust level
|-- .docx / .dotx -----> normal OOXML workflow
|-- .doc -------------> convert to .docx first
|-- .docm / .dotm ----> treat macros as untrusted
|
v
Choose lane
|-- Word-owned template ------> docxtpl
|-- Python structural edit ---> python-docx
|-- Node service generation --> docx
|-- trusted HTML conversion --> mammoth + sanitizer
|-- Markdown / JSON ingest ---> MarkItDown or Docling
|-- tracked-change review ----> revised DOCX + Word Compare
|
v
Generate, edit, or extract
|
v
Quality gate
|-- parseability + unresolved tags ---> scripts/docx_quality_gate.py
|-- comments / revisions / OOXML ----> scripts/docx_inspect_ooxml.py
|
v
Viewer, accessibility, and release checksFormat And Safety Caveats
.docxand.dotxare Office Open XML packages;.docis legacy binary and needs conversion first..docmand.dotmare macro-enabled; do not treat them as safe content inputs.python-docxcan add and read comments in the main document body, but not threaded replies/resolved states, and not comment anchors in headers/footers.python-docxdoes not provide reliable tracked-change authoring.mammothperforms no sanitization of generated HTML or links from untrusted source documents.- Tables of contents and many Word fields are placeholders until updated in Word.
Version-Gate Before Promising A Feature
Do not assume the environment has a current library. This is the single most common way this skill causes a confident-but-wrong answer:
Document.add_comment()only exists frompython-docx1.2.0 onward. On an older pinned version it raisesAttributeError, not a graceful fallback. Check first:python -c "import docx; print(docx.__version__)".- python-docx still has no public high-level property for image alt text (no
.alt_textonInlineShape) as of the current 1.x line —InlineShapeonly documentsheight,width, andtype. The OOXML workaround inreferences/accessibility-compliance.mdreaches into the private_inlineattribute; treat that as an implementation detail that can move between releases, re-verify after any python-docx upgrade, and preferpython-docx's own comment/style APIs wherever a public one exists instead of private attributes. - If a user asks for a feature this skill flags as unsupported (tracked-change authoring, threaded comment replies, resolved-state comments), say so plainly rather than approximating it with formatting hacks — a document that merely looks right (e.g., colored/struck-through text standing in for
<w:ins>/<w:del>) will fail any real redline/legal review because it carries no revision metadata.
Default Workflow
- Identify the file type and trust level:
.docx/.dotxvs.docm/.dotmvs legacy.doc. - Pick the lane:
- Template generation ->
docxtpl - Programmatic structure edits ->
python-docxordocx - Review/comments -> comments or Word Compare
- LLM extraction ->
MarkItDown,Docling, ormammoth
- Generate or modify the document.
- Run
scripts/docx_quality_gate.pyand, when needed,scripts/docx_inspect_ooxml.py. - If shipping externally, validate rendering in Word plus at least one secondary viewer and apply accessibility hygiene.
Core Operations
Create A Document (Python - python-docx)
from docx import Document
from docx.enum.text import WD_ALIGN_PARAGRAPH
from docx.shared import Inches
doc = Document()
title = doc.add_heading("Quarterly Review", 0)
title.alignment = WD_ALIGN_PARAGRAPH.CENTER
doc.add_paragraph("Executive summary goes here.")
table = doc.add_table(rows=2, cols=2)
table.style = "Table Grid"
table.rows[0].cells[0].text = "Metric"
table.rows[0].cells[1].text = "Value"
table.rows[1].cells[0].text = "Revenue"
table.rows[1].cells[1].text = "$1.2M"
doc.add_picture("chart.png", width=Inches(4.5))
doc.save("quarterly-review.docx")Add A Review Comment (Python - python-docx)
from docx import Document
doc = Document()
paragraph = doc.add_paragraph("This clause needs legal review.")
comment = doc.add_comment(
runs=paragraph.runs,
text="Clarify whether this applies to renewals as well.",
author="Legal",
initials="LG",
)
comment.paragraphs[0].add_run(" Add the renewal edge case explicitly.").bold = TrueMore from vasilyu1983
Use this skill in a project
Open any RiverX project, search the Skills panel for vasilyu1983/ai-agents-public/document-docx, and install it in one click.
