> For the complete documentation index, see [llms.txt](https://docs.tensorleap.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tensorleap.ai/tensorleap-integration/python-api/code_loader/datasetclasses/preprocessresponse.md).

# PreprocessResponse

An object that holds the samples data and length. This object is generated in the Preprocessing Function for each dataset slice. Then passed to the **input encoders**, **ground\_truth encoders** and **metadata** functions as an argument.

```python
from code_loader.contract.enums import DataStateType

@dataclass
class PreprocessResponse:
    length: Optional[int] = None
    data: Any = None
    sample_ids: Optional[Union[List[str], List[int]]] = None
    state: Optional[DataStateType] = None
    sample_id_type: Optional[Union[Type[str], Type[int]]] = None
```

For more on `PreprocessResponse`:

<table><thead><tr><th width="167.39065467110788">Args</th><th></th></tr></thead><tbody><tr><td><code>length</code></td><td><em>(int, deprecated)</em> Number of samples in the slice. Deprecated — use <code>sample_ids</code> instead.</td></tr><tr><td><code>data</code></td><td><em>(Any)</em> Dictionary / pandas.DataFrame / List or any object that describes the dataset features. The <code>data</code> parameter is later passed to the <strong>input encoders, ground_truth encoders</strong>, and <strong>metadata</strong> functions.</td></tr><tr><td><code>sample_ids</code></td><td>A list of unique identifiers for each sample in the slice. IDs should be either a list of ints or strings. Preferred over <code>length</code>.</td></tr><tr><td><code>state</code></td><td><em>(</em><a href="/pages/QKMvpPnYZwFl3GAOnxfv">DataStateType</a><em><strong>, optional</strong>)</em> The dataset split this response belongs to. Recommended to always set explicitly.</td></tr><tr><td><code>sample_id_type</code></td><td>(str/int, optional) The type of the sample IDs. Inferred automatically when using <code>sample_ids</code>.</td></tr></tbody></table>

## Examples

#### Basic Usage

```python
from code_loader.contract.datasetclasses import PreprocessResponse
preprocess_response = PreprocessResponse(sample_ids=list(x_df.index), data=x_df)
```

#### Within the Preprocess Function

Full examples can be found at the **Dataset Integration** section of the following guides:

* [**MNIST Guide**](/guides/full-guides/mnist-guide.md)
* [**IMDB Guide**](/guides/full-guides/imdb-guide.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.tensorleap.ai/tensorleap-integration/python-api/code_loader/datasetclasses/preprocessresponse.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
