Langflow 数据类型
Langflow 组件被设计为接受和产生特定类型的输入和输出。 输入和输出数据类型定义了组件间信息的结构和流向。 理解这些结构有助于您构建提供有效输入并正确预期输出格式的应用程序。
组件端口表示每个组件可以发送和接收的数据类型。 某些数据类型从它们所附加的字段中就很明显;例如,System Message 字段接受消息数据。 端口颜色也表示端口的数据类型。 例如 Data 端口,由 表示,可以接受或发出结构化数据对象。
构建 flow 时,将输出端口连接到相同类型(颜色)的输入端口,以在两个组件之间传输该类型的数据。
-
在可视化编辑器中,将鼠标悬停在端口上可查看该端口 的连接详细信息。
-
点击端口可按兼容组件过滤 Components 菜单。
-
如果两个组件具有不兼容的数据类型,您可以使用像 Type Convert 组件 这样的处理组件来在组件之间转换数据。
Data
Data 端口 接受或产生 Data
类型,这是一个结构化数据对象,就像您可能发送到 API 的 JSON 载荷。
此数据类型用于在组件之间传递键值对,如用户配置文件、设置或其他结构化信息。
Data
对象包括一个主要文本字段(由 text_key
指示)和附加元数据。
模式和属性
模式在 data.py
中定义。
以下属性可用:
data
: 存储键值对的字典。text_key
:data
中被认为是主要文本值的键。default_value
: 如果text_key
缺失的回退值。默认text_key
是"text"
。
数据结构
Data
对象在 .data
属性中存储键值对,其中每个键都是字段名,其值可以是任何支持的数据类型。text_key
告诉 Langflow 数据字典中的哪个键是该对象的主要文本值。
_10data_obj = Data(_10 text_key="text", # Field 1_10 data={ # Field 2 (the actual dict)_10 "text": "Hello world",_10 "name": "Charlie",_10 "age": 28_10 },_10 default_value="" # Field 3_10)
Data
objects can be serialized to JSON, created from JSON, or created from other dictionary data.
However, the resulting Data
object is a structured object with validation and methods, not a plain dictionary.
For example, when serialized into JSON, the previous example becomes the following JSON object:
_10{_10 "text_key": "text",_10 "data": {_10 "text": "User Profile",_10 "name": "Charlie Lastname",_10 "age": 28,_10 "email": "charlie.lastname@example.com"_10 },_10 "default_value": ""_10}
DataFrame
DataFrame ports accept or produce pandas DataFrames, which are similar to the tabular CSV data.
Use the DataFrame
type to work with data containing multiple rows or records.
Schema and attributes
The schema is defined in dataframe.py
.
The following attributes are available:
-
Full pandas compatibility: All pandas DataFrame methods and functionality are supported
-
Langflow integration: Accepts lists of
Data
objects, dictionaries, or existing DataFrames. -
Convenience methods:
to_data_list()
add_row()
add_rows()
to_lc_documents()
to_data()
to_message()
-
Text key support: Maintains
text_key
anddefault_value
attributes forData
object compatibility.
DataFrame structure
A DataFrame has a tabular data structure with rows and columns. Keys are columns, and each object in the array is a row.
_12[_12 {_12 "name": "Charlie Lastname",_12 "age": 28,_12 "email": "charlie.lastname@example.com"_12 },_12 {_12 "name": "Alexandra Example",_12 "age": 34,_12 "email": "alexandra@example.com"_12 }_12]
When represented as tabular data, the preceding DataFrame object is structured as follows:
_10| name | age | email |_10|------|-----|-------|_10| Charlie Lastname | 28 | charlie.lastname@example.com |_10| Alexandra Example | 34 | alexandra@example.com |
Embeddings
Embeddings ports emit or ingest vector embeddings to support functions like similarity search.
The Embeddings
data type is used specifically by components that either produce or consume vector embeddings, such as the embedding model components and vector store components.
For example, the Embedding Model component outputs Embeddings
data that you can connect to an Embedding input port on a vector store component.
For information about the underlying Python classes that produce Embeddings
, see the LangChain Embedding models documentation.
LanguageModel
The LanguageModel
type is a specific data type that can be produced by language model components and accepted by components that use an LLM.
When you change a language model component's output type from Model Response to Language Model, the component's output port changes from a Message port to a Language Model port .
Then, you connect the outgoing Language Model port to a Language Model input port on a compatible component, such as a Smart Function component.
For more information about using language model components in flows and toggling LanguageModel
output, see Language Model components.
LanguageModel is an instance of LangChain ChatModel
Because Langflow is built on LangChain, LanguageModel
is actually an instance of a LangChain chat model that uses the configuration parameters set in the originating component.
Often, components produce an instance of an integrated chat model that is designed to support the specific model provider, such as ChatOpenAI
or ChatAnthropic
.
You can inspect the component code to see the specific Chat
instance it produces.
Memory
Memory ports are used to integrate a Message History component with external chat memory storage.
For more information, see the Message History component.
Message
Message ports accept or produce Message
data, which extends the Data
type with additional fields and methods for text input typically used in chat flows.
This data type is used by many components.
Components that accept or produce Message
data may not include all attributes in the incoming or outgoing Message
data.
As long as the data is compatible with the Message
schema, it can be valid.
When building flows, focus on the fields shown on each component in the visual editor, rather than the data types passed between components. The details of a particular data type are often only relevant when you are debugging a flow or component that isn't producing the expected output.
For example, a Chat Input component only requires the content of the Input Text (input_value
) field.
The component then constructs a complete Message
object before passing the data to other components in the flow.
Schema, structure, and attributes
The Message
schema is defined in message.py
.
Some Message
attributes have their own schema definitions, such as content_block.py
.
Message
data is structured as a JSON object.
For example:
_10{_10 "text": "Name: Charlie Lastname, Age: 28, Email: charlie.lastname@example.com",_10 "sender": "User",_10 "sender_name": "Charlie Lastname",_10 "session_id": "some-session-id",_10 "timestamp": "2024-06-01T12:00:00Z",_10 "files": [],_10 "content_blocks": [],_10 "category": "message"_10}
The attributes included in a specific Message
object depend on the context, including the component type, flow activity, and whether the message is a query or response.
Some common attributes include the following:
text
: The main message content.sender
: Identifies the originator of a chat message as eitherUser
orLanguage Model
.sender_name
: The display name for the sender. Defaults toUser
orLanguage Model
.session_id
: The chat session identifier.flow_id
: The ID of the flow that the message is associated with.flow_id
andsession_id
are the same if the flow doesn't use custom session IDs.timestamp
: The UTC timestamp that the message was sent.files
: A list of file paths or images included with the messagecontent_blocks
: Container for rich content input, such as text, media, or code. Also contains error message information if the LLM can't process the input.category
:"message"
,"error"
,"warning"
, or"info"
.
Not all attributes are required, and some components accept message-compatible input, such as raw text input. The strictness depends on the component.
Message data in Input/Output components
In flows with Chat Input/Output components, Message
data provides a consistent structure for chat interactions, and it is ideal for chatbots, conversational analysis, and other use cases based on a dialog with an LLM or agent.
In these flows, the Playground chat interface prints only the Message
attributes that are relevant to the conversation, such as text
, files
, and error messages from content_blocks
.
To see all Message
attributes, inspect the message logs in the Playground.
In flows with Text Input/Output components, Message
data is used to pass simple text strings without the chat-related metadata.
These components handle Message
data as independent text strings, not as part of an ongoing conversation.
For this reason, a flow with only Text Input/Output components isn't compatible with the Playground.
For more information, see Input/Output components.
When using the Langflow API, the response includes the Message
object along with other response data from the flow run.
Langflow API responses can be extremely verbose, so your applications must include code to extract relevant data from the response to return to the user.
For an example, see the Langflow quickstart.
Additionally, input sent to the input port of input/output components does not need to be a complete Message
object because the component constructs the Message
object that is then passed to other components in the flow or returned as flow output.
In fact, some components should not receive a complete Message
object because some attributes, like timestamp
should be added by the component for accuracy.
Tool
Tool ports connect tools to an Agent component.
Tools can be other components where you enabled Tool Mode, they can be the dedicated MCP Tools component, or they can be other components that only support Tool Mode. Multiple tools can be connected to the same Agent component at the same port.
Functionally, Tool
data is a LangChain StructuredTool
object that can be used in agent workflows.
For more information, see Configure tools for agents and Use Langflow as an MCP client.
Unknown or multiple types
If a port can accept or produce multiple data types, it is represented by the gray port icon .
Hover over the port to see the accepted or produced data types.
View data types in flows
In Langflow, you can use Inspect output to view the output of individual components. This can help you learn about the different data type and debug problems with invalid or malformed inputs and output.
The following example shows how to inspect the output of a Type Convert component, which can convert Message
, Data
, or DataFrame
input into Message
, Data
, or DataFrame
output:
-
Create a flow, and then connect a Chat Input component to a Type Convert component.
-
In the Chat Input component, enter some text for the type converter to process.
-
On the Type Convert component, click Run component, and then click Inspect output.
The default output is
Message
data, which is the same as the input coming from the Chat Input component. To see theMessage
data converted toData
orDataFrame
, change the Output Type on the Type Convert component, and then rerun the component.- Message
- Data
- DataFrame
_10Input text_30{_30"timestamp": "2025-07-15 20:56:20 UTC",_30"sender": "User",_30"sender_name": "User",_30"session_id": "a0c7e888-4fd6-4242-b8c8-e761ad690aeb",_30"text": "",_30"files": [],_30"error": false,_30"edit": false,_30"properties": {_30"text_color": "",_30"background_color": "",_30"edited": false,_30"source": {_30"id": null,_30"display_name": null,_30"source": null_30},_30"icon": "",_30"allow_markdown": false,_30"positive_feedback": null,_30"state": "complete",_30"targets": []_30},_30"category": "message",_30"content_blocks": [],_30"id": "9da72da2-efbb-4ccd-90ad-b32429b0418e",_30"flow_id": "a0c7e888-4fd6-4242-b8c8-e761ad690aeb",_30"duration": null_30}_16| Field | Value |_16|-------|-------|_16| timestamp | 2025-07-15 20:56:11 UTC |_16| sender | User |_16| sender_name | User |_16| session_id | a0c7e888-4fd6-4242-b8c8-e761ad690aeb |_16| text | (empty) |_16| files | [] |_16| error | False |_16| edit | False |_16| properties | text_color: '', background_color: '', edited: False, source: {id: None, display_name: None, source: None}, icon: '', allow_markdown: False, positive_feedback: None, state: 'complete', targets: [] |_16| category | message |_16| content_blocks | [] |_16| id | 341686eb-7a39-4b80-a90a-d8bf267815ef |_16| flow_id | a0c7e888-4fd6-4242-b8c8-e761ad690aeb |_16| duration | (empty) |