insert_field
Insert a Word field after specified anchor text, with safe-code validation, placeholder, and automatic backup. Adds dynamic fields like DATE, PAGE, or SEQ to .docx files.
Instructions
Insert a generic Word field right after after_anchor text (plain
paragraph text, literal characters, not XML entities; occurrence picks
which match when the anchor appears more than once). field_code
examples: 'DATE', 'TIME @ "HH:mm"', 'FILENAME', 'NUMPAGES', 'PAGE',
'SEQ Exhibit * Arabic'. Codes are validated against an allowlist of
known-safe fields (document info, page/date/time numbers, SEQ);
anything that links out or executes is refused, naming the allowlist.
The field is written dirty so Word computes the result on the next
refresh; placeholder shows until then. Auto-backup: prev/anchor
slots in .ks4w-backups (backup=False skips rotation only); atomic
validated save. Refuses documents open in Word.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| backup | No | ||
| file_path | Yes | ||
| field_code | Yes | ||
| occurrence | No | ||
| placeholder | No | ||
| after_anchor | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||