Skip to main content

Data & Message

In Langflow, the Data and Message objects serve as structured, functional representations of data that enhance the capabilities and reliability of the platform.

The Data Object


The Data object is a Pydantic model that serves as a container for storing and manipulating data. It carries data—a dictionary that can be accessed as attributes—and uses text_key to specify which key in the dictionary should be considered the primary text content.

  • Main Attributes:
    • text_key: Specifies the key to retrieve the primary text data.
    • data: A dictionary to store additional data.
    • default_value: default value when the text_key is not present in the data dictionary.

Creating a Data Object

You can create a Data object by directly assigning key-value pairs to it. For example:


_10
from langflow.schema import Data
_10
_10
# Creating a Data object with specified key-value pairs
_10
data = Data(text="my_string", bar=3, foo="another_string")
_10
_10
# Outputs:
_10
print(data.text) # Outputs: "my_string"
_10
print(data.bar) # Outputs: 3
_10
print(data.foo) # Outputs: "another_string"

The text_key specifies which key in the data dictionary should be considered the primary text content. The default_value provides a fallback if the text_key is not present.


_10
# Creating a Data object with a specific text_key and default_value
_10
data = Data(data={"title": "Hello, World!"}, text_key="content", default_value="No content available")
_10
_10
# Accessing the primary text using text_key and default_value
_10
print(data.get_text()) # Outputs: "No content available" because "content" key is not in the data dictionary
_10
_10
# Accessing data keys by calling the attribute directly
_10
print(data.title) # Outputs: "Hello, World!" because "title" key is in the data dictionary

The Data object is also convenient for visualization of outputs, since the output preview has visual elements to inspect data as a table and its cells as pop ups for basic types. The idea is to create a unified way to work and visualize complex information in Langflow.

To receive Data objects in a component input, you can use the DataInput input type.

Message object attributes


The Message object extends the functionality of Data and includes additional attributes and methods for chat interactions.

  • Core message data:

    • text: The main text content of the message
    • sender: Identifier for the sender (e.g., "User" or "AI")
    • sender_name: Name of the sender
    • session_id: Identifier for the chat session
    • timestamp: Timestamp when the message was created (UTC)
    • flow_id: Identifier for the flow
    • id: Unique identifier for the message
  • Content and files:

    • files: List of files or images associated with the message
    • content_blocks: List of structured content blocks
    • properties: Additional properties including visual styling and source information
  • Message state:

    • error: Boolean indicating if there was an error
    • edit: Boolean indicating if the message was edited
    • category: Message category ("message", "error", "warning", "info")

The Message object can be used to send, store, and manipulate chat messages within Langflow. You can create a Message object by directly assigning key-value pairs to it. For example:


_10
from langflow.schema.message import Message
_10
_10
message = Message(text="Hello, AI!", sender="User", sender_name="John Doe")

To receive Message objects in a component input, you can use the MessageInput input type or MessageTextInput when the goal is to extract just the text field of the Message object.

Hi, how can I help you?