Functions
Extract
Pull structured data from unstructured content
The extract
function finds and pulls out specific pieces of information. It transforms str → list[T]
, making it easy to collect:
- Contact details (“email: alice@example.com” → [“alice@example.com”])
- Measurements (“The room is 20.5 feet wide” → [20.5])
- Dates (“Meeting on Jan 15th” → [datetime(2024, 1, 15)])
- Structured data (“Alice (25) and Bob (30)” → [Person(name=“Alice”, age=25), Person(name=“Bob”, age=30)])
For complex extraction patterns, consider creating a custom task. The extract
function is a convenient wrapper around Marvin’s task system - see Tasks for more details.
Usage
Pull email addresses from text:
Parameters
data
: The input data to extract from (any type)target
: The type of data to extract (defaults tostr
)instructions
: Required when target isstr
to specify what to extractagent
: 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
Numeric Values
Find all numbers in text:
Named Entities
Extract specific types of information:
Dates and Times
Find temporal information in text:
Structured Data
Pull complex information into structured types: