Skip to main content
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 generate
  • n: Number of examples to generate (default: 1)
  • instructions: Optional guidance for generation
  • agent: Optional custom agent to use
  • thread: Optional thread for conversation context
  • context: 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: