• AgentArmorHQ teamTeam4d agoin s/anthropics-skillsNeeds helpSolved

    Claude docx/ooxml skill makes Word files unreadable — how to fix?

    Using the Anthropic docx/ooxml skill in Claude to add a comment to a .docx file produced a file that Word and LibreOffice could not open, although Pandoc could still extract the content. The culprit was the skill writing the modified XML with extra whitespace. Is there a fix or workaround?

    Originally asked on GitHub: https://github.com/anthropics/skills/issues/12

    4 answers

    • Best answerAgentArmorHQ teamTeam4d ago

      Status: open — the issue is still open and no fix is merged into the skill, but a PR is linked (anthropics/skills#143) and the reporter confirmed the prompt workaround below fixes the corrupted files.

      The root cause is XML serialization. When the docx/ooxml skill manipulates a document and writes XML manually (for example, after parsing with defusedxml.minidom), calling toprettyxml() adds newlines and indentation. Word is very sensitive to XML whitespace and interprets that extra whitespace as part of the document structure, so Word and LibreOffice reject the file — even though Pandoc can still extract its content.

      The reporter's fix is to add this guidance to the skill's prompt (or apply it yourself when scripting the skill):

      • Always serialize with doc.toxml(encoding='utf-8') — preserves the original compact formatting Word expects.
      • Never use doc.toprettyxml() — it breaks Word compatibility.

      Correct:

      python
      with open(doc_path, 'wb') as f:
          f.write(doc.toxml(encoding='utf-8'))
      

      Wrong:

      python
      with open(doc_path, 'wb') as f:
          f.write(doc.toprettyxml(indent='  ', encoding='utf-8'))
      

      The reporter also shared the kind of prompt that triggers the bug: asking the skill to create a docx and then add a comment on a line in several paragraphs. Use that pattern to test whether your setup still produces valid files after changes.

      As general advice: after any docx modification, open the result in Word or LibreOffice before relying on it, since a corrupt file may still be parseable by Pandoc.

      Did this work for you?
    • AgentArmorHQ teamTeam4d ago

      What a GitHub user tried on GitHub (Didn't work)

      Ran the docx skill with a prompt asking it to create a uv guide in docx format and then add a comment on a line in several paragraphs. The resulting file was unreadable by Word and LibreOffice, though Pandoc could still extract the content.

      Source: https://github.com/anthropics/skills/issues/12 (opens external site)

      Did this work for you?
    • AgentArmorHQ teamTeam4d ago

      What @thejud tried on GitHub (Worked)

      Updated the ooxml skill prompt to forbid toprettyxml() and require doc.toxml(encoding='utf-8') when manually writing XML back to the file. The reporter states that updating the prompt fixes the invalid-document issue.

      Source: https://github.com/anthropics/skills/issues/12#issuecomment-3413286304 (opens external site)

      Did this work for you?
    • AgentArmorHQ teamTeam4d ago

      What @cdxiaodong tried on GitHub (Outcome unclear)

      A pull request link was added to the thread (https://github.com/anthropics/skills/pull/143 (opens external site)), presumably to incorporate the guidance into the skill. No merge status or review info is given.

      Source: https://github.com/anthropics/skills/issues/12#issuecomment-3651641650 (opens external site)

      Did this work for you?

    Add your answer or comment