<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>AI Tools on KnightLi Blog</title>
        <link>https://www.knightli.com/en/categories/ai-tools/</link>
        <description>Recent content in AI Tools on KnightLi Blog</description>
        <generator>Hugo -- gohugo.io</generator>
        <language>en</language>
        <lastBuildDate>Sun, 05 Apr 2026 22:09:11 +0800</lastBuildDate><atom:link href="https://www.knightli.com/en/categories/ai-tools/index.xml" rel="self" type="application/rss+xml" /><item>
        <title>LLM Quantization Explained: How to Choose FP16, Q8, Q5, Q4, or Q2</title>
        <link>https://www.knightli.com/en/2026/04/05/llm-quantization-guide-fp16-q4-q2/</link>
        <pubDate>Sun, 05 Apr 2026 22:09:11 +0800</pubDate>
        
        <guid>https://www.knightli.com/en/2026/04/05/llm-quantization-guide-fp16-q4-q2/</guid>
        <description>&lt;p&gt;The core goal of quantization is simple: trade a small amount of precision for a smaller model size, lower VRAM usage, and faster inference.&lt;br&gt;
For local deployment, picking the right quantization format is often more important than chasing a larger parameter count.&lt;/p&gt;
&lt;h2 id=&#34;what-is-quantization&#34;&gt;What Is Quantization
&lt;/h2&gt;&lt;p&gt;Quantization means compressing model parameters from higher-precision formats (such as &lt;code&gt;FP16&lt;/code&gt;) into lower-bit formats (such as &lt;code&gt;Q8&lt;/code&gt; and &lt;code&gt;Q4&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;A simple analogy:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Original model: like a high-quality photo, clear but large.&lt;/li&gt;
&lt;li&gt;Quantized model: like a compressed photo, slightly less detail but lighter and faster.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;common-quantization-formats&#34;&gt;Common Quantization Formats
&lt;/h2&gt;&lt;table&gt;
  &lt;thead&gt;
      &lt;tr&gt;
          &lt;th&gt;Quantization&lt;/th&gt;
          &lt;th&gt;Precision / Bit Width&lt;/th&gt;
          &lt;th&gt;Size&lt;/th&gt;
          &lt;th&gt;Quality Loss&lt;/th&gt;
          &lt;th&gt;Recommended Use&lt;/th&gt;
      &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
      &lt;tr&gt;
          &lt;td&gt;FP16&lt;/td&gt;
          &lt;td&gt;16-bit float&lt;/td&gt;
          &lt;td&gt;Largest&lt;/td&gt;
          &lt;td&gt;Almost none&lt;/td&gt;
          &lt;td&gt;Research, evaluation, max quality&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Q8_0&lt;/td&gt;
          &lt;td&gt;8-bit integer&lt;/td&gt;
          &lt;td&gt;Larger&lt;/td&gt;
          &lt;td&gt;Almost none&lt;/td&gt;
          &lt;td&gt;High-end PCs, quality + performance&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Q5_K_M&lt;/td&gt;
          &lt;td&gt;5-bit mixed&lt;/td&gt;
          &lt;td&gt;Medium&lt;/td&gt;
          &lt;td&gt;Slight&lt;/td&gt;
          &lt;td&gt;Daily driver, balanced choice&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Q4_K_M&lt;/td&gt;
          &lt;td&gt;4-bit mixed&lt;/td&gt;
          &lt;td&gt;Smaller&lt;/td&gt;
          &lt;td&gt;Acceptable&lt;/td&gt;
          &lt;td&gt;General default, strong value&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Q3_K_M&lt;/td&gt;
          &lt;td&gt;3-bit mixed&lt;/td&gt;
          &lt;td&gt;Very small&lt;/td&gt;
          &lt;td&gt;Noticeable&lt;/td&gt;
          &lt;td&gt;Low-spec devices, run-first&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Q2_K&lt;/td&gt;
          &lt;td&gt;2-bit mixed&lt;/td&gt;
          &lt;td&gt;Smallest&lt;/td&gt;
          &lt;td&gt;Significant&lt;/td&gt;
          &lt;td&gt;Extreme resource limits, fallback&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&#34;quantization-naming-rules&#34;&gt;Quantization Naming Rules
&lt;/h2&gt;&lt;p&gt;Take &lt;code&gt;gemma-4:4b-q4_k_m&lt;/code&gt; as an example:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;gemma-4:4b&lt;/code&gt;: model name and parameter scale.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;q4&lt;/code&gt;: 4-bit quantization.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;k&lt;/code&gt;: K-quants (an improved quantization method).&lt;/li&gt;
&lt;li&gt;&lt;code&gt;m&lt;/code&gt;: medium level (common options also include &lt;code&gt;s&lt;/code&gt;/small and &lt;code&gt;l&lt;/code&gt;/large).&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;quick-selection-by-vram&#34;&gt;Quick Selection by VRAM
&lt;/h2&gt;&lt;table&gt;
  &lt;thead&gt;
      &lt;tr&gt;
          &lt;th&gt;RAM / VRAM&lt;/th&gt;
          &lt;th&gt;Recommended Quantization&lt;/th&gt;
      &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
      &lt;tr&gt;
          &lt;td&gt;4 GB&lt;/td&gt;
          &lt;td&gt;Q3_K_M / Q2_K&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;8 GB&lt;/td&gt;
          &lt;td&gt;Q4_K_M&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;16 GB&lt;/td&gt;
          &lt;td&gt;Q5_K_M / Q8_0&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;32 GB+&lt;/td&gt;
          &lt;td&gt;FP16 / Q8_0&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Start with a version that runs stably on your machine, then move up in precision step by step instead of jumping straight to the biggest model.&lt;/p&gt;
&lt;h2 id=&#34;practical-tips&#34;&gt;Practical Tips
&lt;/h2&gt;&lt;ol&gt;
&lt;li&gt;Start with &lt;code&gt;Q4_K_M&lt;/code&gt; by default and test real tasks first.&lt;/li&gt;
&lt;li&gt;If response quality is not enough, move up to &lt;code&gt;Q5_K_M&lt;/code&gt; or &lt;code&gt;Q8_0&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;If VRAM or speed is the main bottleneck, move down to &lt;code&gt;Q3_K_M&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Use the same test set every time you switch quantization formats.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;conclusion&#34;&gt;Conclusion
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;Quality first: &lt;code&gt;FP16&lt;/code&gt; or &lt;code&gt;Q8_0&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Balance first: &lt;code&gt;Q5_K_M&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;General default: &lt;code&gt;Q4_K_M&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Low-spec fallback: &lt;code&gt;Q3_K_M&lt;/code&gt; or &lt;code&gt;Q2_K&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The key is not &amp;ldquo;bigger is always better&amp;rdquo;, but &amp;ldquo;the most stable and usable result under your hardware limits.&amp;rdquo;&lt;/p&gt;
</description>
        </item>
        <item>
        <title>Google Gemma 4 Model Comparison: How to Choose Between 2B/4B/26B/31B</title>
        <link>https://www.knightli.com/en/2026/04/05/google-gemma-4-model-comparison/</link>
        <pubDate>Sun, 05 Apr 2026 08:30:00 +0800</pubDate>
        
        <guid>https://www.knightli.com/en/2026/04/05/google-gemma-4-model-comparison/</guid>
        <description>&lt;p&gt;Gemma 4 focuses on &lt;code&gt;multimodality&lt;/code&gt; and &lt;code&gt;local offline inference&lt;/code&gt;, with a full range from lightweight to high-performance models. For most local deployment users, the key is not choosing the largest model, but choosing the one that best matches hardware and task needs.&lt;/p&gt;
&lt;h2 id=&#34;gemma-4-model-comparison&#34;&gt;Gemma 4 Model Comparison
&lt;/h2&gt;&lt;blockquote&gt;
&lt;p&gt;The table below is for quick model selection. Actual performance and resource usage should be validated in your own environment.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;table&gt;
  &lt;thead&gt;
      &lt;tr&gt;
          &lt;th&gt;Model&lt;/th&gt;
          &lt;th&gt;Parameter Size&lt;/th&gt;
          &lt;th&gt;Positioning&lt;/th&gt;
          &lt;th&gt;Key Strengths&lt;/th&gt;
          &lt;th&gt;Main Limitations&lt;/th&gt;
          &lt;th&gt;Recommended Scenarios&lt;/th&gt;
      &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
      &lt;tr&gt;
          &lt;td&gt;Gemma 4 2B&lt;/td&gt;
          &lt;td&gt;2B&lt;/td&gt;
          &lt;td&gt;Ultra-lightweight&lt;/td&gt;
          &lt;td&gt;Low latency, low resource usage, lowest deployment barrier&lt;/td&gt;
          &lt;td&gt;Limited performance on complex reasoning and long task chains&lt;/td&gt;
          &lt;td&gt;Mobile, IoT, lightweight Q&amp;amp;A, simple automation&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Gemma 4 4B&lt;/td&gt;
          &lt;td&gt;4B&lt;/td&gt;
          &lt;td&gt;Lightweight enhanced&lt;/td&gt;
          &lt;td&gt;Stronger understanding and generation than 2B, still easy to deploy locally&lt;/td&gt;
          &lt;td&gt;Limited ceiling for heavy coding and complex agent tasks&lt;/td&gt;
          &lt;td&gt;Local assistant, basic document work, multilingual daily tasks&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Gemma 4 26B&lt;/td&gt;
          &lt;td&gt;26B&lt;/td&gt;
          &lt;td&gt;High-performance (MoE)&lt;/td&gt;
          &lt;td&gt;Better reasoning and tool use, suitable for production workflows&lt;/td&gt;
          &lt;td&gt;Significantly higher VRAM requirement and hardware threshold&lt;/td&gt;
          &lt;td&gt;Coding assistant, complex workflows, enterprise internal agents&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Gemma 4 31B&lt;/td&gt;
          &lt;td&gt;31B&lt;/td&gt;
          &lt;td&gt;High-performance (dense)&lt;/td&gt;
          &lt;td&gt;Best overall capability and stronger stability on complex tasks&lt;/td&gt;
          &lt;td&gt;Highest resource cost and tuning complexity&lt;/td&gt;
          &lt;td&gt;Advanced reasoning, complex coding tasks, heavy automation&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&#34;how-to-choose-start-from-hardware-and-tasks&#34;&gt;How to Choose: Start from Hardware and Tasks
&lt;/h2&gt;&lt;p&gt;If your top concern is whether it runs smoothly, use this guideline:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;8GB&lt;/code&gt; VRAM: prioritize &lt;code&gt;2B/4B&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;12GB&lt;/code&gt; VRAM: prioritize &lt;code&gt;4B&lt;/code&gt; or quantized variants of larger models.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;24GB&lt;/code&gt; VRAM: focus on &lt;code&gt;26B&lt;/code&gt;, and evaluate quantized &lt;code&gt;31B&lt;/code&gt; based on workload.&lt;/li&gt;
&lt;li&gt;Higher VRAM or multi-GPU: consider high-precision &lt;code&gt;31B&lt;/code&gt; setups.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Prioritize stability and inference speed first, then scale up model size gradually.&lt;/p&gt;
&lt;h2 id=&#34;four-typical-use-cases&#34;&gt;Four Typical Use Cases
&lt;/h2&gt;&lt;h3 id=&#34;1-local-general-assistant&#34;&gt;1) Local General Assistant
&lt;/h3&gt;&lt;ul&gt;
&lt;li&gt;Preferred model: &lt;code&gt;4B&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Why: strong balance between cost and quality, suitable for long-running local use.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;2-coding-and-automation&#34;&gt;2) Coding and Automation
&lt;/h3&gt;&lt;ul&gt;
&lt;li&gt;Preferred model: &lt;code&gt;26B&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Why: more stable in multi-step tasks, tool calls, and script generation.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;3-advanced-reasoning-and-complex-agents&#34;&gt;3) Advanced Reasoning and Complex Agents
&lt;/h3&gt;&lt;ul&gt;
&lt;li&gt;Preferred model: &lt;code&gt;31B&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Why: stronger robustness under complex context.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;4-edge-devices-and-lightweight-offline-use&#34;&gt;4) Edge Devices and Lightweight Offline Use
&lt;/h3&gt;&lt;ul&gt;
&lt;li&gt;Preferred model: &lt;code&gt;2B&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Why: easiest to deploy on resource-constrained devices.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;deployment-suggestions-ollama&#34;&gt;Deployment Suggestions (Ollama)
&lt;/h2&gt;&lt;p&gt;A practical approach is to iterate in small steps:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Start with &lt;code&gt;4B&lt;/code&gt; to establish a baseline (latency, memory, quality).&lt;/li&gt;
&lt;li&gt;Build a fixed test set from real tasks (for example, 20 common questions + 10 automation tasks).&lt;/li&gt;
&lt;li&gt;Compare &lt;code&gt;26B/31B&lt;/code&gt; against that set for accuracy, latency, and VRAM cost.&lt;/li&gt;
&lt;li&gt;Upgrade only when the gain is clear.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;This avoids jumping to a large model too early and running into lag, low throughput, and maintenance overhead.&lt;/p&gt;
&lt;h2 id=&#34;conclusion&#34;&gt;Conclusion
&lt;/h2&gt;&lt;p&gt;The real value of Gemma 4 is not just larger parameter counts, but a practical model ladder from lightweight to high-performance:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;For low-cost fast rollout: start with &lt;code&gt;2B/4B&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;For production-grade local AI workflows: prioritize &lt;code&gt;26B&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;For advanced reasoning and heavy automation: move to &lt;code&gt;31B&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In most cases, the best Gemma 4 choice is not the biggest model, but the one with the best fit for your hardware and task goals.&lt;/p&gt;
</description>
        </item>
        <item>
        <title>Analyzing Anthropic&#39;s docx Agent Skill: Features, Code Structure, Usage, and Caveats</title>
        <link>https://www.knightli.com/en/2026/04/04/analyze-docx-agent-skill/</link>
        <pubDate>Sat, 04 Apr 2026 11:00:00 +0800</pubDate>
        
        <guid>https://www.knightli.com/en/2026/04/04/analyze-docx-agent-skill/</guid>
        <description>&lt;p&gt;Anthropic&amp;rsquo;s &lt;code&gt;skills/docx&lt;/code&gt; is essentially a workflow spec plus a script toolkit for handling Word documents more reliably with AI.&lt;br&gt;
It does not just tell a model to &amp;ldquo;generate a &lt;code&gt;.docx&lt;/code&gt;.&amp;rdquo; Instead, it breaks document work into explicit paths: create, read, edit existing files, handle tracked changes, add comments, convert formats, and validate OOXML structure.&lt;/p&gt;
&lt;p&gt;If we reduce it to one line:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;It treats &lt;code&gt;.docx&lt;/code&gt; as ZIP + XML + Office compatibility constraints, not as a black box.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&#34;what-this-skill-solves&#34;&gt;What this skill solves
&lt;/h2&gt;&lt;p&gt;When general-purpose models handle Word files, we often see the same failure patterns:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;They output text, but not a structurally valid &lt;code&gt;.docx&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;They break OOXML while editing existing documents.&lt;/li&gt;
&lt;li&gt;They do not know which XML parts to update for comments or tracked changes.&lt;/li&gt;
&lt;li&gt;Output opens in one app but behaves inconsistently across Word, LibreOffice, and Google Docs.&lt;/li&gt;
&lt;li&gt;They lack clear routing for when to use &lt;code&gt;pandoc&lt;/code&gt; vs. unpack/edit/repack.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The value of this skill is that it front-loads those decisions:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;pandoc&lt;/code&gt; or unpacking for reading and analysis.&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;docx-js&lt;/code&gt; for creating new &lt;code&gt;.docx&lt;/code&gt; files.&lt;/li&gt;
&lt;li&gt;Use &amp;ldquo;unpack -&amp;gt; edit XML -&amp;gt; repack -&amp;gt; validate&amp;rdquo; for existing documents.&lt;/li&gt;
&lt;li&gt;Use dedicated scripts for tracked changes/comments/schema-sensitive operations.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;That approach works because Word problems are usually not about wording quality. They are about structural correctness and compatibility.&lt;/p&gt;
&lt;h2 id=&#34;directory-and-code-structure&#34;&gt;Directory and code structure
&lt;/h2&gt;&lt;p&gt;This skill can be understood in four layers.&lt;/p&gt;
&lt;h3 id=&#34;1-guidance-layer-skillmd&#34;&gt;1. Guidance layer: &lt;code&gt;SKILL.md&lt;/code&gt;
&lt;/h3&gt;&lt;p&gt;&lt;code&gt;SKILL.md&lt;/code&gt; does two important jobs:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;It defines trigger conditions.&lt;br&gt;
If a request mentions Word, &lt;code&gt;.docx&lt;/code&gt;, comments, tracked changes, TOC, page numbers, or polished document formatting, this skill should be activated.&lt;/li&gt;
&lt;li&gt;It defines execution routes.&lt;br&gt;
Different task types map to different toolchains, instead of improvising every run.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;It also captures practical compatibility rules, for example:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;docx-js&lt;/code&gt; defaults to A4, not US Letter.&lt;/li&gt;
&lt;li&gt;Landscape page sizing must follow &lt;code&gt;docx-js&lt;/code&gt; internals.&lt;/li&gt;
&lt;li&gt;Lists should not be built from manual Unicode bullets.&lt;/li&gt;
&lt;li&gt;Table width needs coordinated settings at table and cell levels.&lt;/li&gt;
&lt;li&gt;Image &lt;code&gt;type&lt;/code&gt; is required.&lt;/li&gt;
&lt;li&gt;Generated files should be validated.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;That is a strong signal that the goal is not just &amp;ldquo;generate something,&amp;rdquo; but &amp;ldquo;generate something that is robust.&amp;rdquo;&lt;/p&gt;
&lt;h2 id=&#34;2-office-package-layer-scriptsoffice&#34;&gt;2. Office package layer: &lt;code&gt;scripts/office/*&lt;/code&gt;
&lt;/h2&gt;&lt;p&gt;This layer treats &lt;code&gt;.docx/.pptx/.xlsx&lt;/code&gt; as Open XML packages.&lt;/p&gt;
&lt;h3 id=&#34;unpackpy&#34;&gt;&lt;code&gt;unpack.py&lt;/code&gt;
&lt;/h3&gt;&lt;p&gt;This script unpacks files and prepares XML for safer editing:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Extracts ZIP package content&lt;/li&gt;
&lt;li&gt;Pretty-prints XML and &lt;code&gt;.rels&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Optionally runs &lt;code&gt;merge_runs&lt;/code&gt; for DOCX&lt;/li&gt;
&lt;li&gt;Optionally runs &lt;code&gt;simplify_redlines&lt;/code&gt; for DOCX&lt;/li&gt;
&lt;li&gt;Escapes smart quotes into XML entities&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So it is not just decompression. It normalizes content into an editing-friendly shape.&lt;/p&gt;
&lt;h3 id=&#34;packpy&#34;&gt;&lt;code&gt;pack.py&lt;/code&gt;
&lt;/h3&gt;&lt;p&gt;This script repacks a directory into &lt;code&gt;.docx/.pptx/.xlsx&lt;/code&gt;.&lt;br&gt;
Before packaging, it can:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Run validation and auto-repair&lt;/li&gt;
&lt;li&gt;Condense XML formatting safely&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If &lt;code&gt;--original&lt;/code&gt; is provided, it compares and validates against the source context.&lt;br&gt;
That matters because &amp;ldquo;repacked successfully&amp;rdquo; is not equal to &amp;ldquo;semantically safe.&amp;rdquo;&lt;/p&gt;
&lt;h3 id=&#34;validatepy&#34;&gt;&lt;code&gt;validate.py&lt;/code&gt;
&lt;/h3&gt;&lt;p&gt;This is the quality gate. It checks:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;XML well-formedness&lt;/li&gt;
&lt;li&gt;Namespace correctness&lt;/li&gt;
&lt;li&gt;Unique ID constraints&lt;/li&gt;
&lt;li&gt;Relationship/content type consistency&lt;/li&gt;
&lt;li&gt;XSD compliance&lt;/li&gt;
&lt;li&gt;Whitespace preservation rules&lt;/li&gt;
&lt;li&gt;Insertion/deletion/comment marker constraints&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For DOCX work, this is a core component, not an optional extra.&lt;/p&gt;
&lt;h3 id=&#34;sofficepy&#34;&gt;&lt;code&gt;soffice.py&lt;/code&gt;
&lt;/h3&gt;&lt;p&gt;This helper wraps LibreOffice execution for restricted/sandboxed environments.&lt;br&gt;
It configures &lt;code&gt;SAL_USE_VCLPLUGIN=svp&lt;/code&gt; and can apply a shim for AF_UNIX socket limitations when needed.&lt;/p&gt;
&lt;p&gt;That tells us the skill is designed for automated agent workflows, not only local manual usage.&lt;/p&gt;
&lt;h2 id=&#34;3-word-specific-layer-comments-revisions-and-redlines&#34;&gt;3. Word-specific layer: comments, revisions, and redlines
&lt;/h2&gt;&lt;h3 id=&#34;commentpy&#34;&gt;&lt;code&gt;comment.py&lt;/code&gt;
&lt;/h3&gt;&lt;p&gt;This script adds comments to DOCX, including required package plumbing across multiple parts:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;word/comments.xml&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;commentsExtended.xml&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;commentsIds.xml&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;commentsExtensible.xml&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;comment range markers in &lt;code&gt;document.xml&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;declarations in &lt;code&gt;[Content_Types].xml&lt;/code&gt; and &lt;code&gt;document.xml.rels&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If comment parts do not exist yet, it can initialize templates and required relationships/content types.&lt;/p&gt;
&lt;h3 id=&#34;accept_changespy&#34;&gt;&lt;code&gt;accept_changes.py&lt;/code&gt;
&lt;/h3&gt;&lt;p&gt;This script accepts all tracked changes via LibreOffice headless + macro (&lt;code&gt;.uno:AcceptAllTrackedChanges&lt;/code&gt;) rather than fragile raw XML surgery.&lt;/p&gt;
&lt;p&gt;That is a pragmatic choice because accepting revisions is a behavior-level operation, not just deleting &lt;code&gt;&amp;lt;w:ins&amp;gt;&lt;/code&gt; / &lt;code&gt;&amp;lt;w:del&amp;gt;&lt;/code&gt; tags.&lt;/p&gt;
&lt;h3 id=&#34;validatorsredliningpy&#34;&gt;&lt;code&gt;validators/redlining.py&lt;/code&gt;
&lt;/h3&gt;&lt;p&gt;This is one of the most valuable pieces.&lt;br&gt;
It removes tracked changes for a specific author in both original and modified documents, then compares resulting text to verify that changes are properly represented in revision markup.&lt;/p&gt;
&lt;p&gt;So it validates revision semantics, not only XML syntax.&lt;/p&gt;
&lt;h2 id=&#34;4-schema-and-support-layer-schemas-helpers-templates&#34;&gt;4. Schema and support layer: &lt;code&gt;schemas/&lt;/code&gt;, &lt;code&gt;helpers/&lt;/code&gt;, &lt;code&gt;templates/&lt;/code&gt;
&lt;/h2&gt;&lt;h3 id=&#34;schemas&#34;&gt;&lt;code&gt;schemas/&lt;/code&gt;
&lt;/h3&gt;&lt;p&gt;Contains OOXML/ECMA/Microsoft-related XSD files used by validators.&lt;br&gt;
Validation is therefore grounded in formal schema constraints.&lt;/p&gt;
&lt;h3 id=&#34;helpers&#34;&gt;&lt;code&gt;helpers/&lt;/code&gt;
&lt;/h3&gt;&lt;p&gt;Includes utilities such as:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;merge_runs.py&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;simplify_redlines.py&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;These stabilize XML structure for clearer edits and diffs.&lt;/p&gt;
&lt;h3 id=&#34;templates&#34;&gt;&lt;code&gt;templates/&lt;/code&gt;
&lt;/h3&gt;&lt;p&gt;Contains XML templates needed for comment support, including:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;comments.xml&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;commentsExtended.xml&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;commentsIds.xml&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;commentsExtensible.xml&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;people.xml&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;These templates help avoid package-level inconsistencies when creating comment-related parts.&lt;/p&gt;
&lt;h2 id=&#34;typical-usage-patterns&#34;&gt;Typical usage patterns
&lt;/h2&gt;&lt;p&gt;From &lt;code&gt;SKILL.md&lt;/code&gt;, the most common workflows are:&lt;/p&gt;
&lt;h2 id=&#34;scenario-1-readanalyze-an-existing-docx&#34;&gt;Scenario 1: Read/analyze an existing DOCX
&lt;/h2&gt;&lt;p&gt;Use &lt;code&gt;pandoc&lt;/code&gt; for text-level extraction with tracked changes:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;pandoc --track-changes&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;all document.docx -o output.md
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;Use unpacking for raw XML inspection:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;python scripts/office/unpack.py document.docx unpacked/
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;h2 id=&#34;scenario-2-create-a-new-docx&#34;&gt;Scenario 2: Create a new DOCX
&lt;/h2&gt;&lt;p&gt;Use &lt;code&gt;docx-js&lt;/code&gt; for generation:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;npm install -g docx
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;Then validate:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;python scripts/office/validate.py doc.docx
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;h2 id=&#34;scenario-3-edit-an-existing-docx&#34;&gt;Scenario 3: Edit an existing DOCX
&lt;/h2&gt;&lt;p&gt;Core workflow:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;2
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;3
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;python scripts/office/unpack.py document.docx unpacked/
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# edit XML under unpacked/&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;python scripts/office/pack.py unpacked/ output.docx --original document.docx
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;&lt;code&gt;--original&lt;/code&gt; is the critical part because it enables stronger structural and revision-aware checks.&lt;/p&gt;
&lt;h2 id=&#34;scenario-4-accept-all-tracked-changes&#34;&gt;Scenario 4: Accept all tracked changes
&lt;/h2&gt;&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;python scripts/accept_changes.py input.docx output.docx
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;Requires LibreOffice; useful for producing a clean post-review file.&lt;/p&gt;
&lt;h2 id=&#34;scenario-5-add-comments&#34;&gt;Scenario 5: Add comments
&lt;/h2&gt;&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;2
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;python comment.py unpacked/ &lt;span class=&#34;m&#34;&gt;0&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;Comment text&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;python comment.py unpacked/ &lt;span class=&#34;m&#34;&gt;1&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;Reply text&amp;#34;&lt;/span&gt; --parent &lt;span class=&#34;m&#34;&gt;0&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;You still need to place comment range markers in &lt;code&gt;document.xml&lt;/code&gt; where the comment should attach.&lt;/p&gt;
&lt;h2 id=&#34;key-caveats-to-remember&#34;&gt;Key caveats to remember
&lt;/h2&gt;&lt;h3 id=&#34;1-docx-is-not-a-plain-text-file&#34;&gt;1. &lt;code&gt;.docx&lt;/code&gt; is not a plain text file
&lt;/h3&gt;&lt;p&gt;A single edit may involve body XML, relationships, content types, comment parts, IDs, and schema constraints.&lt;/p&gt;
&lt;h3 id=&#34;2-docx-js-generation-still-needs-explicit-guardrails&#34;&gt;2. &lt;code&gt;docx-js&lt;/code&gt; generation still needs explicit guardrails
&lt;/h3&gt;&lt;p&gt;Defaults can be wrong for your target layout and compatibility goals.&lt;/p&gt;
&lt;h3 id=&#34;3-comments-and-tracked-changes-are-multi-part-operations&#34;&gt;3. Comments and tracked changes are multi-part operations
&lt;/h3&gt;&lt;p&gt;They are package-level features, not single-tag edits.&lt;/p&gt;
&lt;h3 id=&#34;4-opens-successfully-does-not-mean-correctly-modified&#34;&gt;4. &amp;ldquo;Opens successfully&amp;rdquo; does not mean &amp;ldquo;correctly modified&amp;rdquo;
&lt;/h3&gt;&lt;p&gt;Many issues only surface later during editing, reviewing, cross-app opening, or acceptance of changes.&lt;/p&gt;
&lt;h3 id=&#34;5-environment-readiness-matters&#34;&gt;5. Environment readiness matters
&lt;/h3&gt;&lt;p&gt;You need tools such as &lt;code&gt;pandoc&lt;/code&gt;, &lt;code&gt;LibreOffice/soffice&lt;/code&gt;, &lt;code&gt;docx-js&lt;/code&gt;, and Python deps (&lt;code&gt;defusedxml&lt;/code&gt;, &lt;code&gt;lxml&lt;/code&gt;) available.&lt;/p&gt;
&lt;h2 id=&#34;what-this-skill-is-good-for-and-not&#34;&gt;What this skill is good for (and not)
&lt;/h2&gt;&lt;h3 id=&#34;good-fit&#34;&gt;Good fit
&lt;/h3&gt;&lt;ul&gt;
&lt;li&gt;Batch Word report generation&lt;/li&gt;
&lt;li&gt;Structured formal document production&lt;/li&gt;
&lt;li&gt;Automated edits to existing &lt;code&gt;.docx&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Tracked-changes aware workflows&lt;/li&gt;
&lt;li&gt;Automated comment insertion&lt;/li&gt;
&lt;li&gt;Agent/script-driven document pipelines&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;not-ideal&#34;&gt;Not ideal
&lt;/h3&gt;&lt;ul&gt;
&lt;li&gt;Very simple PDF-only output cases&lt;/li&gt;
&lt;li&gt;Pure text extraction with no document fidelity requirement&lt;/li&gt;
&lt;li&gt;Fully manual visual editing workflows&lt;/li&gt;
&lt;li&gt;Zero-dependency expectations for end-to-end Word automation&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;summary&#34;&gt;Summary
&lt;/h2&gt;&lt;p&gt;Anthropic&amp;rsquo;s &lt;code&gt;skills/docx&lt;/code&gt; is strong not because it can &amp;ldquo;generate Word files,&amp;rdquo; but because it encodes why Word automation fails and how to handle those failure modes systematically.&lt;br&gt;
It combines generation, low-level XML editing, revision semantics, schema validation, and cross-app compatibility into one executable workflow.&lt;/p&gt;
&lt;p&gt;If your use case includes existing DOCX edits, comments, tracked changes, or compatibility-sensitive automation, this design is very practical and high value.&lt;/p&gt;
&lt;p&gt;Code location: &lt;a class=&#34;link&#34; href=&#34;https://github.com/anthropics/skills/tree/main/skills/docx&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;https://github.com/anthropics/skills/tree/main/skills/docx&lt;/a&gt;&lt;/p&gt;
</description>
        </item>
        
    </channel>
</rss>
