# 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: 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:

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

The question should be specific, self-contained, and written in natural language.
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.
