All edits operate on an in-memory session. Nothing is written to disk until you call
save.Core editing workflow
1
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.2
Choose a read format
read_file supports three output formats via the format parameter:For agent workflows, use
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.3
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.4
Replace text in a paragraph
Call
replace_text with the paragraph ID, the exact text to replace, and the replacement:If the target text is fragmented across formatting runs, set
normalize_first: true to merge format-identical adjacent runs before searching.5
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.6
Save the output
Call
save to write the result to disk. You can save a clean version, a tracked-changes version, or both: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.

