Safe Docx lets you read, search, and precisely modify existing Word documents without touching their formatting. This guide walks through the core editing workflow.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/UseJunior/safe-docx/llms.txt
Use this file to discover all available pages before exploring further.
All edits operate on an in-memory session. Nothing is written to disk until you call
save.Core editing workflow
Read the file and discover paragraph IDs
Call Each paragraph in the output is tagged with a stable identifier like
read_file with the path to your .docx file. Safe Docx returns the document content annotated with _bk_* paragraph IDs._bk_42 or _bk_p3c. These IDs are your handles for all subsequent edit operations. You must reference them exactly — including the _bk_ prefix.Choose a read format
read_file supports three output formats via the format parameter:| Format | Description |
|---|---|
toon | Compact, token-efficient format designed for agent consumption. Recommended for most workflows. |
json | Structured JSON with full paragraph and run metadata. |
simple | Plain text output with minimal markup. |
toon to minimize token usage:read_file is token-limited to approximately 14k tokens and returns pagination metadata (has_more, next_offset). Use offset and limit to paginate through large documents.Search for specific text
Use
grep to locate paragraphs containing specific terms without reading the entire document:grep returns matching paragraph IDs and surrounding context. You can also search multiple files at once using the file_paths array for stateless multi-file search.Replace text in a paragraph
Call
If the target text is fragmented across formatting runs, set
replace_text with the paragraph ID, the exact text to replace, and the replacement:| Parameter | Required | Description |
|---|---|---|
target_paragraph_id | Yes | The _bk_* ID of the paragraph to edit |
old_string | Yes | Exact text to find in the paragraph |
new_string | Yes | Replacement text |
instruction | Yes | Human-readable description of the change (used in tracked-changes metadata) |
normalize_first: true to merge format-identical adjacent runs before searching.Insert a new paragraph
Use Set
insert_paragraph to add content before or after an existing paragraph:position to "BEFORE" or "AFTER" relative to the anchor paragraph. Use style_source_id to clone paragraph formatting from a different paragraph instead of the anchor.Real agent prompt example
This prompt reliably produces a clean and tracked-changes output:Related guides
Comparing documents
Produce tracked-changes output from two DOCX versions.
Batch editing
Plan and apply batches of edits with multi-agent coordination.

