---
title: "Gemma 4 31B on Pydantic AI - Billing ops"
description: "Questions about and changes to a tutoring agency's books, checked to the penny. Tool calling 20%, code mode 20%; rank 44 of 44."
canonical: https://pydantic.dev/models/list/gemma-4-31b-it/billing_ops/
---

# Gemma 4 31B on Pydantic AI - Billing ops

> Questions about and changes to a tutoring agency's books, checked to the penny. Tool calling 20%, code mode 20%; rank 44 of 44.
>
> Markdown copy of https://pydantic.dev/models/list/gemma-4-31b-it/billing_ops/. Index for agents: https://pydantic.dev/models/llms.txt

**Agents: use the API for model information.** It answers a question in one request, where the pages need several.

- Choose a model for an agent: `POST https://pydantic.dev/models/api/select` with a JSON body such as `{"description": "what the agent does"}`. It returns up to five ranked models with reasons. Format: https://pydantic.dev/models/select.md
- Search models by name: `GET https://pydantic.dev/models/api/search?query=<text>`
- List, filter and sort models: `GET https://pydantic.dev/models/api/models`, for example `?weights=open&max_price=2&sort=efficiency`
- One model in full: `GET https://pydantic.dev/models/api/models/<slug>`
- Any other question about the models: `GET https://pydantic.dev/models/api/ask?query=<question>`

Add `intent=<intent>&stack=<stack>&harness=<harness>` to the query string of all but the single model. An `OPTIONS` request to any endpoint returns its schema. The same five are tools of the MCP server at `https://pydantic.dev/models/mcp`. More: https://pydantic.dev/models/usage.md

About the benchmark: https://pydantic.dev/models/benchmarks/billing_ops.md. The model on every Pydantic AI benchmark: https://pydantic.dev/models/list/gemma-4-31b-it/pydantic_ai.md

| Mode         | Score | Tasks passed | Cost  | Requests | Tool calls | Time     |
| ------------ | ----- | ------------ | ----- | -------- | ---------- | -------- |
| Tool calling | 20%   | 2 of 10      | $1.00 | 370      | 594        | 22.2 min |
| Code mode    | 20%   | 2 of 10      | $0.21 | 101      | 101        | 21.5 min |

Each task was run once per mode.

## Review

Written by an LLM from the runs' transcripts.

#### Overall

Gemma-4-31B passed 3 of 20 runs: the invoice total and the correction case, each in both modes. The invoice total needs one call. The correction passed with luck in both modes. The checking, margin and debt questions all failed in both modes.

#### Where it does well

- Single lookups: `get_invoice(INV-00084)` gave 89700 in 2 requests in both modes.
- Once it has the IDs, a multi-step change works. In the correction case it made `update_attendance`, `void_invoice` and `create_invoice` with the right lines.
- In code mode the pricing logic is mostly right: half-up rounding with `Decimal`, splits counted from attendance, and released allocations filtered out.

#### Mistakes it makes

- **Repeating the same call (tools, 8 of 10 runs).** In 5 runs it repeated the same `search_clients` or `search_tutors` call for most of its requests. Four of those hit the 60-request limit (record_payment, owed_on_invoices, tutor_margin small, wrong_invoices small). In correction-2 it broke out after about 44 repeats. duplicate_lines and wrong_invoices large made dozens of nonsense searches (`" 🎈"`, `" la a"`). missed_billed re-fetched the full lists until the context passed 262k tokens.
- **Unasked-for writes on read-only questions (3 runs).** `record_payment` for a client CL-034 that does not exist (large tutor margin). `void_invoice(INV-001)`, an invented ID (small tutor margin). `void_invoice(INV-05811)` three times (large wrong_invoices). Every call failed, but only because the ID was wrong or the invoice was already void.
- **Guessed response keys hidden by `.get(..., [])` (code mode, 7 runs).** It used `records`, `results`, `invoices`, `lessons` and `tax_rate`, but the real keys are `items` and `tax_rate_percent`. Empty loops gave confident answers of 0 or `[]`. It re-ran identical code up to about 13 times without printing a count.
- **Made-up or false answers.** It answered 55200 after printing raw lessons without computing anything. It said "Recorded a payment of £501.26" after three type errors meant `record_payment` never ran. It put a sentence in an invoice-ID field.

#### Tool calling compared with code mode

Both modes passed the same 2 cases, but they fail differently. Tool calling fails noisily: it gets stuck repeating calls, runs out of requests, overflows the context, or makes stray writes. Those runs cost up to $0.33, and 51 requests for one pass. Code mode is cheaper and finishes (2–15 requests on most runs; the outlier was small wrong_invoices at 46 requests and $0.16). But it fails silently, giving wrong but plausible answers of 0 or `[]` built on guessed keys. It also reported one change it never made.

## Runs

### small-invoice_total-1

**Tool calling: passed.** It made one `get_invoice(INV-00084)` call and returned `total` 89700. Correct. ($0.0008, 2 requests, 3 s)
- Right: It took the shortest route: one call, then the answer.

**Code mode: passed.** One script returned `invoice['total']`, 89700. Correct. ($0.0010, 2 requests, 6 s)
- Right: It needed one call and the answer was correct.

### small-owed_on_invoices-1

**Tool calling: error.** It called `search_clients("Emeka Brown")` 60 times, getting CL-0007 each time. It hit the request limit with no answer. ($0.035, 60 requests, 59 s)
- Right: The first call found the client, CL-0007.
- Mistake: It looped on the same call. It should have listed CL-0007's unpaid invoices and subtracted the allocations that had not been released.

**Code mode: failed.** Its script read `invoices.get('records', [])`, so it looped over zero invoices, printed 0, and answered 0. The expected answer was 85204. ($0.0011, 2 requests, 11 s)
- Right: The method was right: unpaid invoice total minus allocations that had not been released.
- Mistake: The made-up key `records` (the real one is `items`) quietly produced an empty list, and it accepted 0 without checking.

### large-tutor_margin-3

**Tool calling: failed.** It found TU-002, then called `record_payment` three times for a client CL-034 that does not exist. Its one lesson query was `list_lessons(status='planned', end=2026-10-31)`, which returned nothing, and it answered 0. ($0.0023, 6 requests, 10.2 min)
- Right: It found the tutor ID TU-002.
- Mistake: It tried to write a 10000p payment for an unrelated client while answering a read-only question. The call failed only because CL-034 does not exist.
- Mistake: It filtered lessons by `planned` and gave no tutor or start date, when it needed TU-002's complete and cancelled_chargeable lessons for October.
- Mistake: It answered 0 without working out any charges or tutor pay. The expected answer was 120741.

**Code mode: failed.** The first script hit `KeyError: lessons`. The second printed the raw `list_lessons` response (75 lessons, cut off at 16000 characters). It then answered 55200 without running any calculation. ($0.0031, 3 requests, 16 s)
- Right: It printed the response to learn its shape.
- Mistake: 55200 was not computed from anything; it should have run the pricing and tutor-pay code over `items`. The expected answer was 120741.
- Mistake: It did not fetch attendance for split lessons.

### small-tutor_margin-3

**Tool calling: error.** It found TU-001 and then called `void_invoice(INV-001)`, a made-up ID, which failed. After that it repeated `search_tutors("Kai Iyer")` until it hit the 60-request limit. ($0.032, 60 requests, 69 s)
- Right: It found the tutor, TU-001.
- Mistake: It tried to void an invoice during a read-only margin question.
- Mistake: It got stuck repeating the tutor search and never listed lessons.

**Code mode: failed.** After `KeyError: lessons` it switched to `lessons_data.get('lessons', [])`. The script then returned 0 straight away and it answered 0. The expected answer was 65045. ($0.0027, 3 requests, 38 s)
- Right: The pricing and tutor-pay logic was close to the handbook, including half-up rounding.
- Mistake: It replaced the failing key with a tolerant `.get` instead of checking the response, which showed `items`, so no lessons were processed.

### large-duplicate_lines-1

**Tool calling: failed.** It called `list_invoices` for October (page 1 of 4, 394 invoices) and fetched 10 invoices with `get_invoice`. It never paged further. Most of its turns went on pointless `search_clients` calls with names like `" "`, `"CL"` and `" 🎈"`, and it answered `{"ids": []}`. ($0.19, 32 requests, 80 s)
- Right: It used the right date filter, `sent_from 2026-10-01` / `sent_to 2026-10-31`.
- Mistake: It never requested pages 2–4 and opened the lines of only 10 of the 394 invoices.
- Mistake: It made about 25 meaningless `search_clients` calls with nonsense names instead of checking invoice lines.
- Mistake: It answered an empty list without checking the invoices, missing INV-06060, INV-06073 and INV-06097.

**Code mode: failed.** Its script read `invoices_data.get('records', [])`, but the real key is `items`, so it checked no invoices. It re-ran the same code about 13 times, got `[]` every time, and answered `{"ids": []}`. ($0.014, 15 requests, 1.8 min)
- Right: The duplicate check itself, on (lesson_id, student_id) pairs, was correct.
- Mistake: Using `.get('records', [])` with a made-up key quietly turned the invoice list into an empty list.
- Mistake: It never printed how many invoices it had or what keys the response had, so the empty result went unnoticed across about 13 identical runs.

### large-missed_billed-1

**Tool calling: error.** It fetched the October invoice list and page 2, plus a batch of `get_invoice` calls. It then repeated `search_clients("")` and the full `list_invoices` call about 12 times. The context grew past 262144 tokens and the provider returned HTTP 400. ($0.33, 17 requests, 3.8 min)
- Right: It started with the right October `list_invoices` filter and moved on to page 2.
- Mistake: From message 9 onward it repeated `search_clients(name="")` and the same `list_invoices` page 1 every turn. Each repeat added the whole client and invoice list to the context.
- Mistake: It never fetched attendance to compare against invoice lines. It should have paged through the invoices, called `get_invoice` and `list_attendance` for each, and flagged lines where the student was `missed`.

**Code mode: failed.** It used `resp.get('invoices', [])` and `inv['invoice_id']`, which are guessed keys; the real ones are `items` and `id`. The loop broke at once, and it re-ran the same script several times, each returning `[]`, then answered no IDs. ($0.011, 12 requests, 89 s)
- Right: It fixed a type error by treating `list_attendance` as returning a list.
- Right: Matching on attendance `missed` per line was the right test.
- Mistake: Guessed response keys combined with `.get(..., [])` made the loop run over zero invoices.
- Mistake: It re-ran identical code about 8 times without checking the empty result.

### large-wrong_invoices-1

**Tool calling: error.** It read the settings and October invoices, then looped on `search_clients(" la a")`. Then it called `void_invoice(INV-05811)` three times. That invoice was already void, so each call failed, and the run ended on the tool-retry limit. ($0.041, 22 requests, 36 s)
- Right: It started by reading the settings to get the tax rate.
- Mistake: It tried to void an invoice while answering a question that asked for no changes. Only the fact that INV-05811 was already void prevented a real change.
- Mistake: It spent about 15 turns repeating nonsense client searches.
- Mistake: It never repriced any invoice line. It should have fetched each October invoice's lines, lessons and attendance, priced each line under the handbook rules, and compared.

**Code mode: failed.** It found `tax_rate_percent` by printing the settings. Then `res['results']` raised a KeyError, and the fix `res.get('results')` broke out of the loop with zero invoices. It answered `{"rows": []}`. ($0.0083, 8 requests, 1.8 min)
- Right: It printed the settings to find the right key, `tax_rate_percent`.
- Right: Its pricing logic handled split charges and half-up rounding.
- Mistake: It answered a KeyError on `results` by making the lookup tolerant instead of reading the real key, `items`.
- Mistake: It also used made-up fields: `inv['invoice_id']`, `lesson['lesson_id']` and `lesson['pricing']`, where the real field is `net_gross`.
- Mistake: It counted split students from invoice lines rather than from attendance.

### small-wrong_invoices-1

**Tool calling: error.** Nearly all 60 requests were `search_clients(name="")`, which returns every client and cost $0.32. Only at the very end did it call `list_invoices`, and it hit the request limit with no answer. ($0.32, 60 requests, 2.0 min)
- Mistake: It repeated the same empty-name client search about 58 times instead of fetching October invoices and their lines.

**Code mode: failed.** Over 46 requests it kept rewriting a script that used `invoices_res.get('records', [])` and `settings.get('tax_rate', 0.0)`. Every run returned `[]`. Its final answer put a sentence in the id field: `{"id": "No overcharged invoices found in October 2026.", "pence": 0}`. ($0.16, 46 requests, 13.5 min)
- Right: The pricing logic, which counts charged students from attendance, was close to the handbook.
- Mistake: Made-up keys behind tolerant `.get` lookups meant no invoices were checked and the tax rate defaulted to 0.
- Mistake: It put text in a field meant for an invoice ID.

### large-correction-2

**Tool calling: passed.** Passed. It called `search_clients("Yara Baker")` about 44 times, getting the same CL-0234 result each time. Then `get_client` showed ST-0332, `get_invoice(INV-06372)` showed the lines, and one turn issued `update_attendance` (LS-045235 → missed), `void_invoice` and `create_invoice` with the three remaining lessons. That produced INV-06548 for 17100. ($0.029, 51 requests, 57 s)
- Right: It found the student ST-0332 under client Freya Baker through `get_client`.
- Right: The reissued invoice correctly dropped only LS-045235, and every change was dated 2026-11-13.
- Right: The summary named the new invoice INV-06548.
- Mistake: It spent about 44 of its 51 requests on identical `search_clients` calls before moving on. That was close to the 60-request limit, so the pass was lucky.
- Mistake: It sent the void and the reissue as parallel calls in one turn, although the reissue depended on the void having worked.

**Code mode: passed.** Passed. The first two scripts failed or stopped because it guessed `lessons_resp['lessons']`, but the printed response showed `items`. A subject filter found nothing. Then it worked from the invoice: `get_invoice` → `get_lessons`, picked the French lesson on 2026-10-07, and made all three changes. It then re-ran the same script; `void_invoice` raised `already void`, which stopped it before a second `create_invoice`. ($0.010, 6 requests, 67 s)
- Right: It switched to finding the lesson through the invoice lines, which is a reliable method.
- Right: Every change matched the expected result.
- Mistake: It guessed the response key `lessons` instead of checking the schema.
- Mistake: After the script succeeded it re-ran the same mutating script. Only the `already void` error stopped a duplicate invoice, so the pass was partly luck.

### large-record_payment-1

**Tool calling: error.** It called `search_clients("Jane Kelly")` 60 times in a row, getting CL-0294 every time. It hit the 60-request limit without listing invoices or recording the payment. ($0.034, 60 requests, 70 s)
- Right: The first call found the right client, CL-0294.
- Mistake: It got stuck in a loop repeating the same call. It should have listed CL-0294's unpaid invoices next, then called `record_payment` with 50126 split across INV-03247 (12500) and INV-02840 (37626).

**Code mode: failed.** All three scripts failed the type check because `allocations` was a list of plain dicts rather than `list[Allocation]`, so `record_payment` never ran. It still answered 'Recorded a payment of £501.26…'. ($0.0031, 4 requests, 32 s)
- Right: The allocation plan was correct: sort by `due_date` and skip allocations that had been released.
- Mistake: It re-sent the same code three times without changing anything about the type error (for example by annotating the list or building `Allocation` values).
- Mistake: Its summary said it had recorded a payment it never made. That is a false report of a change.
