> ## Documentation Index
> Fetch the complete documentation index at: https://docs.llmcontrols.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# LLM Controls objects

In LLM Controls, objects are [Pydantic](https://docs.pydantic.dev/latest/api/base_model/) models that serve as structured, functional representations of data.

## **Data object**[**​**](https://docs.langflow.org/concepts-objects#data-object)

The `Data` object is a [Pydantic](https://docs.pydantic.dev/latest/api/base_model/) 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.

### **Create a Data Object**[**​**](https://docs.langflow.org/concepts-objects#create-a-data-object)

1. Create a `Data` object by directly assigning key-value pairs to it.
2. 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.
3. 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 LLM Controls.
4. To receive `Data` objects in a component input, use the `DataInput` input type.

### **Message object**[**​**](https://docs.langflow.org/concepts-objects#message-object)

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

1. **Core message data:**
   * `text`: The main text content of the message
   * `sender`: Identifier for the sender ("User" or "AI")
   * `sender_name`: Name of the sender
   * `session_id`: Identifier for the chat session (`string` or `UUID`)
   * `timestamp`: Timestamp when the message was created (UTC)
   * `flow_id`: Identifier for the flow (`string` or `UUID`)
   * `id`: Unique identifier for the message
2. **Content and files:**
   * `files`: List of files or images associated with the message
   * `content_blocks`: List of structured content block objects
   * `properties`: Additional properties, including visual styling and source information
3. **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")

<Note>
  The `Message` object can be used to send, store, and manipulate chat messages within LLM Controls.
</Note>

### **Create a Message object**[**​**](https://docs.langflow.org/concepts-objects#create-a-message-object)

You can create a `Message` object by directly assigning key-value pairs to it.

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.

## **ContentBlock object**[**​**](https://docs.langflow.org/concepts-objects#contentblock-object)

The `ContentBlock` object is a list of multiple `ContentTypes`. It allows you to include multiple types of content within a single `Message`, including images, videos, and text.

Each content type has specific fields related to its data type. For example:

* `TextContent` has a `text` field for storing strings of text
* `MediaContent` has a `urls` field for storing media file URLs
* `CodeContent` has `code` and `language` fields for code snippets
* `JSONContent` has a `data` field for storing arbitrary JSON data
* `ToolContent` has a `tool_input` field for storing input parameters for the tool

### **Create a ContentBlock object**[**​**](https://docs.langflow.org/concepts-objects#create-a-contentblock-object)

Create a `ContentBlock` object with a list of different content types.

```text theme={null}

from llmcontrols.schema.content_block import ContentBlock
from llmcontrols.schema.content_types import TextContent, MediaContent, CodeContent, JSONContent, ToolContent

# Create a ContentBlock with mixed content types
content_block = ContentBlock(
    title="My Content Block",
    contents=[
        TextContent(text="Hello, this is a text block."),
        MediaContent(urls=["https://example.com/image.png"], caption="An example image"),
        CodeContent(code="print('Hello World')", language="python"),
        JSONContent(data={"key": "value", "count": 42}),
    ]
)
```

### **Add ContentBlocks objects to a message**

In this example, a text and a media `ContentBlock` are added to a message.

```text theme={null}

from llmcontrols.schema.message import Message
from llmcontrols.schema.content_block import ContentBlock
from llmcontrols.schema.content_types import TextContent, MediaContent

# Create content blocks
text_block = ContentBlock(
    title="Summary",
    contents=[TextContent(text="Here is the analysis result.")]
)

media_block = ContentBlock(
    title="Related Images",
    contents=[MediaContent(urls=["https://example.com/chart.png"], caption="Results chart")]
)

# Add to a message
message = Message(text="Analysis complete.")
message.content_blocks = [text_block, media_block]
```

### **DataFrame object**[**​**](https://docs.langflow.org/concepts-objects#dataframe-object)

The `DataFrame` class is a custom extension of the Pandas [DataFrame](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.html) class, specifically designed to work seamlessly with LLM Controls' `Data` objects. The class includes methods for converting between `DataFrame` and lists of `Data` objects.

A `DataFrame` object accepts various input formats, including lists of `Data` objects, dictionaries, and existing `DataFrames`.

### **Create a DataFrame object**[**​**](https://docs.langflow.org/concepts-objects#create-a-dataframe-object)

You can create a DataFrame object using different data formats

```text theme={null}
from llmcontrols.schema import Data
from llmcontrols.schema.data import DataFrame
# From a list of Data objects
data_list = [Data(data={"name": "John"}), Data(data={"name": "Jane"})]
df = DataFrame(data_list)
# From a list of dictionaries
dict_list = [{"name": "John"}, {"name": "Jane"}]
df = DataFrame(dict_list)
# From a dictionary of lists
data_dict = {"name": ["John", "Jane"], "age": [30, 25]}
df = DataFrame(data_dict)
```

### Key Methods

* to\_data\_list(): Converts the DataFrame back to a list of Data objects.
* add\_row(data): Adds a single row (either a Data object or a dictionary) to the DataFrame.
* add\_rows(data): Adds multiple rows (list of Data objects or dictionaries) to the DataFrame.

### Usage Example

```text theme={null}
# Create a DataFrame
df = DataFrame([Data(data={"name": "John"}), Data(data={"name": "Jane"})])
# Add a new row
df = df.add_row({"name": "Alice"})
# Convert back to a list of Data objects
data_list = df.to_data_list()
# Use pandas functionality
filtered_df = df[df["name"].str.startswith("J")]
```

### To use DataFrame objects in a component input, use the DataFrameInput input type:

```text theme={null}
DataFrameInput(
    name="dataframe_input", 
    display_name="DataFrame Input", 
    info="Input for DataFrame objects.", 
    tool_mode=True
```
