# Preprocess Function

The `preprocessing_func` *(custom name)* is a **preprocess** function that is called just once before the training/evaluating process. It prepares the data for later use in **input encoders**, **output encoders**, and **metadata** functions.

```python
from code_loader.contract.datasetclasses import PreprocessResponse
from code_loader.inner_leap_binder.leapbinder_decorators import tensorleap_preprocess

@tensorleap_preprocess()
def preprocessing_func() -> List[PreprocessResponse]:
    ...
    train = PreprocessResponse(sample_ids=list(train_df.index), data=train_df, state=DataStateType.training)
    val = PreprocessResponse(sample_ids=list(val_df.index), data=val_df, state=DataStateType.validation)
    test = PreprocessResponse(sample_ids=list(test_df.index), data=test_df, state=DataStateType.test)
    unlabeled = PreprocessResponse(sample_ids=list(unlabeled_df.index), data=unlabeled_df, state=DataStateType.unlabeled)
​
    return [train, val, test, unlabeled]
```

The [@tensorleap\_preprocess](/tensorleap-integration/python-api/code_loader/decorators/tensorleap_preprocess.md) decorator registers the preprocess function into the Tensorleap integration.

This function returns a `List` of [**`PreprocessResponse`**](/tensorleap-integration/python-api/code_loader/datasetclasses/preprocessresponse.md) objects. The elements on that list correspond to the `train` , `validation,` `test` and `unlabeled` data slices.

For a successful Tensorleap integration, supplying a train and validation set is mandatory, the rest is optional. Refer to the [**Code Integration**](/tensorleap-integration/writing-integration-code.md) section for complete usage instructions.

{% hint style="warning" %}
It is mandatory to return at least a training and a validation set.
{% endhint %}


---

# 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/writing-integration-code/preprocess-function.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.
