Counter

Description

The Counter node analyzes incoming text and outputs a count based on the selected mode: characters, words, lines, or estimated tokens. It is useful for monitoring content length, enforcing size limits before sending to an AI model, or gathering statistics for downstream processing.

When Pass Through is enabled, the original text is sent to the output unchanged, while the count is displayed in the console for monitoring. When disabled, only the numeric count is sent downstream as the node's output.


Configuration Properties

🔢 Count Mode Section

ComboBox
Selects the counting method:

Characters
Counts every character in the input text, including spaces, punctuation, and line breaks. Useful for strict character limits (e.g., SMS, Twitter posts, database field constraints).

Words
Counts words by splitting on whitespace. Consecutive spaces or line breaks are treated as a single separator. Useful for document length estimation, reading time calculation, or billing by word count.

Lines
Counts the number of lines (separated by \n or \r\n). Empty lines are counted. Useful for code analysis, log file processing, or structured text validation.

Tokens (estimation)
Estimates the number of tokens the text would consume when sent to an LLM. The estimation uses a heuristic ratio (typically ~4 characters per token for English, ~2-3 for CJK languages). This is not exact — actual tokenization depends on the model's vocabulary — but it gives a reliable order of magnitude for context budget planning.


📤 Output Mode Section

Pass Through Input Text
When checked, the node sends the original input text to its output unchanged. The count is displayed in the console for monitoring purposes but is NOT sent downstream.
When unchecked, the node sends only the numeric count as its output (e.g., 142).

💡 Tip: Enable Pass Through when you want to preserve the content for downstream nodes while still monitoring the count in the console. Disable it when the count itself is the data you need (e.g., feeding a SwitchNode to check "if token count > 2000").


Usage Example

"Context budget check before AI generation":

  1. A Template node constructs a prompt.
  2. A Counter node with:
    • Count Mode: Tokens (estimation)
    • Pass Through: unchecked
  3. A Switch node checks if the count exceeds 2000:
    • If yes → route to a Summarizer Agent to compress the text.
    • If no → send directly to the Main Agent.

"Display text with word count monitoring":

  1. An Input node receives a long text.
  2. A Counter node with:
    • Count Mode: Words
    • Pass Through: checked
  3. An Output node displays the text, while you can see the word count in the console.

⚠️ Pitfalls to Avoid

Token estimation is approximate: The "Tokens (estimation)" mode uses a simple heuristic, not the actual tokenizer of your model. For precise control, always leave a safety margin (e.g., treat 1800 estimated tokens as "close to 2000 limit").

Empty input returns 0: If no text is connected or the input is empty, the counter outputs 0. This can trigger unexpected branches in a SwitchNode if you're not expecting it.

Pass Through doesn't modify content: When enabled, the text passes through unchanged. The count is only visible in the console, not in the output stream. Don't expect to receive "count\ntext" or any formatted output.

Line counting includes empty lines: If your text ends with a trailing newline (common in copy-paste), the line count may be one higher than expected. Trim the input first if this matters.

Console-only visibility: Remember that with Pass Through enabled, the count is ONLY visible in the console, not in any OutputNode. If you need to display or use the count in your workflow, disable Pass Through and route the count to a separate branch.