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

# Gemini 4 Neon on Pydantic AI Transit Planner

> Journey planning over a real Dresden public transport timetable, with an SVG map of each answer. Tool calling 100%, code mode 100%; rank 1 of 32.
>
> Markdown copy of https://models.pydantic.dev/models/gemini-4-neon/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-4-neon.md

| Mode         | Score | Tasks passed | Cost  | Requests | Tool calls | Time     |
| ------------ | ----- | ------------ | ----- | -------- | ---------- | -------- |
| Tool calling | 100%  | 10 of 10     | $9.43 | 312      | 423        | 72.3 min |
| Code mode    | 100%  | 10 of 10     | $8.97 | 241      | 241        | 67.4 min |

Each task was run once per mode.

## Review

Written by an LLM from the runs' transcripts.

#### Overall

`gemini-4-neon` passed all 20 runs: 10 cases in tool calling and the same 10 in code mode. Both modes returned identical answers for every case. Tool calling used 312 requests and $9.43; code mode used 241 requests and $8.97. No run failed, so the differences are in cost and in avoidable errors.

#### Where it does well

- **Method:** every run loads the files, checks data quality (null `at`/`dwell` pairs, duplicate `(run, n)`, monotonic times) and tests its interpolation against integer division before searching.
- **Search depth:** it runs more rounds than the answer needs, for example 4 legs in `after_midnight`, 7 rounds in `departure_profile` and 6 layers in `tour`.
- **Independent confirmation:** many runs get a second algorithm (Dijkstra, a connection scan or a forward check), and final legs are audited against raw `calls`.
- **Rules:** it handled the after-midnight date with a -86400 shift, walking changes, start walks counted in `departure`, and all 120 orders in `tour`.
- **SVG:** in code mode it checks `data-place` and `data-run` by regex before answering.

#### Mistakes it makes

- **Unquoted `at`:** 19 of 20 runs hit a DuckDB `ParserException` on the reserved word `at` on first use. `tour` (tools) hit it twice.
- **Sandbox Python:** 5 code-mode runs called `d.timetuple()`, which the sandbox lacks. Three more had small code errors (`next()` on a list, a rebound variable, a 3-tuple passed to `dict`).
- **SQL build errors in tools:** `tour` needed four attempts to create `sat_base_calls`; `walking_change` hit division by zero twice.
- **Over-verification:** `saturday_direct` took 29 and 26 requests for one direct leg. Several runs spend 5-8 turns re-inspecting runs after the answer is fixed.
- **`service_changes` skipped:** five tools runs did not apply it. This was harmless only because the two rows are for other days.

#### Tool calling compared with code mode

Code mode is clearly better on the hard cases: `tour` took 22 requests and $1.12 against 45 and $1.71, and `departure_profile` 25 and $1.09 against 37 and $1.40. Loops and cached functions replace 5 KB SQL rounds pasted per turn.

On the simple cases code mode cost more: `one_vehicle`, `saturday_direct`, `arrive_by` and `meeting_point` were $0.07-$0.25 dearer. It often solves once in SQL and again in Python.

Code-mode SVGs are also far larger, about 60-109 KB against 5-17 KB, because they draw every station as a background dot.

## Runs

### one_vehicle

**Tool calling: passed.** Interpolated Wednesday calls into `wed_calls_interp`, enumerated single-vehicle rides from platforms near the origin and returned `R27f8d4b1+2`, departing 29541 and arriving 30480. Passed in 21 requests, the cheapest tools run at $0.61. ($0.61, 21 requests, 4.5 min)
- Right: Counted the walk to the boarding platform in `departure` (29541) separately from `board_time` (29940)
- Right: Verified the repeat offset by showing `arr_time + 2400` for the base run
- Mistake: Message 3: asked for `/data/DATA.md` from `start_line` 150 and got 'has fewer than 150 lines'
- Mistake: Message 9: `max(at + dwell)` with an unquoted `at` had to be re-issued with `"at"` at message 11
- Mistake: Messages 21, 25 and 33 repeat the same `run_instances` CTE in full each time

**Code mode: passed.** Queried candidate single-vehicle rides in SQL, interpolated the candidates in Python and returned `R27f8d4b1+2`, departing 29541 and arriving 30480. Passed in 20 requests, the fewest of any run. ($0.69, 20 requests, 5.5 min)
- Right: Quoted `"at"` from its first calls query, so it avoided the parser error seen elsewhere
- Right: Verified the 399 s walk by integer arithmetic (`dx=9, dy=-398, d2=158485`)
- Right: Checked all 34 base runs of the line without a time filter (message 25)
- Mistake: Message 7: `d.timetuple().tm_yday` raised AttributeError; fixed with date subtraction
- Mistake: Message 21: a query returned 'Total rows fetched: 200 truncated: True' and had to be narrowed at message 23
- Mistake: Costlier than tools ($0.69 against $0.61) for a one-leg answer

### saturday_direct

**Tool calling: passed.** Ran a three-round SQL search for Saturday `2026-339` from 33300 and returned the direct run `Rb28d92d7`, boarding 33484 and arriving 34560. Passed in 29 requests. ($0.66, 29 requests, 4.7 min)
- Right: Checked 2-leg and 3-leg alternatives up to the 34560 bound before accepting the direct run
- Right: Checked calls straddling the start time (`arr_time < 33300 AND dep_time >= 33300`)
- Right: Re-enumerated every run on every service at the origin between 33000 and 34000 (message 47)
- Mistake: Message 5: `count(at)` failed on the unquoted `at`; retried with `"at"`
- Mistake: 29 requests for a single direct leg; rounds 2-3 and the later re-checks (messages 29-47) did not change the answer

**Code mode: passed.** Ran three SQL rounds for Saturday from 33300, then rebuilt the search in Python, and returned the direct run `Rb28d92d7` arriving 34560. Passed in 26 requests. ($0.78, 26 requests, 5.3 min)
- Right: Computed weekday and day-of-year with date subtraction, avoiding the `timetuple` error
- Right: Grepped the raw files for `Rb28d92d7` and its service as a final check (message 45)
- Mistake: Message 5: `WHERE at IS NULL` failed on the unquoted `at`
- Mistake: Message 17 hard-codes the five Saturday service ids instead of joining
- Mistake: 26 requests and a second full Python implementation (messages 41-43) for a single direct leg; $0.78 against $0.66 in tools

### one_change

**Tool calling: passed.** Enumerated one- and two-vehicle journeys with SQL joins for Thursday `2026-337` and returned `Rafeef850` then `R620ec7d9`, arriving 28440. Passed in 27 requests. ($0.79, 27 requests, 5.0 min)
- Right: Checked direct journeys first, then two-leg journeys, then re-ran the two-leg join without pruning leg 1 (message 27)
- Right: Checked the unpruned list of boardable departures regardless of access (message 29)
- Mistake: Message 5: `min(at)` failed on the unquoted `at`; retried with `"at"`
- Mistake: `active_runs` at message 13 ignores `service_changes`; harmless here because both rows it had read are for days `2026-325` and `2026-326`
- Mistake: Messages 47-49 fetched the same run coordinates twice (`STRING_AGG` then row by row)

**Code mode: passed.** Found the 2-leg journey with SQL joins, then re-derived it in Python from the raw files, returning `Rafeef850` then `R620ec7d9`, arriving 28440. Passed in 21 requests. ($0.74, 21 requests, 6.3 min)
- Right: Applied `service_changes` in `active_services`
- Right: Listed all 2-leg journeys with `total_arr <= 28440` to look for ties (message 29)
- Right: Caught and fixed a raw `&` in the SVG text ('Header & Itinerary') at message 39 before answering
- Mistake: Message 5: `count(at)` failed on the unquoted `at`
- Mistake: The Python re-implementation at messages 25-27 (about 9 KB of code) repeated work the SQL had already done

### walking_change

**Tool calling: passed.** Ran a round-based SQL search for Friday `2026-338` from 61500 and returned `R76d2117b+4`, a walk to `P72ccec8b`, then `R3a0dccd4+54`, arriving 63480. Passed in 39 requests. ($0.89, 39 requests, 7.7 min)
- Right: Modelled the walk between platforms in the change (alight `P6e794064`, board `P72ccec8b`)
- Right: Ran an independent cumulative check through extra rounds (`ready_4` and beyond) before answering
- Right: Compared near-miss runs such as `Rd49d751b+59` (arrival 63180) stop by stop against the ready times
- Mistake: Message 9: `typeof(at)` failed on the unquoted `at`
- Mistake: Messages 21-24: `Division by zero` in `// (s_b - s_a)` twice, once in the build and again in the check query
- Mistake: Message 65: BinderException for `SELECT place ... FROM places` (the column is `ref`)
- Mistake: Messages 55 and 57 ran nearly the same shifted-time query twice

**Code mode: passed.** Built a round-based search in Python with walk transfers, confirmed it with a connection scan over DuckDB-computed calls, and returned the same journey arriving 63480. Passed in 27 requests against 39 in tools, at the same cost of $0.89. ($0.89, 27 requests, 6.9 min)
- Right: Checked float against integer interpolation in SQL (`float_vs_int_diff`)
- Right: Independent connection scan (message 41) and an all-options SQL join (message 43) agreed
- Right: Inspected whether near-miss runs `R3a0dccd4+54` and `Rd49d751b+59` were catchable at each stop
- Mistake: Message 5: `at IS NULL` failed on the unquoted `at`
- Mistake: Message 7: `d.timetuple().tm_yday` AttributeError
- Mistake: Messages 27-39: seven inspection turns after the journey was known

### after_midnight

**Tool calling: passed.** Built a SQL round-based search over Friday (`2026-338`, shifted -86400) and Saturday services and returned a 2-leg journey arriving 6420. Passed in 32 requests. ($0.86, 32 requests, 10.1 min)
- Right: Handled the after-midnight date by combining both service days in `active_runs` with a `day_offset` of -86400
- Right: Checked interpolation against integer division (`arr_t != dep_a + ((arr_b - dep_a) * (s - s_a)) // (s_b - s_a)` returned 0) and monotonicity (`non_mono` = 0)
- Right: Ran rounds up to 4 legs (`best_arr` 18575, 6420, 6420, 6420) before accepting the 2-leg answer
- Mistake: Message 11: `count(*) FILTER (WHERE at IS NULL)` failed with a ParserException because `at` is unquoted; fixed with `"at"` on the next turn
- Mistake: Message 15: `DESCRIBE places; DESCRIBE calls; DESCRIBE repeats;` in one call had to be re-issued as separate calls at message 17
- Mistake: Messages 39-55: about eight follow-up queries re-inspecting runs such as `R181e1950` and `Rb1b7f205` after the answer was already found

**Code mode: passed.** Loaded the files in Python, built a 400 m walk grid and a round-based search over both service days, and returned the same 2-leg journey arriving 6420. Passed in 23 requests. ($0.75, 23 requests, 6.5 min)
- Right: Used exact integer walking distance with `math.isqrt`
- Right: Cross-checked with an independent Dijkstra (message 33)
- Right: Checked the written SVG with regex for `data-place` and `data-run` before answering
- Mistake: Message 5: one of the batched queries, `min(at)`, failed on the unquoted `at`; re-issued with `"at"`
- Mistake: Messages 25-39: seven turns re-inspecting nearby runs (`R181e1950`, `Rb1b7f205`) after the answer was found
- Mistake: SVG is about 109 KB because every station is drawn as a background dot

### arrive_by

**Tool calling: passed.** Ran a backward latest-departure search in SQL for day `2026-344` and returned departure 63360, arrival 64440 on `R1aabe4da+29` then `Rfd6f9e2d+67`. Passed in 26 requests. ($0.69, 26 requests, 5.3 min)
- Right: Applied `service_changes` with `+`/`-` in `active_services`
- Right: Compared results by leg count (`latest_dep` null, 63360, 63360, 63060 for 1-4 legs) and picked the 2-leg option
- Right: Listed every later first departure (`total_dep >= 63300`) to confirm none could still arrive by 64800
- Mistake: Message 5: `SELECT min(at), max(at) ...` failed on the unquoted reserved word `at`; retried with `"at"`
- Mistake: Message 41 re-checked the weekday bits of every service after the answer was fixed, which added nothing

**Code mode: passed.** Ran a backward DP in DuckDB driven from a Python loop (`dp_board`, k up to 12), then re-solved in pure Python, returning departure 63360 and arrival 64440. Passed in 27 requests, one more than tools and $0.25 dearer. ($0.94, 27 requests, 6.0 min)
- Right: Applied `service_changes` in `active_services`
- Right: Looped the DP step in Python (`for k in range(7, 13)`) instead of pasting rounds
- Right: Re-implemented the search in Python from the raw files as a second opinion (messages 39-41)
- Mistake: Message 7: `FILTER (WHERE at IS NULL ...)` failed on the unquoted `at`
- Mistake: Solving twice (SQL DP then Python) roughly doubled the work; messages 29-37 are five more inspection queries

### departure_profile

**Tool calling: passed.** Built a backward profile search in SQL through seven rounds (`pareto_1`..`board_7`), then returned a list of Pareto journeys starting at departure 25327. Passed, but it was the second most expensive tools run at 37 requests and $1.40. ($1.40, 37 requests, 9.7 min)
- Right: Tested DuckDB `ASOF LEFT JOIN` semantics on a toy `VALUES` table before relying on it
- Right: Iterated rounds until improvements at the origin stopped (`imp_from_4_to_7_at_origin` = 0)
- Right: Cross-checked with an independent forward earliest-arrival query for start times such as 25327 and 25328
- Right: Verified each leg's access flags, times and order with a `j_legs` VALUES table
- Mistake: Message 7: `min(at)` failed with a ParserException; retried with `"at"`
- Mistake: Round queries were pasted repeatedly at 3-5 KB each (messages 41-47) instead of using a macro, which drove the cost

**Code mode: passed.** Built a connection list in Python, ran forward scans per candidate departure and an independent backward profile scan, and returned the same journey list as tools. Passed in 25 requests and $1.09, against 37 and $1.40 in tools. ($1.09, 25 requests, 8.5 min)
- Right: Compared Python interpolation against a DuckDB interpolation of all active calls (message 29)
- Right: Checked all 107 candidate departures for near misses (message 35)
- Right: Verified every leg, transfer walk and margin of the 12 journeys (message 33)
- Mistake: Message 5: called `run_sql` without `await` and gathered; one query failed on the unquoted `at`
- Mistake: Message 9: `d.timetuple().tm_yday` raised `AttributeError: 'datetime.date' object has no attribute 'timetuple'` in the sandbox
- Mistake: Message 41: `next(i for ...)` raised `TypeError: 'list' object is not an iterator`; rewritten at message 43

### meeting_point

**Tool calling: passed.** Ran a two-friend round-based search in SQL over Saturday `2026-339` and chose station `Sbb9212fa` with meeting time 33701, one leg each. Passed in 26 requests. ($0.75, 26 requests, 5.6 min)
- Right: Applied `service_changes` when building `active_services`
- Right: Computed both friends in one set of tables (`r0_ready` with a `friend` column) and ranked stations by `GREATEST(f1.best_arr, f2.best_arr)`
- Right: Extended to round 5 to confirm nothing better (`min_r5_arr` 34260 and 33920)
- Mistake: Message 5: `min(at)` failed on the unquoted `at`; retried with `"at"`
- Mistake: Message 11: four `DESCRIBE` statements in one call returned only one result, so it queried `information_schema.columns` at message 13
- Mistake: Messages 41-45 chased run `Rd7036af4`, which departs at 32358 before the start time, for three turns

**Code mode: passed.** Wrote `run_raptor(origin_station, t0)` in Python, ran it for both friends and confirmed with a connection scan, returning `Sbb9212fa` at 33701. Passed in 24 requests. ($0.82, 24 requests, 5.5 min)
- Right: One reusable function served both friends
- Right: Independent connection scan across all 6,852 expanded Saturday runs agreed with the first result
- Right: Hand-checked interpolation for `Rc0124950` and `Rfa439a34` around Albertplatz
- Mistake: Message 5: `MAX(at + dwell)` failed on the unquoted `at`
- Mistake: Message 9: `d.timetuple()` AttributeError
- Mistake: Message 27: `TypeError: 'int' object is not subscriptable` because `arr2` had been rebound; fixed at message 29 by recomputing `arr2_check`
- Mistake: Messages 35-39 chased `Rd7036af4` again, as in tools

### timed_tour

**Tool calling: passed.** Defined a table macro `raptor_earliest(src_st, t0)` and chained it across the four timed visits, returning six legs and arrival 44160. Passed in 30 requests at $1.07. ($1.07, 30 requests, 7.9 min)
- Right: Wrapped the search in `CREATE MACRO raptor_earliest` and reused it via `UNION ALL` for several sub-journeys in one call
- Right: Re-ran six rounds from Mickten at 43200 to confirm 44160
- Right: Audited all six legs against the raw `calls` table and hand-checked interpolation for `R2d3055ed`
- Mistake: Message 7: a multi-statement query with `count(at)` failed on the unquoted `at`
- Mistake: Message 19: dropped and rebuilt `base_calls_interp` after the first version
- Mistake: `wed_runs` ignores `service_changes`; harmless because the two rows are for other days

**Code mode: passed.** Built a connection scan in Python and tried the visit orders with `itertools`, returning the same six legs and arrival 44160 as tools. Passed in 26 requests at $1.13. ($1.13, 26 requests, 8.9 min)
- Right: Compared Python and DuckDB interpolation by checksum (message 23)
- Right: Investigated an alternative without a starting walk from Prohlis and compared it as 'Option B' before choosing
- Right: Validated the final answer object against the SVG in code
- Mistake: Message 7: `d.timetuple()` AttributeError
- Mistake: Message 9: `FILTER (WHERE at IS NULL)` failed on the unquoted `at`
- Mistake: Message 47: `ValueError: dictionary update sequence element #0 has length 3` from a three-group regex passed to `dict`; fixed at message 49

### tour

**Tool calling: passed.** Solved the visiting-order problem as a layered DP in SQL (`dp_layers`, layers 1-6) and returned an 11-leg tour arriving 48660. Passed, but it was the most expensive run at 45 requests and $1.71. ($1.71, 45 requests, 11.9 min)
- Right: Kept all states per layer and visited-set mask rather than a greedy order
- Right: Batched all origin states of a layer through `q_batch` so each layer was one search
- Right: Verified all 11 legs, their services and repeats, and the 22 board/alight calls against raw data
- Mistake: Message 7: `FILTER (WHERE at IS NULL)` failed on the unquoted `at`
- Mistake: Messages 13-19: four attempts to create `sat_base_calls` (BinderException on `r.ref`, ConversionException casting `nan` to INT64, then 'Table ... already exists' until it used `CREATE OR REPLACE`)
- Mistake: Message 77: used `at` as a column alias in a `VALUES` CTE and hit the same ParserException a second time
- Mistake: Messages 51 and 53 ran an identical recursive backtrack query twice
- Mistake: Layer queries were pasted at 4.5-5.5 KB each (messages 39-49)

**Code mode: passed.** Wrote `csa_from_station` in Python, cached results and checked all 120 visiting orders, returning the same 11-leg tour arriving 48660. Passed in 22 requests and $1.12, against 45 and $1.71 in tools. ($1.12, 22 requests, 8.0 min)
- Right: Checked all 5! = 120 permutations directly with cached scans (message 23)
- Right: Re-ran each of the six stages round by round with `raptor_stage` to confirm leg counts
- Right: Verified all 11 legs independently in DuckDB (message 33)
- Right: Used `assert` checks on the SVG, then moved the legend to avoid overlapping routes
- Mistake: Message 5: `FILTER (WHERE at IS NULL)` failed on the unquoted `at`
- Mistake: Messages 29-31 spent two turns on how to reach `R81f00f31` from `Sc29ca723`, the same detour tools took
