---
title: "Gemini 4 Hydrogen 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 90%; rank 1 of 32."
canonical: https://models.pydantic.dev/models/gemini-4-hydrogen/transit_planner/
---

# Gemini 4 Hydrogen 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 90%; rank 1 of 32.
>
> Markdown copy of https://models.pydantic.dev/models/gemini-4-hydrogen/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-hydrogen.md

| Mode         | Score | Tasks passed | Cost  | Requests | Tool calls | Time     |
| ------------ | ----- | ------------ | ----- | -------- | ---------- | -------- |
| Tool calling | 100%  | 10 of 10     | $3.80 | 271      | 354        | 36.2 min |
| Code mode    | 90%   | 9 of 10      | $3.57 | 233      | 233        | 34.3 min |

Each task was run once per mode.

## Review

Written by an LLM from the runs' transcripts.

#### Overall

19 of 20 cases passed: 10/10 with tool calling, 9/10 in code mode. The one failure is `tour` in code mode, which returned a valid-looking round trip back at 50012 where the tools run's accepted trip gets back at 48660. Every other case gave identical legs in both modes. Total cost was $3.80 (271 requests) for tools and $3.57 (233 requests) for code mode. I read both `tour` runs in detail and skimmed the other 18 for errors and final answers.

#### Where it does well

- **Data rules.** It handled service days, repeats (`<run>+<k>`), untimed-call interpolation, start walks (`one_vehicle` boards after a 399 s walk) and the after-midnight case correctly in both modes.
- **Self-checking.** It routinely re-verified chosen legs against raw `at`/`dwell`, access letters and walk distances, and ran extra search rounds to confirm nothing improved. In code-mode `tour` it cross-checked its Python interpolation against SQL sums.
- **Recovery.** Every tool error was fixed on the next call; none led to a wrong answer.

#### Mistakes it makes

- **Unquoted `at`.** At least 11 of 20 runs (probably 13) hit a DuckDB parser error from `max(at)` or `at IS NULL` before quoting the column; `saturday_direct` code mode did it twice in a row.
- **Stay rule in `tour`.** The two modes modelled the 15-minute stay differently. Code mode added same-station platform walks after the 900 s and so rejected the 48660 trip; tools mode treated any platform of the visited station as zero walk and passed. On the coordinates shown, the tools trip's Waldschlößchen stay is about 816 s under the literal wording, so that pass looks lenient. The expected answer is not recorded, so this cause is likely, not confirmed.
- **Inconsistent `visits`.** `timed_tour` reported different visit departures in the two modes for the same legs; both passed.
- **Other SQL slips.** `IGNORE NULLS` placement, a NaN cast from an unguarded `s_b = s_a`, a `place`-to-INT64 cast, and a struct-field binder error.

#### Tool calling compared with code mode

Tools mode hand-unrolls each search round as a separate SQL statement, so the hard cases cost most: `departure_profile`, `timed_tour` and `tour` took 35–37 requests and $0.59–0.63 each. Code mode's Python connection scan did the same three in 28–31 requests for $0.47–0.51. On simple cases code mode was no cheaper and sometimes dearer (`after_midnight` $0.40 vs $0.29, `arrive_by` $0.41 vs $0.31), partly because it draws every station as a background dot, giving SVGs of 60–115k characters.

Code mode also tripped on sandbox limits: `date.timetuple()` (2 runs), `time.monotonic()` (2 runs), `next()` on a generator (4 runs), and one `KeyError: rows` from not checking a `run_sql` error result.

## Runs

### one_vehicle

**Tool calling: passed.** Found the single-vehicle journey on `R27f8d4b1+2`, boarding `P0091960a` at 29940 after a start walk (journey departure 29541), arriving 30480. Passed in 16 requests with no tool errors. ($0.23, 16 requests, 2.4 min)
- Right: Quoted `"at"` from the first query, so no parser error
- Right: Considered platforms within walking distance of the origin rather than only the origin's own platforms; the answer boards after a 399-second walk
- Right: Checked the run's service and repeat row before answering

**Code mode: passed.** Same single-vehicle answer as tools mode (`R27f8d4b1+2`, departure 29541, arrival 30480). Passed in 16 requests. ($0.23, 16 requests, 2.4 min)
- Right: Same request count and cost as tools mode ($0.23)
- Mistake: Message 19: `next(r for r in res_near_orig['rows'] if r[0] == 'P0091960a')` raised `TypeError: 'list' object is not an iterator`

### saturday_direct

**Tool calling: passed.** Found a single direct run `Rb28d92d7` from `P7fa04a55` at 33484 to `P1093f876` at 34560. Passed, but used 23 requests for a one-leg answer. ($0.23, 23 requests, 2.1 min)
- Right: Same answer as code mode
- Mistake: Message 9: `COUNT(at)` failed on the unquoted `at`
- Mistake: 23 requests against 16 in code mode for the same one-leg result

**Code mode: passed.** Same direct run `Rb28d92d7` as tools mode, arriving 34560. Passed in 16 requests, the cheapest run of the benchmark ($0.215). ($0.22, 16 requests, 2.1 min)
- Right: 7 fewer requests than tools mode
- Mistake: Messages 7 and 9: the unquoted `at` error (`COUNT(*) FILTER (WHERE at IS NULL)`, then `SUM(CASE WHEN at IS NULL ...)`) happened twice in a row before it quoted the column

### one_change

**Tool calling: passed.** Found the earliest journey with at most two vehicles: `Rafeef850` then `R620ec7d9`, arriving 28440. Passed in 18 requests. ($0.22, 18 requests, 2.1 min)
- Right: Same answer as code mode
- Right: Issued parallel `run_sql` calls in one turn while exploring
- Mistake: Message 7: `SELECT max(at), min(at), count(*) FILTER (WHERE at IS NULL)` failed on the unquoted `at`

**Code mode: passed.** Same two-leg answer as tools mode (arrival 28440). Passed in 21 requests with no tool errors found. ($0.29, 21 requests, 2.6 min)
- Right: No failed calls
- Mistake: 3 more requests and higher cost ($0.29 vs $0.22) than tools mode for an identical answer

### walking_change

**Tool calling: passed.** Found a two-leg journey with a walking change (`R76d2117b+4` to `P6e794064`, then `R3a0dccd4+54` from `P72ccec8b`), arriving 63480. Passed in 24 requests. ($0.28, 24 requests, 2.6 min)
- Right: Same answer as code mode
- Right: Used parallel `run_sql` calls in one turn
- Mistake: Message 7: `sum(CASE WHEN at IS NULL ...)` failed on the unquoted `at`

**Code mode: passed.** Same two-leg journey with a walking change as tools mode, arriving 63480. Passed in 21 requests. ($0.27, 21 requests, 2.7 min)
- Right: 3 fewer requests and slightly lower cost ($0.27 vs $0.29) than tools mode
- Right: Kept the SVG small (about 6k characters) here, unlike its other code-mode runs
- Mistake: Message 3: `(SELECT max(at) FROM calls)` parser error on the unquoted `at`
- Mistake: Message 13: `LAST_VALUE(...) IGNORE NULLS OVER (...)` parser error — DuckDB wants `IGNORE NULLS` inside the parentheses

### after_midnight

**Tool calling: passed.** Built interpolated call tables and a walk table in DuckDB, then ran round-by-round SQL (`best_arr`, `best_arr2`, `best_arr3`, `board4`/`leg4`) to find a two-leg journey arriving 6420. Passed in 24 requests. ($0.29, 24 requests, 2.7 min)
- Right: Rebuilt `base_calls` after checking the interpolation (`last_value ... IGNORE NULLS`) rather than trusting the first version
- Right: Ran a fourth round (`leg4`) and checked it gave no improvement over `best_arr3` before answering
- Right: Checked service, repeat and line of the chosen runs before writing the SVG
- Mistake: Message 7: `SELECT min(at), max(at) ...` failed with a parser error because `at` was not quoted; fixed on the next call
- Mistake: Rounds were hand-unrolled as separate SQL statements, which is why a simple two-leg answer took 24 requests

**Code mode: passed.** Reached the same two-leg answer as tools mode (arrival 6420) but with the most sandbox trouble of any run. Passed in 28 requests. ($0.40, 28 requests, 3.8 min)
- Right: Printed day-of-year and weekday bits for 3–6 December to settle which service days apply after midnight
- Right: Final legs identical to tools mode
- Mistake: Message 9: `d.timetuple().tm_yday` raised `AttributeError` (not available in the sandbox)
- Mistake: Message 11: a `run_sql` parser error at `)` returned inside the result dict
- Mistake: Message 33: `KeyError: rows` from `step['rows']` — the code did not check whether a `run_sql` result was an error before indexing it
- Mistake: Message 35: `BinderException: There are no UNIQUE/PRIMARY KEY constraints` from an `ON CONFLICT` insert
- Mistake: Cost $0.40 against $0.29 in tools mode for the same answer

### arrive_by

**Tool calling: passed.** Found the latest departure (63360) that reaches Lennéplatz by 18:00 with two legs, arriving 64440. Passed, but took 30 requests. ($0.31, 30 requests, 3.0 min)
- Right: Final answer matches the code-mode run exactly (`R1aabe4da+29` then `Rfd6f9e2d+67`)
- Mistake: Message 7: `SELECT max(at) FROM calls` failed with a parser error on the unquoted `at`
- Mistake: 30 requests for a two-leg journey is the highest of the simple cases; I only skimmed this conversation for errors and the final answer, not every query

**Code mode: passed.** Returned the same latest-departure journey as tools mode (leave 63360, arrive 64440). Passed in 23 requests, with no tool errors found. ($0.41, 23 requests, 3.6 min)
- Right: Checked weekday bits for 2026-344 and 2026-343 and the `calls` schema before computing
- Right: 7 fewer requests than tools mode
- Mistake: Cost $0.41 against $0.31 in tools mode despite fewer requests; the SVG includes a dot for every station in the network (about 84k characters)

### departure_profile

**Tool calling: passed.** Computed a per-departure-time profile with temp tables `first_boardings`, `r1_alights`, `r1_ready`, `r2_boardings` up to a fifth round, then a `pareto` filter, and returned the journey list. Passed in 37 requests at $0.59. ($0.59, 37 requests, 5.5 min)
- Right: Checked that rounds 4 and 5 (`r4_improved`, `r5_alights`) did not beat `d123.best_123` before stopping
- Right: Verified services, repeats and interpolation ratios for the base runs of all 12 journeys
- Right: Built the SVG station markers with `string_agg` in SQL instead of typing coordinates
- Mistake: Message 5: `max(at + coalesce(dwell, 0))` failed on the unquoted `at`
- Mistake: Joint highest request count of the benchmark (37) because every round is a separate hand-written statement

**Code mode: passed.** Produced the same journey list as tools mode. Passed in 31 requests at $0.47, cheaper than tools mode ($0.59). ($0.47, 31 requests, 4.6 min)
- Right: Recovered from a division-by-zero in the interpolation SQL and went on to the right profile
- Right: 6 fewer requests and lower cost than the hand-unrolled SQL rounds in tools mode
- Mistake: Message 15: `ConversionException: Type DOUBLE with value nan can't be cast ... INT64` in `floor((arr_b - dep_a) * (s - s_a) / ...)` — the `s_b = s_a` case from DATA.md was not guarded
- Mistake: Message 53: `next(i for i, c in enumerate(clist) ...)` raised `TypeError: 'list' object is not an iterator` in the sandbox

### meeting_point

**Tool calling: passed.** Searched from both origins and picked station `Sbb9212fa`, meeting at 33701 with one leg each. Passed in 27 requests. ($0.38, 27 requests, 3.7 min)
- Right: Answer identical to the code-mode run (`Rc0124950` and `Rfa439a34`, time 33701)
- Mistake: Message 5: one of two parallel `run_sql` calls failed with a parser error at `)` (same error text as the unquoted-`at` failures in other runs)
- Mistake: Message 31: `ConversionException: Could not convert string 'P037b7677' to INT64 when casting from source column place` — a type mix-up in a union or join that cost a retry

**Code mode: passed.** Found the same meeting station `Sbb9212fa` at 33701 with the same two one-leg journeys. Passed in 19 requests with no tool errors found. ($0.29, 19 requests, 2.8 min)
- Right: 8 fewer requests and lower cost ($0.29 vs $0.38) than tools mode
- Right: No failed calls in the conversation

### timed_tour

**Tool calling: passed.** Planned a four-station round trip with five legs, back at 44160. Passed in 35 requests at $0.62. ($0.62, 35 requests, 6.1 min)
- Right: Quoted `"at"` from the start; no tool errors in the conversation
- Right: Legs and arrival are identical to the code-mode run
- Mistake: The `visits` departures (35493, 38244, 40478, 43241) differ from code mode's (35523, 38312, 40560, 43260) for the same legs, so the two runs applied the walk-before-boarding rule differently; both were accepted
- Mistake: One of the two most expensive tools cases

**Code mode: passed.** Same five legs and arrival 44160 as tools mode. Passed in 30 requests at $0.49, cheaper than tools mode ($0.62). ($0.49, 30 requests, 4.8 min)
- Right: Legs identical to tools mode with 5 fewer requests
- Mistake: Message 9: `MAX(at)` parser error on the unquoted column
- Mistake: Message 31: `time.monotonic()` raised `RuntimeError: 'time.time' is not supported in this environment`
- Mistake: Message 53: `next(...)` on a generator raised `TypeError`
- Mistake: Reported `visits` departures (35523, 38312, 40560, 43260) differ from the tools-mode run's values for the same legs

### tour

**Tool calling: passed.** Ran a station-level bitmask DP as tables `dp_lvl0`…`dp_lvl5` and `dp_final`, got 48660 via Julius-Vahlteich-Str., Altpieschen, Waldschlößchen, Marienberger Straße, Wasaplatz, then rebuilt the 11 legs in `best_segments`. Passed in 37 requests at $0.63. ($0.63, 37 requests, 6.0 min)
- Right: `dp_final` compared all five possible last stations (48660, 49877, 49920, 50012, 50177) and took the best
- Right: Re-checked every leg's access letters, raw `at`/`dwell` and interpolation, and tested whether more rounds changed `dp_final`
- Mistake: Message 13: `last_value(CASE WHEN at IS NOT NULL ...` failed on the unquoted `at`
- Mistake: Message 27: `BinderException: Cannot extract field 'board_n'` from a `min_by` struct
- Mistake: The DP is keyed on station, with `t_ready = arr_time + 900` and `station_walk` giving zero walk to any platform of the visited station. At Waldschlößchen it alights at `P50445d2a` at 42450 and boards at `Pca84a5e7` at 43380; by the coordinates shown in the code-mode run those platforms are about 114 m apart, so under the question's wording (departure = vehicle departure minus the walk) the stay is about 816 s. It also reported the visit departure as 43380, not minus the walk. The grader accepted it, so the pass depends on a lenient reading

**Code mode: failed.** Parsed the files in Python and ran a connection scan over (visited-mask, platform) states, returning a 10-leg round trip back at 50012. Failed: the tools-mode run's accepted trip gets back at 48660, 1,352 seconds earlier. ($0.51, 28 requests, 4.9 min)
- Right: Cross-checked its Python interpolation against the SQL table `calls_sat_base` (both sums 2524552449 / 2524589769)
- Right: Re-ran the scan with a tie-break sort `(d1, r_id, idx_from)` and got 50012 again
- Right: Verified every leg's access letters and walk distances in SQL, and checked the SVG's `data-run` and `data-place` values by regex
- Right: The answer it gave is internally consistent: every visit shown has a stay of at least 900 s after subtracting the walk
- Mistake: Message 39, the scan: after alighting at a target platform it sets `t_vis = a2 + 900` and then `nt = t_vis + d` for every platform in `walk_adj[p2]`, including other platforms of the same station. The accepted tools-mode trip needs Waldschlößchen from `P50445d2a` (arrive 42450) to `Pca84a5e7` (board 43380), about 114 m apart: 42450 + 900 + 114 = 43464 > 43380, so this scan rejects it. This is the most likely reason it missed 48660; the expected answer is not recorded, so I cannot confirm it
- Mistake: Its reading is the literal one in the question ("departure of that vehicle minus the walk"), but it never tested the alternative. Its own result printed the order ending at Julius-Vahlteich-Str.; it should have compared orders under a station-level stay (ready at any platform of the visited station 900 s after arrival), as the tools run did, and noticed the 22-minute gap
- Mistake: Messages 7, 11, 27, 49: four avoidable errors — `d.timetuple()` not available, unquoted `at`, `time.monotonic()` not supported, `next()` on a generator
