Examples

Discover a new category

Open in playground →
  • Enum
  • when
  • Text

Task

File an expense under one of your categories, or name a new one when none of them fits.

Challenges

  • category lists your categories plus new. new_category runs only when the answer is new: "when": {"category": "new"}, and it sees that answer, so it names what the expense actually is.
  • Bar association dues are not travel, meals, software or office supplies, so this one comes back new, named professional_fees. A flight, "Flight from Boston to Chicago for the client meeting, $312.", came back travel, and new_category was skipped.

Laying out…

Time 0.42 s · Cost $0.0000056

Generation(
    result={
        'category': {
            'value': 'new',
            'probabilities': {
                'travel': 0.001,
                'meals': 0.001,
                'software': 0.001,
                'office_supplies': 0.001,
                'new': 0.996,
            },
            'confidence': 0.995,
        },
        'new_category': 'professional_fees',
    },
    thinking={},
    usage=Usage(input_tokens=111, thinking_tokens=0),
)

Build it into a task: Classification with category discovery, in the cookbook.