---
title: "Gemini 3.8 Flash on Pydantic AI Transit Planner"
description: "Journey planning over a real Dresden public transport timetable, with an SVG map of each answer. Tool calling 90%, code mode 90%; rank 10 of 32."
canonical: https://models.pydantic.dev/models/gemini-3.8-flash/transit_planner/
---

# Gemini 3.8 Flash on Pydantic AI Transit Planner

> Journey planning over a real Dresden public transport timetable, with an SVG map of each answer. Tool calling 90%, code mode 90%; rank 10 of 32.
>
> Markdown copy of https://models.pydantic.dev/models/gemini-3.8-flash/transit_planner/. Index for agents: https://models.pydantic.dev/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://models.pydantic.dev/api/select` with a JSON body such as `{"description": "what the agent does"}`. It returns up to five ranked models with reasons. Format: https://models.pydantic.dev/select.md
- Search models by name: `GET https://models.pydantic.dev/api/search?query=<text>`
- List, filter and sort models: `GET https://models.pydantic.dev/api/models`, for example `?weights=open&max_price=2&sort=efficiency`
- One model in full: `GET https://models.pydantic.dev/api/models/<slug>`
- Any other question about the models: `GET https://models.pydantic.dev/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://models.pydantic.dev/mcp`. More: https://models.pydantic.dev/usage.md

About the benchmark: https://models.pydantic.dev/benchmarks/transit_planner.md. The model on every Pydantic AI benchmark: https://models.pydantic.dev/models/gemini-3.8-flash.md

| Mode         | Score | Tasks passed | Cost  | Requests | Tool calls | Time     |
| ------------ | ----- | ------------ | ----- | -------- | ---------- | -------- |
| Tool calling | 90%   | 9 of 10      | $4.45 | 615      | 615        | 59.7 min |
| Code mode    | 90%   | 9 of 10      | $3.99 | 546      | 546        | 53.3 min |

Each task was run once per mode.

## Review

Written by an LLM from the runs' transcripts.

#### Overall

18 of 20 runs passed: 9 of 10 in tool calling and 9 of 10 in code mode. The two failures are different cases. `tour` in tool calling hit the 80-request limit with no answer. `departure_profile` in code mode returned the right journeys with several times 1 second low. Runs are long: 61.5 requests on average in tool calling ($4.45 total) and 54.6 in code mode ($3.99 total). Five passing runs used 71 to 78 of the 80 requests.

#### Where it does well

- **Timetable rules.** Every run handled service days, repeats named `<run>+<k>`, untimed-call interpolation, the 400 m walk limit and the 120 s change margin. `after_midnight` correctly shifted day-338 runs by 86400 in both modes.
- **Walks.** It found the non-obvious ones: a 399 s start walk in `one_vehicle`, platform-to-platform changes in `walking_change`, `arrive_by` and `after_midnight`.
- **Verification.** It usually searched one leg deeper than the answer and re-checked chosen legs against raw `calls.txt`.

#### Mistakes it makes

- **Slow, one-step-at-a-time work.** One statement per request, many bare `count(*)` checks, and repeated single-run inspections. This caused the `tour` failure and left `timed_tour`, `walking_change` and `meeting_point` within 2 to 9 requests of the limit.
- **Rounding.** In `departure_profile` (code mode) float division inside `math.floor` is the probable cause of 25326 instead of 25327; its own check reused the same numbers.
- **Unproven optimality.** `timed_tour` was built hop by hop in one visit order in both modes. The `tour` tool-calling search capped each hop at two vehicles and was heading for 49560, against 48660 found in code mode.
- **Repeated slips.** The reserved word `at` unquoted in SQL in at least 11 runs; a write outside `/out/`; SVGs of 69 KB and 173 KB.
- **Off-task probing in code mode.** Four runs listed `/` or looked for git history and "previous prompts".

#### Tool calling compared with code mode

Same pass count, but code mode is the better fit for search-heavy cases. On `tour` it wrote a connection-scan router and tried all 120 orders in 58 requests, where tool calling ran out at 80. `meeting_point` took 53 requests against 73. Code mode has its own risks: the float rounding failure, a `MemoryError` at 268 MB in `timed_tour` that forced a reload, and unsupported calls (`time.time()`, `subprocess`, `xml.parsers.expat`). Tool calling was cheaper only on `one_vehicle` (31 against 41 requests) and gave exact integer times because DuckDB did the arithmetic.

## Runs

### one_vehicle

**Tool calling: passed.** Found no direct run between the two stations, widened to platforms within 400 m and answered bus `R27f8d4b1+2` from `P0091960a` after a 399 s walk, departure 29541. Passed in 31 requests, the fewest of any case. ($0.42, 31 requests, 6.1 min)
- Right: Recognised the single-vehicle journey needs a start walk and set departure to 29940 - 399 = 29541
- Right: Expanded repeats inline in one CTE instead of materialising every table
- Mistake: `JOIN runs r ON c1.run = r.run` failed (the column is `ref`), message 13
- Mistake: Cost $0.42 for 31 requests, high per request because of large result sets (for example `SELECT rep.* FROM repeats JOIN runs`, message 39)

**Code mode: passed.** Found the walk to `P0091960a` and bus `R27f8d4b1+2`, departure 29541, arrival 30480, the same as tool calling. Passed in 41 requests against 31 for tool calling. ($0.30, 41 requests, 4.9 min)
- Right: Grepped `DATA.md` for the departure rule before fixing departure as board time minus walk
- Right: Checked the SVG text for the required `data-place` and `data-run` attributes
- Mistake: Off-task probing of the sandbox: `os.listdir('/')` (error), then `subprocess.run(['git', 'log', ...])` (error) at messages 55-60
- Mistake: `xml.parsers.expat` is not available (message 78)
- Mistake: Wrote a 69 KB SVG with every station as a background dot, which bloats the final output

### saturday_direct

**Tool calling: passed.** Found tram 9 run `Rb28d92d7` from `P7fa04a55` at 33484 to `P1093f876` at 34560 and confirmed no 2-leg journey beats it. Passed in 54 requests. ($0.35, 54 requests, 4.7 min)
- Right: Recomputed the interpolated time 33484 by hand from segment distances (messages 35 and 83)
- Right: Checked start and end walks and a 2-leg join before answering a direct ride
- Mistake: The answer was visible by message 66; about 20 more requests re-inspected individual runs (`R2aa4cdd7+1`, `Re6e69040`, `Ree22098b+2`, `Rebc40153`, `R4ffe86eb`) and re-read `Rb28d92d7` three times
- Mistake: Queried `service_changes` after not loading it (`Table with name service_changes does not exist`, message 79); the active-service filter never applied changes, harmless here because no change falls on day 339

**Code mode: passed.** Loaded tables with SQL, then searched 1-, 2- and 3-leg journeys in Python and answered the direct tram `Rb28d92d7`, 33484 to 34560. Passed in 43 requests. ($0.27, 43 requests, 4.1 min)
- Right: Confirmed no 2-leg or 3-leg journey arrives before 34560
- Right: Recomputed the interpolation distances (`d_170_180: 534`, ...) for the boarding time 33484
- Mistake: Looked for 'hidden files or git history or previous prompts' with `os.listdir` (message 33, runtime error)
- Mistake: One unterminated-string SQL error (message 20) and the `at IS NULL` reserved-word error (message 14)

### one_change

**Tool calling: passed.** Interpolated and expanded calls, ran 1-vehicle and 2-vehicle queries with start, transfer and end walks, and answered `Rafeef850` then `R620ec7d9`, arriving 28440. Passed in 53 requests. ($0.36, 53 requests, 5.5 min)
- Right: Applied `service_changes` in `active_services`
- Right: Verified the interpolated boarding time 27669 at `P0708873e` from the raw calls of `Rafeef850`
- Mistake: Tried `read_csv('/data/DATA.md', sep='|')` to grep the rules (message 47); it failed and was not needed
- Mistake: Seven queries (messages 87-101) fetched station lists, tram counts and sample tram paths purely as SVG background
- Mistake: `max(at)` reserved-word error at message 17

**Code mode: passed.** Explored with SQL, then loaded everything in Python, enumerated 45 one-vehicle and 3,596 two-vehicle journeys and answered arrival 28440 via `Rafeef850` and `R620ec7d9`. Passed in 44 requests. ($0.28, 44 requests, 3.8 min)
- Right: Printed the segment-by-segment distance sum for `Rafeef850` to confirm the interpolated 27669
- Right: Compact 2 KB SVG
- Mistake: Did the active-run counting twice, first in SQL (messages 27-41) and then again in Python (messages 47-53)
- Mistake: `max(at)` reserved-word error at message 11

### walking_change

**Tool calling: passed.** Built leg candidates and a staged reachability search (`reach_leg1`, `board_leg2`, `reach_leg2`, `board_leg3`) and answered `R76d2117b+4` then `R3a0dccd4+54` with a walk from `P6e794064` to `P72ccec8b`, arriving 63480. Passed in 74 requests. ($0.53, 74 requests, 6.2 min)
- Right: Checked that runs arriving just before 63480 (`Rd49d751b+59`, `R52ef239e+30`, `Rce63e9d0+7`, `R77afbc0f+67`) cannot be caught
- Right: Extended the search to a third leg before accepting the 2-leg answer
- Mistake: First `write_file` went to a path outside `/out/` (`files can only be written under /out/`, message 144), so the whole 6 KB SVG was sent twice
- Mistake: Four near-identical `WITH target_calls` queries, one per target run (messages 89-95), instead of one query over all four
- Mistake: 74 of 80 requests

**Code mode: passed.** Explored with SQL, then searched up to 3 legs in Python with a walk graph and answered the same journey as tool calling, arrival 63480. Passed in 65 requests. ($0.45, 65 requests, 4.4 min)
- Right: Checked 57 candidate arrivals before 63480 and the alternative via Tharandter Straße before accepting the answer
- Right: Verified `data-place` and `data-run` attributes by regex on the written SVG
- Mistake: Twelve SQL exploration requests (messages 11-35) duplicated what the Python load then recomputed
- Mistake: Wrote a 173 KB SVG with every stop as a background dot; the final output is over 200,000 characters
- Mistake: One runtime error while printing journeys (message 76)

### after_midnight

**Tool calling: passed.** Built DuckDB tables for both service days (`2026-338` shifted by -86400 and `2026-339`), searched 1-, 2- and 3-leg joins and returned `R93fefd15` then `R900bf42f+2`, arriving 6420. Passed in 65 requests. ($0.49, 65 requests, 6.1 min)
- Right: Handled the previous service day correctly: `active_runs` carried a `day_offset` of 86400 for `2026-338` runs
- Right: Used the 74 m walk between `P96dc02de` and `P983fcb99` at Südhöhe for the change
- Right: Checked 3-leg joins and feeder runs into earlier arrivals (`R181e1950`, `R59c237c0`) before settling
- Mistake: Read `DATA.md` twice (messages 1 and 3) and hit the reserved-word error on `count(at)` (message 21)
- Mistake: About 15 one-off `SELECT ... WHERE c.run = '...'` inspections of single runs (messages 43-59, 77-87), one request each, instead of one join

**Code mode: passed.** Loaded the files in Python, built run instances for service days 338 (offset -86400) and 339, searched 1- to 3-leg journeys and returned the same answer as tool calling, arrival 6420. Passed in 51 requests. ($0.42, 51 requests, 5.5 min)
- Right: Correct two-service-day handling in Python
- Right: Checked whether any earlier arrival at Wasaplatz could be reached (`Found journeys to targets: 0`) and ran a 3-leg search
- Mistake: One `Runtime error` while precomputing walk pairs (message 44)
- Mistake: Around ten single-run print-outs (messages 55-75) after the 2-leg search already gave 6420
- Mistake: Wrote a 12.8 KB SVG

### arrive_by

**Tool calling: passed.** Interpolated all calls in SQL, built `leg1_options` and searched 2- and 3-leg joins for the latest departure arriving by 64800; answered departure 63360, arrival 64440. Passed in 51 requests. ($0.24, 51 requests, 4.2 min)
- Right: Tested DuckDB `IGNORE NULLS` window syntax on a `VALUES` toy before using it for interpolation
- Right: Explicitly searched departures after 63360 (`depart_after_63360`, `leg2_after_63360`, a 3-leg join) to prove nothing later works
- Right: Used the walk `P3b6efaff` to `P6ea0167f` at Straßburger Platz
- Mistake: `SELECT count(*) FROM calls WHERE at IS NULL` failed on the reserved word `at` (message 23), a mistake repeated in most runs
- Mistake: Several sanity queries with no use later (`DISTINCT access`, `at IS NOT NULL AND dwell IS NULL`), and two queries for Elbe/ferry places only to decorate the SVG

**Code mode: passed.** Interpolated in Python, enumerated 1,105 first legs and 4,050 2-leg journeys, then ran a frontier search up to 4 legs for departures at or after 63360; answered departure 63360, arrival 64440. Passed in 48 requests. ($0.31, 48 requests, 4.1 min)
- Right: Asserted that first and last calls of every run are timed before interpolating
- Right: Explored up to 4 legs for later departures and inspected the near misses (`R0e4beb23`, `R2d3055ed+34`)
- Right: Read back `/out/journey.svg` before answering
- Mistake: Printed `data_md` in three slices (messages 5-9), the last one empty
- Mistake: One `Runtime error` (message 70) from using `run_info` before defining it

### departure_profile

**Tool calling: passed.** Built 2-leg and 3-leg journey tables in SQL, filtered the Pareto set with `NOT EXISTS`, and returned 12 journeys from 25327 to 28620. Passed in 63 requests. ($0.43, 63 requests, 6.3 min)
- Right: Interpolation done in SQL with `::BIGINT` casts gave `P8e65d0ee` departures 25327, 25927, ... which the grader accepted
- Right: Checked 3-leg journeys (681,154 rows) and journeys leaving after 08:00 (up to 30000) so later dominating journeys were considered
- Right: Re-verified every chosen leg against `all_calls` in one `UNION ALL` query (message 113)
- Mistake: Dropped `28669 -> 31063` and `28767 -> 31980` from `pareto_2leg` only after a second Pareto query over 28600-30000; the first filter was limited to departures up to 28800 and so was wrong at the edge
- Mistake: Around 8 count-only queries (messages 75-84) that did not change the plan

**Code mode: failed.** Built the profile in Python with 2-leg and 3-leg searches plus a connection-scan check and returned 12 journeys, but with departures 25326, 25926, 26526, ... where tool calling got 25327, 25927, 26527. Marked failed. ($0.44, 65 requests, 5.9 min)
- Right: Dominance logic and the journey set match the passing tool-calling run: same 12 departure/arrival pairs apart from the 1-second offsets
- Right: Cross-checked every arrival with `run_csa` (`Match: True` for all, message 112)
- Mistake: Interpolated times are 1 s low on every leg of `R77afbc0f+k` at `P8e65d0ee` (25326 vs 25327) and on `R023e7fca+2` at `Pf749c778` (27316 vs 27317). The Python at message 51 uses float division inside `math.floor((arr_b - dep_a) * (s[i] - s_a) / (s_b - s_a))`; the passing SQL version cast to `BIGINT`. This is the probable cause; integer `//` would have avoided it
- Mistake: Its own check could not catch this: `run_csa` reused the same interpolated times, and it never compared one interpolated call against a `run_sql` computation
- Mistake: For the 25620, 26220, ... journeys it reported the change at `P3b6efaff` (alight 26335, board 26700) rather than `Pd6ad09b1` as in the passing run; same times overall, picked as `j_list[0]` without a tie rule
- Mistake: `time.time()` is not supported in the sandbox (message 46), costing one request

### meeting_point

**Tool calling: passed.** Built per-friend leg tables up to 4 legs (`f1_leg1`..`f2_leg4`), joined arrivals per station and picked Albertplatz `Sbb9212fa` at 33701. Passed in 73 requests, close to the limit of 80. ($0.47, 73 requests, 5.8 min)
- Right: Found the answer early (message 85, direct legs) and then confirmed with 2- to 4-leg tables and end walks
- Right: Checked raw calls for the two interpolated arrivals 33701 and 33692
- Mistake: `CREATE TABLE f2_all_journeys` failed with `Referenced column "run2" not found` because `f2_leg4` had been created with too few columns; needed `DESCRIBE`, a drop and a rebuild (messages 105-111)
- Mistake: Two walk-reach queries returned no rows (messages 65-68) and were not followed up
- Mistake: 73 of 80 requests: the long hand-built leg tables left almost no margin

**Code mode: passed.** Wrote a round-based router (`full_raptor`, 3 rounds) from each origin, intersected reachable stations and answered Albertplatz at 33701, the same as tool calling. Passed in 53 requests against 73. ($0.40, 53 requests, 5.6 min)
- Right: A general earliest-arrival search to all stations replaced the hand-built leg tables used in tool calling
- Right: Verified both interpolated arrivals (33701, 33692) from raw `calls.txt`
- Mistake: Walked the filesystem with `os.walk('/')` and `os.listdir('/')` (messages 15-17) and tried to search the Python environment for rule text (message 31, runtime error): four requests with no value
- Mistake: A variable mix-up made `p1` a string (`p1: Pfff1e027`), giving `p1_walkable platforms: 0` and three debugging requests (messages 41-47)

### timed_tour

**Tool calling: passed.** Built interpolated, expanded `all_calls`, then assembled the tour hop by hop (Prohlis, TU, Pohlandplatz, Mickten) with hand-written joins and returned arrival 44160. Passed in 71 requests. ($0.61, 71 requests, 7.8 min)
- Right: Visit departures subtract the walk to the next platform (for example TU departure 38268 = 38312 - 44)
- Right: Verified each of the six legs against raw `calls.txt` and `repeats.txt` before answering
- Mistake: No enumeration of the 24 visit orders is visible in the queries I read: the order was fixed by inspection and each hop queried separately, so the optimal result is not proven by the run
- Mistake: Two binder errors (`Table "c" does not have a column`, `Referenced table "tu" not found`) and one ambiguous-column error cost three requests
- Mistake: 71 of 80 requests

**Code mode: passed.** Reached the same tour as tool calling (arrival 44160) but only after a `MemoryError` forced a full reload; finished on request 78 of 80. ($0.65, 78 requests, 8.2 min)
- Right: Recovered from the memory limit by reloading compact tuples and building a time-windowed connection list
- Right: Checked each hop's walk (44, 82, 19 m) and re-verified `R2d3055ed` distances step by step
- Mistake: `MemoryError: memory limit exceeded: 268447030 bytes` at message 82 while searching Prohlis to TU; state was lost and messages 83-92 repeat the loading, with four more runtime errors on the way
- Mistake: As in tool calling, the order was built one hop at a time with `find_direct_legs`; no enumeration of the 24 orders is visible
- Mistake: Passed with two requests to spare

### tour

**Tool calling: error.** Built station-to-station trip tables limited to one or two vehicles, evaluated all 120 orders in `eval_step1`..`eval_final`, and was still reading leg details when it hit the 80-request limit. No answer and no SVG were produced. ($0.55, 80 requests, 6.9 min)
- Right: Sound structure: `perms` with 120 rows and a chained earliest-arrival evaluation with a 900 s stay
- Right: Pareto-pruned 1,248,034 trips to 1,201 rows in `true_pareto_trips`
- Mistake: One SQL statement per request throughout; about 15 early requests were bare `count(*)` checks (messages 15-31, 75, 103, 115-119), and six separate `CREATE TABLE eval_stepN` requests could have been one statement
- Mistake: Trips were capped at two vehicles per hop with the second boarding within 1800 s; its best order reached 49560 (message 153), while the code-mode run with unrestricted connection scanning returned 48660, so the answer it was heading for was probably not optimal
- Mistake: At request 78-79 it was still inspecting `eval_final` rows; it should have written the SVG and called the result tool as soon as `eval_final` existed

**Code mode: passed.** Wrote a connection-scan router (`find_journey_fast`), evaluated all 120 orders with `itertools.permutations` and returned a 12-leg tour arriving 48660. Passed in 58 requests where tool calling ran out at 80. ($0.46, 58 requests, 6.8 min)
- Right: One Python loop did what tool calling spread over about 20 SQL requests, with no cap on vehicles per hop
- Right: Audited the result: every transfer margin, every leg against the raw calls, and the start walk from Julius-Vahlteich-Str. (288 m to `Pb25f298a`)
- Right: Compared with a no-start-walk variant (49843) to confirm walking first is what makes 48660 possible
- Mistake: Early requests listing `/data`, the working directory and `/out` (messages 13-17)
- Mistake: `time.time()` unsupported (message 36); one more runtime error at message 94
