Text Truncate Node
The Text Truncate node shortens long text to a fixed length. It supports character-based and line-based truncation, making it ideal for keeping LLM replies concise, summarizing logs, or preparing snippets for downstream steps.
Node Configuration
Basic Settings
-
Node Name
- Use an action-oriented name like “Trim AI Reply”
- Output variables inherit the node name prefix, for example
$Trim AI Reply.text
-
Text Source
- Choose a variable from upstream nodes such as
$LLM.output
or$input.content
- Any context variable reference is supported
- Choose a variable from upstream nodes such as
-
Mode
- Characters (default): Truncates based on Unicode character count
- Lines: Splits by newline
\n
and keeps the first N lines
-
Limit
- Accepts zero or any non-negative integer
- A value of 0 outputs an empty string
- The field is required and supports variable references (for example
$settings.limit
)
-
Output Variable
- Defaults to
text
- Downstream nodes read the result using
$NodeName.text
- Defaults to
How It Works
- During execution, the node resolves
$node.field
placeholders across all inputs, including nested paths. - If the limit is empty or invalid, the workflow throws an error to avoid ambiguous results.
- The implements of the truncation logic:
- Characters: Truncates based on Unicode character count, supports emoji, Chinese, etc.
- Lines: Splits on newlines and joins back the first N lines
- After truncation, the node writes the result into context, visible in debug outputs under
$NodeName.text
.
Usage Examples
1. Cap LLM Responses (Characters)
- Insert a Text Truncate node after your LLM node.
- Configure it as follows:
Text: $LLM.outputMode: CharactersLimit: 280
- Pass
$Text Truncate.text
to a Content Combiner or Output node to ensure the reply stays within 280 characters.
2. Show the First Lines of Logs (Lines)
- Fetch multi-line logs via an Input or HTTP node.
- Configure the Text Truncate node:
Text: $Fetch Logs.responseMode: LinesLimit: 5
- Reference
$Text Truncate.text
downstream to display only the first five lines.
Advanced Techniques
- Dynamic Limits: Drive the limit with environment-specific variables, such as
$Config.maxChars
, for flexible policies. - Chained Control: Combine line truncation followed by character truncation when you need structural and length guarantees.
- Fallback Handling: Pair with conditional nodes to provide default messages when truncation yields an empty result.
Best Practices
- Preview Input Size: Use the debugger or Content Combiner to confirm the original length before truncating.
- Clarify Units: Document whether teammates should configure characters or lines to avoid misconfiguration.
- Preprocess Large Text: For extremely long content, preprocess with other nodes (JSON extraction, code execution) before truncating.
- Idempotent Output: Ensure truncated results remain meaningful if the workflow runs multiple times on the same data.