Sort an email, then ask what that kind needs
Open in playground →One answer picks which question comes next. The email is classed as an invoice, a meeting request or a job application, and only the follow-up for that kind runs: an amount, a date or a role.
Challenges
kindis an enum of three. Each follow-up has awhenon one of them, so exactly one runs:amount_due(a number) for an invoice,meeting_date(a string) for a meeting request,role(an enum) for a job application.- This email is an invoice, so
amount_duecomes back as the number1240, andmeeting_dateandroleare skipped: no requests are sent for them, andskippedlists them. - The tests run in code on the typed
kind. The fields awhennames are dependencies, so none of the follow-ups listsdepends_on.
import os
from typellm import TypeLLMClient
client = TypeLLMClient(api_key=os.environ["TYPELLM_API_KEY"])
response = client.generate(
context="Subject: Invoice INV-2291\n\nHi, please find attached invoice INV-2291 from Acme Hosting for September. Amount due: $1,240.00 by October 15. Thanks, Acme Billing",
questions={
"kind": {
"instructions": "What kind of email is this?",
"type": "string",
"enum": [
"invoice",
"meeting_request",
"job_application"
]
},
"amount_due": {
"instructions": "Amount due in dollars.",
"type": "number",
"when": {
"kind": "invoice"
}
},
"meeting_date": {
"instructions": "Proposed meeting date, as YYYY-MM-DD.",
"type": "string",
"when": {
"kind": "meeting_request"
}
},
"role": {
"instructions": "Which role is the candidate applying for?",
"type": "string",
"enum": [
"engineering",
"design",
"sales"
],
"when": {
"kind": "job_application"
}
}
},
)
print(response)Generation(
result={
'kind': 'invoice',
'amount_due': 1240,
},
thinking={},
usage=Usage(input_tokens=195, thinking_tokens=0),
skipped=[
'meeting_date',
'role',
],
)