# Metadata Function

For each sample, Tensorleap allows additional data to be added for future analysis. Each defined piece of data is wrapped in a **metadata function**.

```python
from code_loader.contract.datasetclasses import PreprocessResponse
from code_loader.inner_leap_binder.leapbinder_decorators import tensorleap_metadata
import numpy as np
...
@tensorleap_metadata(name='metadata_label_description', metadata_type={"label":DatasetMetadataType.int, "is_circle": DatasetMetadataType.boolean})
def metadata_label(idx: int, preprocess: PreprocessResponse) -> Dict[str, Union[int, bool]]:
    return {
        'label': int_metadata_creator(preprocess, idx),
        'is_circle': bool_metadata_creator(preprocess, idx),
    }
```

The [@tensorleap\_metadata](/tensorleap-integration/python-api/code_loader/decorators/tensorleap_metadata.md) decorator registers each metadata function into the Tensorleap integration.

You can add additional custom metadata that will later be available for each sample to help with analysis. This function is called for each evaluated sample.

These functions should return either:

* An int/bool/float/str property per sample
* A dictionary with multiple attributes that maps str keys to int/bool/float/str properties

{% hint style="warning" %}
When using the dictionary syntax, the supplied dictionary must be flat (i.e. a mapping of a str to bool/float/str/int). Non-flat dictionaries will result in integration errors.
{% endhint %}

Usage within the full script can be found at the [**Integration Script**](/tensorleap-integration/writing-integration-code.md#dataset-script).


---

# 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/metadata-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.
