Back to Langflow

Text Operations

docs/versioned_docs/version-1.9.0/Components/text-operations.mdx

1.10.0.dev416.6 KB
Original Source

import Icon from "@site/src/components/icon"; import PartialParams from '@site/docs/_partial-hidden-params.mdx';

The Text Operations component performs operations on text strings.

The output type depends on the selected operation: most operations return a Message, Word Count returns a JSON object, and Text to DataFrame returns a Table.

Use the Text Operations component in a flow

The following example demonstrates how to use a Text Operations component to clean text output from a language model before passing it to another component:

  1. Create a flow with a Language Model component and a Text Operations component, and then connect the Language Model component's Message output to the Text Operations component's Text Input.

    All operations in the Text Operations component require a text string as input. If the preceding component doesn't produce Message or text output, you can use the Type Convert component to reformat the data first.

  2. In the Operation field, select the operation you want to perform. For this example, select Text Clean.

    :::tip You can select only one operation. If you need to perform multiple operations, chain multiple Text Operations components together to execute each operation in sequence. :::

  3. Configure the operation's parameters. For this example, enable Remove Extra Spaces and Remove Empty Lines to normalize the model's output.

  4. Optional: Connect the output to a Chat Output component to view the result in the Playground.

  5. Click <Icon name="Play" aria-hidden="true" /> Run component on the Text Operations component, and then click <Icon name="TextSearch" aria-hidden="true" /> Inspect output to view the result.

Text Operations parameters

Many parameters are conditional based on the selected Operation (operation).

<PartialParams />
NameDisplay NameInfo
text_inputText InputInput parameter. The text string to process. Required for all operations.
operationOperationInput parameter. The operation to perform on the text. See Available text operations.
case_typeCase TypeInput parameter. The case conversion to apply. Options: uppercase, lowercase, title, capitalize, swapcase. Default: lowercase. Only shown for Case Conversion.
search_patternSearch PatternInput parameter. The text or regex pattern to find. Only shown for Text Replace.
replacement_textReplacement TextInput parameter. The text to substitute for each match. Only shown for Text Replace.
use_regexUse RegexInput parameter. If enabled, treats Search Pattern as a regular expression. Default: Disabled. Only shown for Text Replace.
extract_patternExtract PatternInput parameter. The regular expression pattern to match against the text. Only shown for Text Extract.
max_matchesMax MatchesInput parameter. Maximum number of matches to return. Default: 10. Only shown for Text Extract.
head_charactersCharacters from StartInput parameter. Number of characters to return from the beginning of the text. Must be non-negative. Default: 100. Only shown for Text Head.
tail_charactersCharacters from EndInput parameter. Number of characters to return from the end of the text. Must be non-negative. Default: 100. Only shown for Text Tail.
strip_modeStrip ModeInput parameter. Which side(s) of the text to strip. Options: both (default), left, right. Only shown for Text Strip.
strip_charactersCharacters to StripInput parameter. Specific characters to remove. Leave empty to strip whitespace. Only shown for Text Strip.
text_input_2Second Text InputInput parameter. The second text string to join with the first. Only shown for Text Join.
remove_extra_spacesRemove Extra SpacesInput parameter. Collapse multiple consecutive spaces into a single space. Default: Enabled. Only shown for Text Clean.
remove_special_charsRemove Special CharactersInput parameter. Remove all characters except alphanumeric and spaces. Default: Disabled. Only shown for Text Clean.
remove_empty_linesRemove Empty LinesInput parameter. Remove blank lines from the text. Default: Disabled. Only shown for Text Clean.
table_separatorTable SeparatorInput parameter. The character used to delimit columns. Default: |. Only shown for Text to DataFrame.
has_headerHas HeaderInput parameter. Whether the first row is a header row. Default: Enabled. Only shown for Text to DataFrame.
count_wordsCount WordsInput parameter. Include word count and unique word count in the output. Default: Enabled. Only shown for Word Count.
count_charactersCount CharactersInput parameter. Include character count (with and without spaces) in the output. Default: Enabled. Only shown for Word Count.
count_linesCount LinesInput parameter. Include total and non-empty line count in the output. Default: Enabled. Only shown for Word Count.

Available text operations

Options for the operation input parameter are as follows.

NameRequired InputsOutputProcess
Word CountNoneJSONCounts words, unique words, characters, and lines in the text.
Case Conversioncase_typeMessageConverts the text to the specified case.
Text Replacesearch_pattern, replacement_text, use_regexMessageReplaces occurrences of a pattern with replacement text.
Text Extractextract_pattern, max_matchesMessageExtracts all substrings matching a regex pattern, returned as newline-separated text.
Text Headhead_charactersMessageReturns the first n characters of the text.
Text Tailtail_charactersMessageReturns the last n characters of the text.
Text Stripstrip_mode, strip_charactersMessageRemoves whitespace or specified characters from the edges of the text.
Text Jointext_input_2Text, MessageConcatenates two text inputs separated by a newline.
Text Cleanremove_extra_spaces, remove_special_chars, remove_empty_linesMessageNormalizes text by removing extra spaces, special characters, and empty lines.
Text to DataFrametable_separator, has_headerTableConverts a delimiter-separated text table into a Table.

See also