> ## Documentation Index
> Fetch the complete documentation index at: https://askmarvin.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# classify

# `marvin.fns.classify`

## Functions

### `classify`

```python theme={null}
def classify(data: Any, labels: Sequence[T] | type[T], multi_label: bool = False, *, instructions: str | None = None, agent: Agent | None = None, thread: Thread | str | None = None, context: dict[str, Any] | None = None, handlers: list[Handler | AsyncHandler] | None = None, prompt: str | None = None) -> T | list[T]
```

Classifies input data into one or more predefined labels using a language model.

This function uses a language model to analyze the input data and assign it to
the most appropriate label(s) from the provided sequence of labels or Enum class.

Args:
data: The input data to classify. Can be any type.
labels: Either a sequence of possible labels (of type T) or an Enum class to
classify the data into. If an Enum class is provided, its values will be
used as the labels.
multi\_label: If False (default), returns a single label. If True, returns
multiple labels as a list.
instructions: Optional additional instructions to guide the classification.
Used to provide specific guidance about how to interpret or classify
the data.
agent: Optional custom agent to use for classification. If not provided,
the default agent will be used.
thread: Optional thread for maintaining conversation context. Can be
either a Thread object or a string thread ID.
context: Optional dictionary of additional context to include in the task.
handlers: Optional list of handlers to use for the task.
Returns:

* If labels is a Sequence\[T]:
  * If multi\_label is False: returns T
  * If multi\_label is True: returns list\[T]
* If labels is an Enum class:
  * If multi\_label is False: returns E (the Enum value)
  * If multi\_label is True: returns list\[E] (list of Enum values)

Examples:

```python theme={null}
>>> # Using a sequence of labels
>>> classify("red car", ["red", "blue", "green"])
'red'

>>> # Using an Enum class
>>> class Colors(enum.Enum):
...     RED = "red"
...     BLUE = "blue"
...     GREEN = "green"
>>> classify("red car", Colors)
<Colors.RED: 'red'>

>>> # Multi-label classification
>>> classify("red and blue car", Colors, multi_label=True)
[<Colors.RED: 'red'>, <Colors.BLUE: 'blue'>]

>>> # Boolean classification
>>> classify("2+2=4", bool)
True
```

### `classify_async`

```python theme={null}
async def classify_async(data: Any, labels: Sequence[T] | type[T], multi_label: bool = False, *, instructions: str | None = None, agent: Agent | None = None, thread: Thread | str | None = None, context: dict[str, Any] | None = None, handlers: list[Handler | AsyncHandler] | None = None, prompt: str | None = None) -> T | list[T]
```

Asynchronously classifies input data into one or more predefined labels using a language model.

This function uses a language model to analyze the input data and assign it to
the most appropriate label(s) from the provided sequence of labels or Enum class.

Args:
data: The input data to classify. Can be any type.
labels: Either a sequence of possible labels (of type T) or an Enum class to
classify the data into. If an Enum class is provided, its values will be
used as the labels.
multi\_label: If False (default), returns a single label. If True, returns
multiple labels as a list.
instructions: Optional additional instructions to guide the classification.
Used to provide specific guidance about how to interpret or classify
the data.
agent: Optional custom agent to use for classification. If not provided,
the default agent will be used.
thread: Optional thread for maintaining conversation context. Can be
either a Thread object or a string thread ID.
context: Optional dictionary of additional context to include in the task.
prompt: Optional prompt to use for the task. If not provided, the default
prompt will be used.
Returns:

* If labels is a Sequence\[T]:
  * If multi\_label is False: returns T
  * If multi\_label is True: returns list\[T]
* If labels is an Enum class:
  * If multi\_label is False: returns E (the Enum value)
  * If multi\_label is True: returns list\[E] (list of Enum values)

Examples:

```python theme={null}
>>> # Using a sequence of labels
>>> await classify_async("red car", ["red", "blue", "green"])
'red'

>>> # Using an Enum class
>>> class Colors(enum.Enum):
...     RED = "red"
...     BLUE = "blue"
...     GREEN = "green"
>>> await classify_async("red car", Colors)
<Colors.RED: 'red'>

>>> # Multi-label classification
>>> await classify_async("red and blue car", Colors, multi_label=True)
[<Colors.RED: 'red'>, <Colors.BLUE: 'blue'>]

>>> # Boolean classification
>>> await classify_async("2+2=4", bool)
True
```

***

**Parent Module:** [`fns`](marvin-fns)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.