replace_text
Replace a text string in a Google Docs tab by verifying exact matches, setting expected match count, and previewing with dry-run to prevent accidental changes.
Instructions
Replace occurrences of a text string in a Google Doc tab.
Use this tool when you need to make an exact-text substitution in a document tab. Call list_tabs first to get the tab_id, then read_document to confirm the text you want to replace is present as-is.
The tool locates every occurrence of find using a normalization ladder
(exact → curly/straight quote equivalence → NBSP/whitespace collapse →
soft-hyphen strip) and refuses the write if the match count does not equal
expected_matches. This prevents accidental multi-replacement and
duplicate-sentence collapse.
Set dry_run=True to preview the operation without writing; the response
carries applied: false and the matched span information but makes no
API call.
On success the response carries before/after excerpts (±200 chars), the
normalization rung used, pre/post revision IDs, and audit_logged.
Errors are returned as typed envelopes with error_code, message,
diagnostics, and retryable so the caller can act on them precisely:
ZERO_MATCH – find string not found; near-miss span included
MATCH_COUNT_MISMATCH – wrong number of matches; all locations listed
REVISION_CONFLICT – document changed mid-call; re-read and retry
STRUCTURAL_BOUNDARY – match crosses a paragraph boundary
INVALID_INPUT – empty find, or find equals replace
TAB_NOT_FOUND – tab_id not in document; available tabs listed
SUGGESTIONS_PRESENT – tab has pending suggested edits; accept/reject
them in the Docs UI first, then retry (a pending
suggestion makes the write's computed indices
unsafe — see verified writes, below)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| find | Yes | ||
| doc_id | Yes | ||
| tab_id | Yes | ||
| dry_run | No | ||
| replace | Yes | ||
| expected_matches | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||