fill_and_save
Apply batch edits to a document template and save or return the result. Use after listing template targets to fill with chatbot-generated content.
Instructions
Apply a batch of edits to the template and write/return the result.
USE WHEN: You have called list_template_targets() and composed an edits list mapping the chatbot's generated content into the right target_ids. DO NOT USE WHEN: You have not yet fetched target_ids and text_hashes from list_template_targets() — fill_and_save will fail validation.
INPUT modes: provide the template via template_path OR
template_b64 + template_filename.
OUTPUT modes: provide output_path (server-side write) OR set
return_output_bytes=True (response includes output_b64). Required
unless dry_run=True. Use bytes when the chatbot is in a different
filesystem than the MCP server.
Each edit dict must include edit_type ("text" | "structural" | "style")
plus the fields required for that type:
text: target_id, expected_text_hash, new_text (+ optional target_kind, reason)
structural: operation, target_id (+ position, text/rows/values, row_index, column_index)
style: target_id (+ any style fields: bold, color, font_size_pt, etc.)
STYLE EDIT TARGETING:
Run-level fields (bold / italic / underline / color / font_size_pt) must
use target_kind='run' against a run target. Paragraph-level fields
(paragraph_align / left_indent_pt / etc.) use target_kind='paragraph'.
Mixing the two raises a clean style_field_target_mismatch response.
BUILT-IN ROBUSTNESS:
Auto-skip of container/child edit conflicts (cell↔paragraph, paragraph↔run). Skipped entries in
skipped_redundant_edits.Pre-check for duplicate target_id.
Output extension validation.
Defensive type coercion (None edits → empty list).
Output format follows the template: DOCX→DOCX, HWP/HWPX→HWPX. PDF input cannot be written back as PDF.
Returns: dict with
status: ok / dry_run_ok / validation_failed / apply_failed / edit_parse_failed / not_found / duplicate_target_id / style_field_target_mismatch / format_requires_java / file_error / permission_error / runtime_error / bad_argument / output_extension_mismatch / format_not_writableoutput_pathORoutput_b64+output_size_bytes(status=ok)length_safe,length_warnings,skipped_redundant_editsrecovery_hint(when status != ok)edits_applied
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| template_path | No | ||
| edits | No | ||
| output_path | No | ||
| dry_run | No | ||
| template_b64 | No | ||
| template_filename | No | ||
| return_output_bytes | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||