As many items as the input holds
Until now, every TypeLLM field returned one value: a string, a number, a choice. But many answers are lists. The people at a meeting, the jobs on a CV, the products on an order. You don't know how many there are until you read the input.
TypeLLM 0.6 adds array. It returns as many items as the input holds, and every item has the type you gave it.
A list of names
Who was at this standup?
response = client.generate(context=notes, questions={
"attendees": {"type": "array", "items": {"type": "string"},
"instructions": "Names of the people at the standup."},
})The notes say "Present: Priya, Jun and Leo. Marco is out sick." The API returns:
response.result # {"attendees": ["Priya", "Jun", "Leo"]}Marco is in the notes, but he was not at the standup, so he is not in the list. The instructions decide which items belong.
A list of records
An array's items can be objects, so each item is a typed record. Here is the CV from the top of this post, a PDF page sent as an image:
response = client.generate(
context="Read the attached CV.",
images=["cv.png"],
questions={
"work_experience": {
"type": "array",
"items": {"type": "object", "properties": {
"company": {"type": "string"},
"title": {"type": "string"},
"start_year": {"type": "integer"},
"end_year": {"type": ["integer", "null"]},
}},
"instructions": "Each position on the CV, most recent first.",
},
"skills": {"type": "array", "items": {"type": "string"},
"instructions": "Every skill listed on the CV."},
},
){"work_experience": [
{"company": "Lumina Health", "title": "Staff Data Engineer",
"start_year": 2023, "end_year": None},
{"company": "Corvo Logistics", "title": "Senior Data Engineer",
"start_year": 2020, "end_year": 2023},
# ... five more, down to
{"company": "Politecnico di Milano", "title": "Teaching Assistant",
"start_year": 2011, "end_year": 2012}],
"skills": ["Python", "SQL", "Scala", ..., "Terraform", "AWS"]} # 16 skillsThe current job has no end year, so end_year is None, not a made-up year, and every other year is an integer, not a string. The degrees and languages are on the CV too, but they are not jobs or skills, so they are not in either list. Seven jobs and sixteen skills came back from one call, in about eight seconds.
How it works: one item at a time
A list is hard to type because its length is part of the answer. TypeLLM builds the list one item at a time. Each step sees the input and the list so far, written out as JSON, and makes one decision.
- A list of strings, numbers or choices. The next item may be a value or
null. A value is added to the list;nullends it. For an enum list, every item is one of your values: the model chooses from them and does not write them out. - A list of objects. Each step first asks one yes-or-no question: should a new item be appended to the current array? If yes, the new item's properties are all generated at once, side by side, and the list grows by one. If no, the list is done.
Because every step sees the list so far, a later item knows what is already there. An item that would repeat one already in the list is not added, and the list ends there. Each step continues from the same cached input, so a long document is read once, not once per item.
Bounds
minItemsandmaxItemsbound a list. BelowminItems, the list cannot end; atmaxItems, it stops.- A list holds at most 50 items.
- A field that
depends_onan array sees all of it, so a later field can summarise or check the list.
And objects
object groups typed properties into one value, such as the candidate on a CV: {"name": ..., "email": ..., "city": ...}. Its properties take everything a field takes, including thinking, depends_on and when.
Try it
Objects and arrays are in TypeLLM 0.6.0 and the TypeLLM API. Run the standup or CV example in the playground, or read the output types docs.