# @tensorleap\_metadata

The `tensorleap_metadata` decorates a [**Metadata Function**](/tensorleap-integration/writing-integration-code/metadata-function.md).

```python
@tensorleap_metadata(name='metadata_sample_index', metadata_type={"label": DatasetMetadataType.int, "is_circle": DatasetMetadataType.boolean})
def metadata_sample_index(idx: int, preprocess: PreprocessResponse) -> Union[int, str, bool, float, Dict[str, Union[int, str, bool, float]]]:
    pass
```

<table><thead><tr><th width="158.46928201888204">Args</th><th></th></tr></thead><tbody><tr><td><code>metadata_type</code></td><td><p><em>(</em><a href="/pages/2yMyTPWnRB18eFN3r2Fi"><em><strong>DatasetMetadataType</strong></em></a><em><strong>, optional</strong>)</em> This property helps visualize the <strong>metadata</strong> data.</p><ul><li>For a <strong>float</strong> metadata value, use <code>DatasetMetadataType.float</code></li><li>For a <strong>string</strong> metadata value, use <code>DatasetMetadataType.string</code></li><li>For a <strong>int</strong> metadata value, use <code>DatasetMetadataType.int</code></li><li>For a <strong>boolean</strong> metadata value, use <code>DatasetMetadataType.boolean</code></li><li>For a <strong>dictionary</strong> return a dictionary that maps key name to key type</li></ul><p>Providing MetadataType becomes mendatory if some of the samples has a "None" value for the metadata</p></td></tr><tr><td><code>name</code></td><td><em>(str)</em> The given name of the <strong>metadata,</strong> e.g. label.</td></tr></tbody></table>

### Examples

#### Basic Usage

```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),
    }
```

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

#### Guides

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/decorators/tensorleap_metadata.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.
