Functions
Generate
Create examples of any data type
The generate
function creates realistic examples of any type. It transforms () → T
, making it easy to produce:
- Test data (“Generate a plausible email address” → “sarah.jones@company.com”)
- Sample content (“Generate a product description” → “Sleek wireless earbuds with…”)
- Structured examples (“Generate a recipe” → Recipe(title=“Lemon Garlic Pasta”, ingredients=[…]))
For complex generation patterns, consider creating a custom task. The generate
function is a convenient wrapper around Marvin’s task system - see Tasks for more details.
Usage
Generate a simple string:
Parameters
target
: The type of data to generaten
: Number of examples to generate (default: 1)instructions
: Optional guidance for generationagent
: 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
Multiple Examples
Generate a list of items:
Structured Data
Generate complex objects:
With Context
Generate content with specific requirements:
Collections
Generate lists and dictionaries: