Inspect Doc Structure
inspect_doc_structureInspect a Google Doc's structure before editing to identify safe insertion points, existing tables, headers, footers, tabs, and paragraph statistics.
Instructions
Essential tool for finding safe insertion points and understanding document structure.
USE THIS FOR:
Finding the correct index for table insertion
Understanding document layout before making changes
Locating existing tables and their positions
Getting document statistics and complexity info
Inspecting structure of specific tabs
CRITICAL FOR TABLE OPERATIONS: ALWAYS call this BEFORE creating tables to get a safe insertion index.
WHAT THE OUTPUT SHOWS:
total_elements: Number of document elements
total_length: Maximum safe index for insertion
tables: Number of existing tables
table_details: Position and dimensions of each table
headers / footers: Real segment IDs and previews for header/footer editing
tabs: List of available tabs in the document (if no tab_id specified)
empty_paragraphs: newline-only count, excluding existing/suggested object anchors
empty_paragraph_ranges: start/end extents, capped at 100
empty_paragraph_ranges_truncated: whether ranges were omitted
last_paragraph: is_list_item and is_empty, or null if no body paragraphs
Paragraph statistics cover top-level body paragraphs and appear at the top level in basic mode or under "statistics" in detailed mode. Ranges can include required empty paragraphs. Before cleanup, use detailed=true to check adjacent elements, formatting, and object anchors. Preserve the final newline and newlines before tables, tables of contents, or section breaks. The final range has end == total_length and may be omitted by truncation.
WORKFLOW FOR TABLE INSERTION: Step 1: Call this function Step 2: Note the "total_length" value Step 3: Use an index < total_length for table insertion Step 4: Create your table
FORMATTING WORKFLOW: After inserting all text via batch_update_doc with end_of_segment=true, call this tool with detailed=true to get exact start_index and end_index for every paragraph. Use those indices directly in format_text and update_paragraph_style operations in a second batch_update_doc call.
HEADER/FOOTER WORKFLOW: For ordinary header/footer text, use update_doc_headers_footers. If you need low-level segment editing, call this tool first and use the real segment_id values returned under headers/footers. Do not invent IDs.
The detailed output includes elements[].start_index and elements[].end_index with text_preview for each paragraph, making it easy to identify which ranges to format.
SUB-PARAGRAPH FORMATTING: text_preview is truncated to 100 characters by default. To compute the index of a token inside a longer paragraph, pass preview_chars=0 or None for untruncated text, then add the token's UTF-16 offset within that text to the paragraph's start_index (non-BMP characters such as emoji occupy two UTF-16 units).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| tab_id | No | Optional ID of the tab to inspect. If not provided, inspects main document. | |
| detailed | No | Whether to return detailed structure information | |
| document_id | Yes | ID of the document to inspect | |
| preview_chars | No | Maximum characters of paragraph, header and footer text preview. Pass 0 or None for the full text, needed to locate a token inside a paragraph longer than the default 100 characters. | |
| user_google_email | Yes | User's Google email address |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |