Line Items Are a List of Objects

nested schema validation

Part of: Receipt Scanner

merchant, date, and total are the easy part. The useful part of a receipt is the list of things someone actually bought. That list has a different shape than the flat fields you validated last lesson. It's a variable-length array of objects, and every object can go wrong in its own way. Asking for a list of objects Extend the prompt's schema with an items array, and show the model exactly what one item looks like: One concrete example item in the prompt does more work than a paragraph describing the shape. Models copy a pattern far more reliably than they follow an abstract spec. Why line items break more than flat fields A blurry photo or a cramped receipt can push the model into merging two items into one, or inventing a quantity it couldn't actually read, or handing back a price as the string "$4.50" when you wanted the number 4.5. A flat field either shows up or goes missing. A list field is messier: it can carry some good entries and some broken ones in the same array. That means validating each item on its own, not just checking that items exists. What "valid" means for one item Three checks, run against every entry in the list: - name is a non-empty string. - quantity is a p

Challenge: Line Item Bouncer