Replace a text range
replace_rangeReplace a specified range in a Google Doc with new text in one atomic update, keeping the original start style. Use fresh indexes from read_document_text to ensure accurate placement.
Instructions
Replaces the content in [start_index, end_index) with new text — one atomic batchUpdate that deletes the range and inserts at its start, so nothing is lost if either step would fail. Get fresh indexes from read_document_text first: indexes are stale after ANY previous edit. The new text takes the style at start_index. Cannot cut across a table cell boundary or delete a paragraph's final newline together with only part of the next paragraph — the API rejects such ranges. An empty replacement is allowed and equals delete_range.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"document_id": "<document_id>",
"start_index": "<start_index>",
"end_index": "<end_index>",
"text": "<text>"
},
"name": "replace_range"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | The replacement text; empty string just deletes the range. | |
| tab_id | No | Tab to target (from list_tabs). Omit for the first/only tab. | |
| end_index | Yes | End of the range to replace (exclusive). | |
| segment_id | No | Header/footer/footnote segment id (from get_document). Omit for the document body. | |
| document_id | Yes | The document id — the long id from the document URL (docs.google.com/document/d/<documentId>/edit) or from create_document output. | |
| start_index | Yes | Start of the range to replace (inclusive). |