Skip to main content

Parser

The Parser component extracts text from structured data (DataFrame or Data) using a template or direct stringification. The output is a Message containing the parsed text.

This is a versatile component for data extraction and manipulation in your flows. For examples of Parser components in flows, see the following:

A flow that uses a Parser component to extract text from a Structured Output component.

Parsing modes

The Parser component has two modes: Parser and Stringify.

In Parser mode, you create a template for text output that can include literal strings and variables for extracted keys.

Use curly braces to define variables anywhere in the template. Variables must match keys in the DataFrame or Data input, such as column names. For example, {name} extracts the value of a name key. For more information about the content and structure of DataFrame and Data objects, see Langflow data types.

If your template includes literal text and variables, you can use double curly braces to escape literal curly braces in the template and prevent interpretation of that text as a variable. For example: This is a template with {{literal text in curly braces}} and a {variable}.

When the flow runs, the Parser component iterates over the input, producing a Message for each parsed item. For example, parsing a DataFrame creates a Message for each row, populated with the unique values from that row.

Employee summary template

This example template extracts employee data into a natural language summary about an employee's hire date and current role:


_10
{employee_first_name} {employee_last_name} was hired on {start_date}.
_10
Their current position is {job_title} ({grade}).

The resulting Message output replaces the variables with the corresponding extracted values. For example:


_10
Renlo Kai was hired on 11-July-2017.
_10
Their current position is Software Engineer (Principal).

Employee profile template

This example template uses Markdown syntax and extracted employee data to create an employee profile:


_10
# Employee Profile
_10
## Personal Information
_10
- **Name:** {name}
_10
- **ID:** {id}
_10
- **Email:** {email}

When the flow runs, the Parser component iterates over each row of the DataFrame, populating the template's variables with the appropriate extracted values. The resulting text for each row is output as a Message.

The following parameters are available in Parser mode.

Some parameters are hidden by default in the visual editor. You can modify all parameters through the Controls in the component's header menu.

NameDisplay NameInfo
input_dataData or DataFrameInput parameter. The Data or DataFrame input to parse.
patternTemplateInput parameter. The formatting template using plaintext and variables for keys ({KEY_NAME}). See the preceding examples for more information.
sepSeparatorInput parameter. A string defining the separator for rows or lines. Default: \n (new line).
clean_dataClean DataWhether to remove empty rows and lines in each cell or key of the DataFrame or Data input. Default: Enabled (true)

Test and troubleshoot parsed text

To test the Parser component, click Run component, and then click Inspect output to see the Message output with the parsed text. You can also connect a Chat Output component if you want to view the output in the Playground.

If the Message output from the Parser component has empty or unexpected values, there might be a mapping error between the input and the parsing mode, the input has empty values, or the input isn't suitable for plaintext extraction.

For example, assume you use the following template to parse a DataFrame:


_10
{employee_first_name} {employee_last_name} is a {job_title} ({grade}).

The following Message could result from parsing a row where employee_first_name was empty and grade was null:


_10
Smith is a Software Engineer (null).

To troubleshoot missing or unexpected values, you can do the following:

  • Make sure the variables in your template map to keys in the incoming Data or DataFrame. To see the data being passed directly to the Parser component, click Inspect output on the component that is sending data to the Parser component.

  • Check the source data for missing or incorrect values. There are several ways you can address these inconsistencies:

Search