Filter

Description

The Filter node processes incoming text line by line and keeps or removes lines based on a pattern match. It is the go-to tool for cleaning up AI outputs, extracting relevant data from logs, or removing unwanted content (headers, footers, empty lines, specific keywords) before further processing.

It supports both simple text matching and full Regular Expressions, and can operate in two modes: keeping lines that match the pattern, or excluding them.


Configuration Properties

🔍 Pattern Section

TextBox
The pattern to search for in each line.

  • If Use Regex is unchecked: the pattern is treated as a literal string (case-sensitive). A line is considered a match if it contains this exact substring.
  • If Use Regex is checked: the pattern is interpreted as a Regular Expression (e.g., ^\d+ to match lines starting with digits, .*error.* for case-insensitive error detection).

⚙️ Options Section

Use Regex
When checked, the Pattern field is interpreted as a Regular Expression. This unlocks powerful matching capabilities (wildcards, anchors, character classes, quantifiers).
When unchecked, the pattern is a simple substring search.

💡 Tip: Use simple text matching for straightforward keyword filtering (faster, easier to read). Switch to Regex only when you need complex patterns like "lines starting with a date" or "lines containing a number followed by a colon".

Keep Matching
When checked, the node keeps only the lines that match the pattern (filtering IN). All non-matching lines are discarded.
When unchecked, the node removes the lines that match the pattern (filtering OUT). All non-matching lines are kept.

💡 Tip: Think of Keep Matching as a "whitelist" mode (only what matches survives) and unchecked as a "blacklist" mode (everything survives except what matches).


Usage Example

"Extract only error lines from a log file":

  1. A File Read node loads a large log file.
  2. A Filter node with:
    • Pattern: ERROR
    • Use Regex: unchecked
    • Keep Matching: checked
  3. An Output node displays only the lines containing "ERROR".

"Remove all empty lines and comments from code":

  1. A File Read node loads a source code file.
  2. A Filter node with:
    • Pattern: ^\s*$|^// (matches empty lines or lines starting with //)
    • Use Regex: checked
    • Keep Matching: unchecked
  3. The output contains only actual code lines.

⚠️ Pitfalls to Avoid

Regex syntax errors: If Use Regex is checked and the pattern is invalid (e.g., unbalanced parentheses, unclosed brackets), the node will fail silently or pass all lines through unchanged. Always test your regex in a tool like regex101.com before using it in TzuFlow.

Case sensitivity: Simple text matching (Use Regex unchecked) is case-sensitive. If you need case-insensitive matching, either use Regex with the (?i) flag (e.g., (?i)error) or ensure your pattern matches the exact case of the input.

Empty output: If your pattern is too restrictive and no lines match (or all lines are excluded), the node will output an empty string. This can cause downstream nodes (like Agent) to fail or produce unexpected results. Always verify your pattern on a small sample first.

Line-by-line processing: The filter operates on individual lines, not on the entire text. If you need to match patterns that span multiple lines (e.g., a block of text between two markers), you will need to use a Code node with custom logic instead.

Performance on large files: Filtering a file with 10,000+ lines using a complex Regex can be slow. For very large files, consider splitting the file first with a Dispatch node and processing chunks in parallel.