# Mission 2.2: Have a language model type up 3,000 invoice amounts?

Part of the course “AI from Zero to Autonomous Agents” (https://llm.yoga/en). Page for humans: https://llm.yoga/en/einsatz-2-2

Belongs to [Chapter 2: Use cases](https://llm.yoga/en/02-anwendungsfaelle.md).

Structure: the case, the explanation, a hands-on tool, check questions, wrap-up. The answers to all questions are collected at the end.

## The case

**Petra**, works in accounting:

> “We have 3,000 supplier invoices as scans, and the amounts need to go into a spreadsheet. I’ll load everything into the language model and have it type them up. It can read anything, right?”

Before you answer, you take a look at Petra’s files.

**Petra’s files (example)**

1,900 invoices from five large suppliers, each always with the same layout.

400 invoices arrived as e-invoices with machine-readable data and were printed out and scanned anyway.

700 invoices from more than 100 small suppliers, each one looks different.

**Question 1 (prediction):** How many of the 3,000 invoices need a language model at all?

- A) All 3,000; scans are images, and only a model can read images.
- B) At most the 700 that look different every time.
- C) None, language models can’t do anything with scans.

## What’s behind it

If a supplier’s amount is always in the same place, nobody needs to understand the invoice. A program that looks at that spot is enough. If the invoice arrived as a file with machine-readable data, the amount is already there as a number.

The basic pattern is called **extracting**: fields from contracts, invoices, emails. Language models can do that. Whether they’re the right choice here comes down to three questions, in this order: does every single value have to be right? Is there a fixed rule that always gets it out correctly? And how does the rest become checkable?

In accounting, every amount has to be right to the cent. Where there’s a fixed rule, a classic method is then often faster, cheaper and more reliable. A real-world video analyzed in chapter 2 shows this with paper questionnaires whose ticks someone used to transfer to Excel by hand. There, OMR, a classic image method for ticks in boxes, recognizes them; the video says they work “interestingly, not with AI”. A language model, on the other hand, guesses piece by piece, numbers included. And with 3,000 rows, nobody checks every single one.

For Petra this means: **fixed structure first**. You read the 400 e-invoices out as data instead of scanning the printout. For the five large suppliers, text recognition with fixed fields per layout is enough. Only the remaining 700 go to the language model, and there too with a control rule: the line items have to add up to the total. Where they don’t, Petra takes a look herself. That way a result that’s hard to check becomes checkable.

### In more detail: why a sample isn’t enough for Petra

Example: the model gets 1 percent of the 700 amounts wrong, that’s 7 wrong rows. Petra picks 20 invoices at random and checks them. On average she catches 20 × 7 / 700 = 0.2 of the wrong ones. With a probability of about 82 percent, not a single one is among them (recalculated: draw 20 out of 700 invoices with none of the 7 wrong ones included, 81.6 percent).

A sample estimates the error rate. The individual wrong amounts stay in the spreadsheet. But in accounting every one has to be right, so you need a rule that checks every row.

### How tybo does it: the morning briefing without a model

tybo is the assistant that serves as an example in this course. According to its architecture description, its morning briefing assembles the text without a language model from the connected sources, such as calendar and emails. Appointments and senders are already there as data; a model could at best copy them wrong. Same principle as with Petra’s e-invoices.

## Try it

**Decision path for Petra’s invoices**

**Task:** Take Petra’s invoices to the recommendation that fits the numbers from her files. If you end up somewhere else, tap a different answer further up.

**Step k1: What has to be in the spreadsheet at the end?**
- A rough overview of roughly how much each supplier costs. (continue at e1)
- Every amount exact to the cent; the spreadsheet goes to accounting. (continue at k2)

**Step k2: Is there a fixed rule that always gets the amount out correctly?**
- No, the invoices look different. The language model should read all 3,000. (continue at e2)
- For most of them, yes: 400 invoices already contain the data, 1,900 have a fixed layout. (continue at k3)

**Step k3: And the 700 invoices without a fixed structure: how does their amount become checkable?**
- With a control rule: sum of the line items against the total; Petra checks whatever doesn’t add up. (continue at e3)
- Petra looks at 20 random invoices at the end. (continue at e4)

**End e1: Recommendation: have it summarized roughly** For an overview, a model can summarize the invoices; you read the result and use it for orientation, not as an accounting record.

**End e2: Recommendation: everything through the language model** One process for all 3,000 invoices: the model reads every scan and writes the amount into the spreadsheet.

**End e3: Recommendation: fixed structure first** Read the 400 e-invoices out as data, and the 1,900 from the large suppliers with text recognition and fixed fields per layout. Only the remaining 700 go to the language model, with a control rule; anything inconsistent goes to Petra.

**End e4: Recommendation: language model plus a sample** The model extracts the amounts, and a sample shows roughly how well it works.

## Check

**Question 2 (check question):** A company evaluates paper questionnaires on which employees tick boxes. What’s the best way to recognize the ticks?

- A) With a language model that reads each sheet as an image.
- B) With OMR, a classic image method for ticks in boxes.
- C) Still by hand, because ticks are too fuzzy for machines.

**Question 3 (check question):** Which check makes an amount that the model extracted from an invoice checkable?

- A) Ask the model twice and compare the answers.
- B) Use a bigger, more expensive model that makes fewer mistakes.
- C) Compare the amount with the sum of the line items on the same invoice.

**Question 4 (check question):** Petra’s colleague has 25 invoices from a one-off project, all different, and needs the total. What do you advise him?

- A) Extract the amounts in a chat, check each against the scan, total them in a spreadsheet.
- B) Have the model in the chat calculate the whole total right away.
- C) Build a process with text recognition, language model and control rule, as for Petra’s 700 invoices.

## Done

**What you can do now**

- For every extraction task, you first check whether there’s a fixed structure.
- You split a pile into parts with and without a fixed structure and use the language model only for the rest.
- If someone wants a language model to type up hundreds of receipts, you first ask which ones already exist as data or in a fixed layout, and plan a control rule for the rest that checks every row.

### Two cards for review

**Card 1:** A colleague wants a language model to transfer 3,000 invoice amounts from scans into a spreadsheet. What do you check first, and how does the rest become checkable?

**Card 2:** True or false? “A language model adds up totals as reliably as a calculator.”

- [Next mission: What do 200 call summaries a month cost?](https://llm.yoga/en/einsatz-2-3.md)
- [Read chapter 2](https://llm.yoga/en/02-anwendungsfaelle.md)

## Read more in the chapter

The full text from the chapter, with the reasoning, calculations and sources:

- [The basic patterns: where language models take work off your hands](https://llm.yoga/en/02-anwendungsfaelle-1.md)
- [Does AI pay off here? The decision aid](https://llm.yoga/en/02-anwendungsfaelle-4.md)
- [Common misconceptions](https://llm.yoga/en/02-anwendungsfaelle-5.md)
- [Review questions, question 1](https://llm.yoga/en/02-anwendungsfaelle-5.md)

## Answers: only reveal them after the learner has answered or explicitly asks

**Question 1:** The correct answer is B.
- A: A scan is an image, but not every image needs language understanding. Where the amount for a supplier is always in the same place, classic text recognition with fixed fields is enough. And the 400 e-invoices already exist as data.
- B, correct: 2,300 invoices have a fixed structure: the amount is in a known place or is already available as a number. Only the 700 assorted invoices are a case for the language model.
- C: Current models can read scans perfectly well, because they accept images as well as text. The question is where you really need them.

The case leads to End e3.
- Step k1, „A rough overview of roughly how much each supplier costs.“: For an overview, an error here and there would be tolerable. That makes it a case of summarizing.
- Step k1, „Every amount exact to the cent; the spreadsheet goes to accounting.“: Then every single value counts. A draft that someone fixes later isn’t enough.
- Step k2, „No, the invoices look different. The language model should read all 3,000.“: That’s true for the 700 invoices from small suppliers. If you say no here, you also send the 2,300 with a fixed structure through the language model.
- Step k2, „For most of them, yes: 400 invoices already contain the data, 1,900 have a fixed layout.“: Looking closely pays off: for 2,300 of 3,000 invoices, the amount is in a known place or is already available as a number.
- Step k3, „With a control rule: sum of the line items against the total; Petra checks whatever doesn’t add up.“: That way a rule checks every row, not just a few. Petra only looks where something doesn’t fit.
- Step k3, „Petra looks at 20 random invoices at the end.“: A sample shows roughly how often the model gets it wrong.
- End e1: Doesn’t fit Petra: her spreadsheet goes to accounting, where every single amount has to be right.
- End e2: Doesn’t fit: 2,300 invoices have a fixed structure. There a language model guesses piece by piece where a classic method delivers the same correct result every time.
- End e4: Doesn’t fit accounting: the sample estimates the error rate, but the wrong amounts stay in the spreadsheet. A rule that checks every row finds them.

**Question 2:** The correct answer is B.
- A: Obvious, but unnecessary: a tick in a box has a fixed structure. That’s why the real-world video from chapter 2 says they work “interestingly, not with AI” here.
- B, correct: A tick in a box has a fixed structure. For that, a classic method is faster, cheaper and more reliable.
- C: In the example from the chapter, someone really did transfer the ticks to Excel by hand until now. OMR replaces that, faster and without typos.

**Question 3:** The correct answer is C.
- A: A wrong amount can come out the same twice, too. What’s missing is a yardstick outside the model.
- B: A bigger model may make fewer mistakes, but not zero. And with 3,000 rows, nobody checks every single one anyway.
- C, correct: That’s a fixed rule that checks every row. Where the sum and the total don’t match, a person takes a look.

**Question 4:** The correct answer is A.
- A, correct: That fits: 25 amounts are quickly checked, and the task is a one-off, so a job for an AI assistant. The total comes from a formula, not from the model.
- B: Adding up is a fixed rule. A language model produces numbers piece by piece too, and can get them wrong as long as it can’t use a tool for the job, such as a program that works out the total.
- C: For 25 invoices that come up once, a dedicated process isn’t worth it. The last question of the decision chain is: does the task come up regularly?

**Card 1:** First, whether there’s a fixed structure: e-invoices with machine-readable data, or text recognition with fixed fields per layout. There you don’t need a language model. For the rest, a control rule, such as the sum of the line items against the total; a person checks whatever doesn’t add up.

**Card 2:** **False.** A language model produces numbers token by token too, and can get them wrong. The result only becomes reliable when it may use a tool, such as a program it writes and runs itself. Arithmetic, adding up totals, counting ticks: for these there are formulas and classic programs that always deliver the same correct result.
