Functions
Classify
Assign data to predefined categories
The classify
function turns any input into clear categories. It transforms str → L
where L
is your set of labels, making it easy to identify:
- Sentiment (“Great product!” → Positive)
- Topics (“AI in healthcare” → [Technology, Healthcare])
- Priority (“URGENT: System down” → Critical)
- Status (“All tests passing” → Success)
For complex classification needs, consider creating a custom task. The classify
function is a convenient wrapper around Marvin’s task system - see Tasks for more details.
Usage
Classify text into predefined categories:
Parameters
data
: The input data to classify (any type)labels
: Either a sequence of labels or an Enum classmulti_label
: Whether to return multiple labels (defaults toFalse
)instructions
: Optional instructions to guide classificationagent
: Optional custom agent to usethread
: Optional thread for conversation contextcontext
: Optional additional context
Async Support
The function is also available in an async version:
Examples
Basic Classification
Use simple string labels to categorize content:
Using Enums
Add type safety with Python enums:
Multi-label Classification
Identify multiple applicable categories:
Custom Instructions
Guide the classification with specific criteria: