Truncate text shortens a string to a maximum length and appends an ellipsis when content is removed. Agents use this for card previews, log teasers, and fitting snippets into tight context windows before sending full documents to chunking or summarization tools.
How it works
If the input length is within the limit, it is returned unchanged. Otherwise the tool keeps the first maxLength code units of the string, then replaces the final three characters with ... when there is room—so the visible result never exceeds the configured maximum. The ellipsis counts toward the limit, which matches common UI preview patterns.
When to use it
- Fit tool output into UI or notification character limits
- Preview long agent responses in dashboards or chat sidebars
- Build teaser text before calling the chunk-text tool on the full body
- Trim error messages or stack traces for compact logging displays
Example
With max length 8, the phrase hello world becomes hello... (three dots count toward the limit). Shorter inputs like hi pass through without an ellipsis.
Limitations
Counts UTF-16 code units, not grapheme clusters—some emoji or combined marks may split unexpectedly. Max length must be greater than the ellipsis length (3). The tool does not break on word boundaries; use chunk-text for sentence-aware splitting.