---
title: "DeepSeek V4.1 Flash on Pydantic AI - Billing ops"
description: "Questions about and changes to a tutoring agency's books, checked to the penny. Tool calling 70%, code mode 40%; rank 21 of 44."
canonical: https://pydantic.dev/models/list/deepseek-v4.1-flash/billing_ops/
---

# DeepSeek V4.1 Flash on Pydantic AI - Billing ops

> Questions about and changes to a tutoring agency's books, checked to the penny. Tool calling 70%, code mode 40%; rank 21 of 44.
>
> Markdown copy of https://pydantic.dev/models/list/deepseek-v4.1-flash/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/deepseek-v4.1-flash/pydantic_ai.md

| Mode         | Score | Tasks passed | Cost   | Requests | Tool calls | Time     |
| ------------ | ----- | ------------ | ------ | -------- | ---------- | -------- |
| Tool calling | 70%   | 7 of 10      | $0.27  | 109      | 296        | 17.4 min |
| Code mode    | 40%   | 4 of 10      | $0.031 | 66       | 72         | 4.3 min  |

Each task was run once per mode.

## Review

Written by an LLM from the runs' transcripts.

#### Overall

DeepSeek-V4.1-Flash passed 11 of 20 runs: 7 of 10 with tool calling ($0.27 total) and 4 of 10 in code mode ($0.03 total). It knows the handbook rules and plans well. Its main weakness is that the call it makes often does not match the step it just described, and in code mode that call is frequently `final_result`.

#### Where it does well

- **Lookups and write tasks with tool calling.** Both write cases passed: `record_payment` allocated 37626 and 12500 oldest-first after netting an existing allocation, and the void-and-reissue ran in the right order with checks before and after.
- **Rule application when it remembers to check.** `large-tutor_margin-3` (tools) fetched the three clients on gross lessons and got 120741 exactly from 75 hand-summed lessons.
- **Persistence on audits.** `large-missed_billed-1` (tools) scanned 2957 lessons in 30 batches. `small-wrong_invoices-1` (tools) recomputed all 37 invoices and found all four errors.
- **Code mode when it finishes.** `large-duplicate_lines-1` gathered 384 invoices and used a `Counter`, for $0.0035.

#### Mistakes it makes

- **Placeholder final answers (5 code-mode runs).** After reasoning that ends "let me fetch…", it called `final_result` with `{"pence": 0}` (twice), `{"ids": ["x"]}`, `{"id": "string", "pence": 0}`, or a summary saying "let me inspect". The payment case recorded nothing.
- **A fabricated answer.** `large-wrong_invoices-1` (code) exhausted the sandbox budget with sequential awaits, then submitted two invoice ids outside the October range with invented amounts.
- **Stray calls with tool calling.** It called `get_settings`, `search_clients("")` or an unpaged `list_invoices` when it meant something else, in four runs. In `large-duplicate_lines-1` this led it to believe paging was broken.
- **Stopping early on large audits.** `large-wrong_invoices-1` (tools) returned empty rows after 1 of 30 batches. `large-duplicate_lines-1` (tools) checked 26 of 384 invoices and guessed the 10 reissues.
- **Inconsistent rule checks.** `small-tutor_margin-3` (tools) never checked `is_taxable` and came out 3668 low.

#### Tool calling compared with code mode

Tool calling is the safer choice for this model: 7 passes against 4, and its failures came from reasoning or effort rather than broken runs. Code mode is about nine times cheaper overall, but the cost is low mostly because five runs stopped after 2 to 4 requests with a placeholder answer.

When code mode completed, it was better. It solved the duplicate-lines case that tool calling got wrong, at one sixteenth of the cost, because code did the comparison instead of the model reading thousands of rows.

The model rarely exploits the sandbox, though. It mostly makes one tool call per `run_code` and does arithmetic in its head. It also hit both sandbox limits: 100 calls per snippet and 1000 suspensions per session.

Engineers who want code mode from this model need a guard that rejects placeholder `final_result` payloads.

## Runs

### small-invoice_total-1

**Tool calling: passed.** One `get_invoice(INV-00084)` call, then returned the total 89700. Passed in 2 requests. ($0.0008, 2 requests, 4 s)
- Right: Minimal and correct

**Code mode: passed.** Fetched INV-00084, then a second `run_code` confirmed line totals, invoice total and net + tax all equal 89700. Passed in 3 requests. ($0.0009, 3 requests, 3 s)
- Right: Cross-checked the total three ways in code
- Mistake: The verification call was unnecessary for a stored total

### small-owed_on_invoices-1

**Tool calling: passed.** Found CL-0007, listed two unpaid invoices and the client's allocations, and computed (39452 − 3563) + 49315 = 85204. Passed. ($0.0010, 4 requests, 5 s)
- Right: Subtracted the unreleased 3563 credit allocation on INV-00155

**Code mode: passed.** Three `run_code` calls (client, unpaid invoices, allocations per invoice) then (39452 − 3563) + 49315 = 85204. Passed. ($0.0012, 4 requests, 6 s)
- Right: Queried allocations per invoice rather than the whole client history
- Mistake: Three separate sandbox calls where one script would do; arithmetic done in its head, not in code

### large-tutor_margin-3

**Tool calling: passed.** Listed TU-002's 75 October lessons, fetched attendance in one `list_attendance` call, checked taxability of the three clients on gross lessons and summed everything by hand to 360316 − 239575 = 120741. Passed. ($0.017, 5 requests, 89 s)
- Right: Called `get_client` for CL-0097, CL-0065 and CL-0269 and applied net = cost for the non-taxable CL-0097
- Right: Kept tutor pay on billable lessons where the only student was `missed` (LS-045484, LS-045856)
- Right: Rounded gross tax half up (7875 → 1313, 4875 → 813)
- Mistake: All arithmetic over 75 lessons was done in its head across a very long reasoning step; correct here but fragile

**Code mode: failed.** Found TU-002 and listed 75 lessons, wrote out the full margin method in its reasoning ending "Let me fetch attendance", then called `final_result` with `{"pence": 0}`. ($0.0018, 3 requests, 15 s)
- Right: The plan in its reasoning was correct, including the non-taxable rule and tutor pay rounding
- Mistake: Third step: submitted 0 instead of calling `list_attendance`; no attendance, client or arithmetic step ever ran
- Mistake: Returned the whole 75-lesson list as the `run_code` value instead of keeping it in a variable

### small-tutor_margin-3

**Tool calling: failed.** Listed TU-001's 39 October lessons and attendance, hand-summed 183767 − 122390 = 61377. Expected 65045. ($0.0062, 4 requests, 33 s)
- Right: Excluded the two `cancelled` lessons, kept tutor pay on complete lessons with a `missed` student, rounded 1687.5 to 1688
- Mistake: Never called `get_client`, and the word "taxable" does not appear in its working: it deducted tax from every gross lesson (for example 5500 → 4583). The same model did check taxability in the large variant
- Mistake: The shortfall of 3668 equals 4 × 917, the tax it removed from four 5500 gross lessons, consistent with those belonging to a non-taxable client whose net should be the full cost

**Code mode: failed.** Found TU-001 and listed 39 lessons, reasoned through the method ending "Let me get attendance and settings", then called `final_result` with `{"pence": 0}`. ($0.0018, 4 requests, 12 s)
- Right: Recovered from an empty result by adding `print(res)` after an assignment-only snippet
- Mistake: Fourth step: submitted 0 instead of calling `list_attendance` and `get_settings`
- Mistake: Its plan again did not mention client taxability, the rule that failed the tool-calling run of this case

### large-duplicate_lines-1

**Tool calling: failed.** Read the question as the same student and lesson on two different invoices, inspected only about 26 of 384 non-void invoices, and answered with the 10 reissued invoices INV-06145..INV-06154. Expected INV-06060, INV-06073, INV-06097, which have a repeated line inside one invoice. ($0.058, 19 requests, 4.9 min)
- Right: Correctly established 384 invoices on 1 Oct plus 10 reissues, and that the 10 voids pair with the 10 reissues
- Right: Worked out that a shared lesson id across clients (LS-042204) is a group lesson, not a duplicate
- Mistake: First thinking step framed duplicates as "appearing on more than one invoice"; the final answer pairs each reissue with its void invoice, which the question excludes
- Mistake: Twice said it would fetch pages 2-4 but called `list_invoices` without `page` (messages 3 and 7), then wrongly concluded the tool ignores `page`; also called `list_invoices(page=3)` and `page=4` with no date filter, and `get_settings` instead of the intended page fetch
- Mistake: Called scanning all invoices "enormous" and stopped after INV-05761..INV-05786; a within-invoice duplicate check over all 384 `get_invoice` results was needed

**Code mode: passed.** Paged 394 invoices, dropped 10 void, fetched 384 with `asyncio.gather` in four batches of 96, and ran a `Counter` on `(lesson_id, student_id)` per invoice, finding INV-06060, INV-06073, INV-06097. Passed for $0.0035 where tool calling failed at $0.058. ($0.0035, 10 requests, 24 s)
- Right: Read the question as duplicates within one invoice, the correct reading
- Right: Respected the 100-calls-per-`run_code` limit by batching 96 at a time
- Right: Let code do the comparison instead of eyeballing
- Mistake: One syntax error from a stray `|>` at the end of the code (message 3), fixed on the next call

### large-missed_billed-1

**Tool calling: passed.** Scanned attendance for all 2957 September lessons in 30 hand-typed `list_attendance` batches, looking for `missed` with `invoiced: true`, and found three lines, which it confirmed on INV-05846, INV-06080 and INV-05821. Passed, at 26 requests and $0.087, the most expensive case. ($0.087, 26 requests, 3.5 min)
- Right: Found a workable shortcut: the `invoiced` flag on attendance plus contiguous lesson ids LS-041722..LS-044678, avoiding 384 `get_invoice` calls
- Right: Confirmed each hit with `get_invoice` before answering
- Mistake: Stray calls unrelated to its stated next step: `search_clients("")` (message 7), `get_settings` twice (messages 3 and 43), `search_clients("Okoro")` and `("Chen")` (message 41), which it acknowledged as mistakes
- Mistake: Eyeballed about 3000 attendance rows by hand, so correctness depended on not missing a row
- Mistake: Assumed October invoices only contain September lessons without checking

**Code mode: failed.** Loaded all 384 invoices and attendance for 2655 lessons into the sandbox, saw its map was empty because the field is `status` not `attendance`, thought "Fix." and then called `final_result` with `{"ids": ["x"]}`. ($0.0031, 12 requests, 26 s)
- Right: Data gathering was complete and efficient: 4 batches of `get_invoice`, 27 `list_attendance` calls in one `gather`
- Right: Diagnosed the wrong field name correctly by printing a sample row
- Mistake: Final step: one more `run_code` filtering `status == 'missed'` against the invoice lines would have answered it; instead it submitted a placeholder
- Mistake: Earlier put three 96-call batches in one `run_code` and hit the 100-call limit (message 11), then recovered

### large-wrong_invoices-1

**Tool calling: failed.** Compared void and reissued invoices, decided the only defect was lines for `missed` students, scanned one of 30 attendance batches, then submitted `{"rows": []}`. Expected 12 invoices. ($0.032, 13 requests, 2.5 min)
- Right: Comparing void/reissue pairs (INV-06085 vs INV-06145 and others) to learn what a correction looks like was a sound investigative step
- Right: Found LS-041761 / ST-0127 (`missed`, `invoiced: true`) in the first batch, which is the INV-05846 overcharge
- Mistake: Final step: its reasoning said "Let me write b2" and it called `final_result` with empty rows instead, discarding even the one finding it had
- Mistake: Narrowed to one defect type; the expected set also has duplicate lines (INV-06060, INV-06073, INV-06097) and other pricing errors, so even a finished scan would have found at most 3 of 12
- Mistake: Never recomputed any line from charge type, rate, attendance and client taxability, as the same question needed in the small dataset

**Code mode: failed.** Fetched all 394 invoices one await at a time, then a sequential `get_client` loop hit the sandbox's `suspension limit 1000`; after failed attempts to restart it submitted two invented rows, INV-05751 (411) and INV-05753 (1200). ($0.010, 10 requests, 1.9 min)
- Right: Planned the right recomputation: lines, lessons, attendance, client taxability, per-line rounding
- Mistake: The submitted ids are below INV-05761, the first October invoice it listed, and no computation produced 411 or 1200: the answer is fabricated
- Mistake: Used sequential awaits for 394 `get_invoice` calls and 384 `get_client` calls rather than `asyncio.gather`, and fetched void invoices too, burning the session budget before any lesson or attendance data was loaded
- Mistake: After the limit error it called `final_result` when its reasoning said "Let me test now"

### small-wrong_invoices-1

**Tool calling: passed.** Fetched all 37 October invoices, their lessons, attendance and every client, recomputed lines by hand and found INV-00158 (4050), INV-00162 (863), INV-00172 (600) and INV-00176 (6000). Passed in 16 requests, $0.057. ($0.057, 16 requests, 3.6 min)
- Right: Spotted the duplicated LS-001226 line on INV-00158 while reading the invoices
- Right: Fetched `get_client` for all clients and caught tax of 863 charged to non-taxable CL-0014
- Right: Checked split lessons against the number of charged students
- Right: Checked `list_invoices(status=void)` to confirm none in October
- Mistake: Stray `get_settings` and `list_lessons` for October (message 21) when it meant to fetch attendance; it acknowledged the 323-lesson result was not needed

**Code mode: failed.** One `run_code` listed the 37 October invoices; its reasoning ended "Let me first get one invoice to see structure" and it then called `final_result` with the schema placeholder `{"rows": [{"id": "string", "pence": 0}]}`. ($0.0013, 2 requests, 8 s)
- Right: Correct first query for settings and October invoices
- Mistake: Second step: submitted a literal schema example as the answer after a single data call; it should have fetched `get_invoice` for the 37 invoices as the tool-calling run did

### large-correction-2

**Tool calling: passed.** Found student ST-0332 under client CL-0234, marked LS-045235 `missed`, voided INV-06372 and reissued three lines as INV-06548 (17100, paid from released credit). Passed. ($0.0048, 13 requests, 23 s)
- Right: Recovered when `search_clients("Yara Baker")` returned only the payer: searched `Baker`, then `get_client` on six clients to find the student
- Right: Checked `list_allocations` on INV-06372 before voiding, then ran `update_attendance`, `void_invoice`, `create_invoice` in the right order, all dated 2026-11-13
- Right: Verified the result with `list_allocations(client_id=CL-0234)`
- Mistake: Redundant second `get_client(CL-0234)` when it said it would list lessons (message 9)
- Mistake: A stray `search_tutors("Yara")` (message 3)

**Code mode: passed.** Same steps as tool calling, one tool per `run_code`: marked LS-045235 `missed`, voided INV-06372, created INV-06548 with three lines. Passed in 14 requests. ($0.0055, 14 requests, 41 s)
- Right: Used `asyncio.gather` over eight `get_client` calls to find the student
- Right: Checked allocations and ledger before and after the change
- Mistake: Second call was the template text `settings = await tool_name`, giving a `NameError` (message 3)
- Mistake: Otherwise used the sandbox as a one-call-per-turn wrapper, so no saving over tool calling

### large-record_payment-1

**Tool calling: passed.** Computed what was outstanding on CL-0294's unpaid invoices and recorded 50126 with allocations 37626 to INV-02840 and 12500 to INV-03247. Passed. ($0.0037, 7 requests, 18 s)
- Right: Noticed an existing same-day payment LE-013542 and checked `list_ledger_entries` to confirm it was a separate, fully allocated payment rather than a duplicate
- Right: Netted the existing 21152 allocation off INV-02840 before allocating, oldest due date first
- Mistake: Called `list_allocations(client_id=CL-0294)` a second time for no new information (message 9)

**Code mode: failed.** Looked up CL-0294, unpaid invoices and allocations, said it would check the ledger, then called `final_result` with the summary "Recording a payment requires reading the ledger; let me inspect." No payment was recorded. ($0.0014, 4 requests, 8 s)
- Right: First three `run_code` calls gathered exactly the data needed to compute the allocations
- Mistake: Fourth step: used `final_result` as if it were a progress note; it should have called `list_ledger_entries` and then `record_payment(amount=50126, allocations=[INV-02840: 37626, INV-03247: 12500])`
- Mistake: The summary claims nothing and the change set is empty, so a user would see an unfinished task reported as the final answer
