Read a photographed receipt
Open in playground →A crumpled receipt goes in; typed strings, integers, numbers and booleans come out, and a discount percentage is computed from two of them.
Challenges
- The only input is a photo of a crumpled receipt: there is no text to copy from.
- Amounts are printed as
194,000. Each must come back as the number194000, not a string, and not194. - The discount percentage is not printed anywhere. It has to be worked out from the subtotal and the discount, so it is asked after them with
depends_on.

import os
from typellm import TypeLLMClient
client = TypeLLMClient(api_key=os.environ["TYPELLM_API_KEY"])
response = client.generate(
context="Read the attached photo of a restaurant receipt.",
questions={
"first_item": {
"type": "string",
"instructions": "Name of the first line item, exactly as printed."
},
"item_lines": {
"type": "integer",
"instructions": "How many line items are listed?"
},
"subtotal": {
"type": "number",
"instructions": "Subtotal in rupiah as a plain number; the receipt uses commas as thousands separators."
},
"discount": {
"type": "number",
"instructions": "Discount in rupiah as a plain number."
},
"total": {
"type": "number",
"instructions": "Total in rupiah as a plain number."
},
"paid_in_cash": {
"type": "boolean",
"instructions": "Was the bill paid in cash?"
},
"discount_percent": {
"type": "number",
"depends_on": [
"subtotal",
"discount"
],
"instructions": "Discount as a percentage of the subtotal."
}
},
images=["receipt.jpg"],
)
print(response)Generation(
result={
'first_item': 'ICE BLACKCOFFEE',
'item_lines': 3,
'subtotal': 194000,
'discount': 19400,
'total': 174600,
'paid_in_cash': True,
'discount_percent': 10,
},
thinking={},
usage=Usage(input_tokens=1270, thinking_tokens=0),
)