---
title: "Gemini 4 Carbon 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-carbon/transit_planner/
---

# Gemini 4 Carbon 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-carbon/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-carbon.md

| Mode         | Score | Tasks passed | Cost  | Requests | Tool calls | Time      |
| ------------ | ----- | ------------ | ----- | -------- | ---------- | --------- |
| Tool calling | 100%  | 10 of 10     | $7.26 | 305      | 337        | 148.3 min |
| Code mode    | 100%  | 10 of 10     | $6.46 | 265      | 265        | 137.6 min |

Each task was run once per mode.

## Review

Written by an LLM from the runs' transcripts.

#### Overall

`gemini-4-carbon` passed all 20 runs (10 cases × 2 modes) with no provider errors. Both modes gave the same answer on every case; the only visible difference is the change platform in `departure_profile` (`P3b6efaff` versus `Pd6ad09b1`), with the same times. It is correct but not economical: 305 requests and $7.26 in tool calling, 265 requests and $6.46 in code mode.

#### Where it does well

- **Follows the data rules.** Every run handled service-day bitmasks, `service_changes`, interpolation of untimed calls, repeat expansion and the 400 m walk table. `after_midnight` added the previous service day at `-86400`.
- **Searches exhaustively.** `tour` evaluated all 120 orders and `timed_tour` all 24. `meeting_point` proved a fifth round changed nothing (`improved_before_34000` = 0).
- **Checks before answering.** It compared integer and floating floor division, re-read raw calls of the chosen runs, and in code mode read the SVG back with a regex.
- **Gets fine rules right**, such as departure equal to boarding minus the walk (`one_vehicle`: `29541` against a `29940` boarding).

#### Mistakes it makes

- **Unquoted `at`.** The reserved-word column caused a `ParserException` in 19 of 20 runs. `after_midnight` and `departure_profile` (tools) each needed three tries, changing `!=` to `<>` before quoting `"at"`. `tour` (code mode) repeated it in the next script.
- **NaN casts in interpolation**: `ConversionException ... value nan` in four runs (`tour` tools; `after_midnight`, `tour`, `walking_change` code mode).
- **Over-verification and SVG decoration.** Tool runs spent 3 to 15 requests after the answer was known on re-checks and background tram-network queries; `tour` took 46 requests and `timed_tour` 40.
- **Unchecked results in code mode.** `result['rows']` on an error dict raised `KeyError` in three runs. `d.timetuple().tm_yday` failed in three. `tour` hit the 30-second limit and lost its session.

#### Tool calling compared with code mode

Code mode used 13% fewer requests and cost 11% less. The gain is concentrated in the hard cases: `timed_tour` fell from 40 to 26 requests ($1.29 to $0.80), `meeting_point` from 31 to 21 and `tour` from 46 to 37, because loops replaced hand-unrolled rounds. Simple cases gained little, and `one_change` got worse (21 to 29). Code mode added independent pure-Python re-solves in four runs, but also errors that tool calling never met (sandbox limits, `KeyError`, the time-out) and much larger SVGs (up to 120 KB against about 17 KB).

## Runs

### one_vehicle

**Tool calling: passed.** Checked for a direct run between the two stations, then allowed a walk to a nearby platform and returned one leg on `R27f8d4b1+2` boarding `P0091960a` at `29940`, with departure `29541`. Passed in 24 requests. ($0.71, 24 requests, 12.2 min)
- Right: Reported departure `29541` as boarding time minus the 399-second walk, as the question's rules require.
- Right: Re-checked the walk distance between the origin platforms and `P0091960a` (message 35) before committing to a boarding platform outside the origin station.
- Mistake: Message 9: `COUNT(at)` parser error on unquoted `at`, one retry.
- Mistake: Messages 27-33: four near-duplicate queries on which lines serve which platforms.

**Code mode: passed.** After three failed set-up turns it built `calls_timed`, searched single-vehicle journeys including a walk to nearby platforms, and returned the same leg on `R27f8d4b1+2` with departure `29541`. Passed in 22 requests. ($0.43, 22 requests, 10.0 min)
- Right: Same answer as the tool run, including departure equal to boarding minus the walk.
- Right: Cheapest handling of this case: $0.43 against $0.71.
- Mistake: Message 3: `Invalid named parameter "varchar" for function read_csv` (the option is `all_varchar`).
- Mistake: Message 5: parser error on `NULLIF(at, '')` with unquoted `at`.
- Mistake: Message 9: `d.timetuple().tm_yday` `AttributeError`.
- Mistake: Messages 17, 21, 25: the `active_services` CTE was pasted into three separate scripts rather than saved as a table.

### saturday_direct

**Tool calling: passed.** Built Saturday services (`days & 32`), interpolated and expanded calls, ran a round search from `33300` and returned a single leg on `Rb28d92d7` from `33484` to `34560`. Passed in 26 requests. ($0.53, 26 requests, 8.9 min)
- Right: Checked `service_changes` and the Saturday bit before building runs.
- Right: Checked integer floor division against `FLOOR` on doubles in the interpolation (message 21).
- Mistake: Message 9: `FILTER (WHERE at IS NULL)` parser error on unquoted `at`, one retry.
- Mistake: Messages 43-47: three versions of a background-route query for the SVG.

**Code mode: passed.** Ran a round search in SQL, then loaded the CSV files in Python and repeated the search with grid-bucketed walks; returned the same single leg `33484`→`34560`. Passed in 20 requests. ($0.40, 20 requests, 15.0 min)
- Right: Independent Python re-implementation (messages 29-31) with an exact integer `ceil_hypot` using `math.isqrt`.
- Right: Fewest requests on this case of either mode (20 against 26).
- Mistake: Message 5: `KeyError` on `['rows']`: it indexed five results in one dict without checking for `error`, so the whole turn was lost.
- Mistake: Message 7: the retry then revealed the parser error on unquoted `at`.

### one_change

**Tool calling: passed.** Enumerated 1-vehicle and 2-vehicle journeys from `S98bf09ad` after `27600` with walk joins and returned `Rafeef850` then `R620ec7d9` arriving `28440`. Passed in 21 requests, the fewest of the tool runs. ($0.49, 21 requests, 9.1 min)
- Right: Issued parallel `run_sql` calls in one turn (messages 7, 9, 15, 19, 25, 31), which kept the request count down.
- Right: First 1-vehicle query returned no rows; it widened the window to `36000` rather than concluding there was none.
- Mistake: Message 7: `WHERE at IS NULL` parser error on unquoted `at`, one retry.
- Mistake: Messages 31-37: four versions of the background tram-edge query for the SVG.

**Code mode: passed.** Built day calls for `2026-337` and `2026-336`, queried 1-leg and 2-leg journeys and returned the same `27669`→`28440` answer. Passed in 29 requests, eight more than the tool run. ($0.55, 29 requests, 9.2 min)
- Right: Recomputed the interpolated times of `Rafeef850` and `R620ec7d9` in Python (message 41) as a check on the SQL.
- Right: Used `asyncio.gather` for the five SVG data queries (message 53).
- Mistake: Message 7: `d.timetuple().tm_yday` `AttributeError`.
- Mistake: Message 9: parser error on `NULLIF(at, '')` with unquoted `at`.
- Mistake: Message 23: `DROP TABLE base_calls` and rebuild after the first interpolation table was wrong.
- Mistake: Messages 47-51: three background-geometry queries for the SVG.

### walking_change

**Tool calling: passed.** Built Friday services, expanded calls and a walks table, ran rounds up to `r4_ready` with the 120-second change margin, and returned bus `R76d2117b+4` then tram `R3a0dccd4+54` arriving `63480`. Passed in 22 requests. ($0.42, 22 requests, 8.7 min)
- Right: Applied the change margin and walk together (`a.arr_t + 120 + w.walk_sec`), giving a change that alights at `P6e794064` and boards at a different platform `P72ccec8b`.
- Right: Ran four rounds although the answer needed two.
- Mistake: Message 11: parser error at `SELECT run, n, place, at, dwell` from the unquoted `at`, one retry.
- Mistake: Messages 23-27: three single-row look-ups (`runs`, `services`, `repeats`) that could have been one query.

**Code mode: passed.** Put most of the pipeline into a few large SQL scripts (one of 8,336 characters), ran rounds to `ready_5`, and returned the same bus-then-tram journey arriving `63480`. Passed in 19 requests, the fewest of all 20 runs. ($0.45, 19 requests, 9.2 min)
- Right: Checked a fifth round (`-- Also check leg_5 just in case`).
- Right: Investigated negative interpolation spans (`span_sec < 0`) before trusting the times.
- Mistake: Message 5: parser error on `WHERE at = ''` with unquoted `at`.
- Mistake: Message 13: `ConversionException ... value nan` when casting the interpolation ratio; fixed by rebuilding as `base_calls_exact`.

### after_midnight

**Tool calling: passed.** Loaded the files into DuckDB, built an interpolated and repeat-expanded call table covering both service day `2026-338` (offset `-86400`) and `2026-339`, ran a round-based search from `4200` and returned a 2-leg journey arriving `6420`. Passed in 34 requests. ($0.87, 34 requests, 14.9 min)
- Right: Treated the 01:10 start as possibly served by the previous service day: `active_svc` unions day `2026-338` with `day_offset -86400`.
- Right: Checked 2-leg and 3-leg alternatives (`-- Check all 3-leg journeys arriving <= 6500`) and re-read the raw calls of `R93fefd15` and `R900bf42f` before answering.
- Mistake: Messages 11-16: three consecutive `ParserException`s from the unquoted column `at` (`(at IS NULL) != (dwell IS NULL)`, then the same with `<>`, then `COUNT(at) OVER`); it changed the operator before quoting `"at"`.
- Mistake: Messages 55-61: four successive `run_sql` rewrites of a background tram-network query used only for SVG decoration.

**Code mode: passed.** Same approach as the tool run, with previous-day services at `-86400`, plus an attempted in-Python cross-check; returned the same journey arriving `6420`. Passed in 35 requests. ($0.76, 35 requests, 13.9 min)
- Right: Same answer as tool calling, leg for leg.
- Right: Read `/out/journey.svg` back and checked `data-place`, `data-run` and unescaped `&` before finishing.
- Mistake: Message 3: parser error on unquoted `at` inside the first load script.
- Mistake: Message 19: `ConversionException ... value nan` in the interpolation.
- Mistake: Message 35: `KeyError: rows` because the code indexed `cand_2leg['rows']` without checking for an `error` key; it needed a `print(cand_2leg)` turn to discover a `BinderException` (`Referenced table "pb1" not found`). Two requests lost.
- Mistake: The 12,504-character SVG script drew every station as a dot, giving a 120 KB SVG.

### arrive_by

**Tool calling: passed.** Built `calls_interp`, `exp_calls` and `walks`, ran a backward search for the latest origin departure reaching `S6f32bdc5` by `64800`, and returned the `63360` departure arriving `64440`. Passed in 26 requests. ($0.39, 26 requests, 8.1 min)
- Right: Backward search by number of legs gave `max_orig_dep` `63360` for k=2 and k=3, then listed every boarding after `63360` near the origin to confirm none could still arrive by `64800`.
- Right: Among equal latest departures it chose the earlier arrival (`64440` via `Rfd6f9e2d+67` rather than `64500` via `R54c1ee76+5`).
- Mistake: Message 7: `count(*) FILTER (WHERE at IS NULL)` failed with a parser error on the unquoted `at`; fixed next turn with `"at"`.
- Mistake: Message 23: `BinderException` for `a.a_place` (wrong alias in a CTE join), one retry.
- Mistake: Messages 39-47: four queries re-fetching the same stop coordinates for the SVG, after `string_agg` output was truncated.

**Code mode: passed.** Built the tables through `run_sql` inside `run_code`, enumerated 1- and 2-leg journeys, checked later boardings, and returned the same `63360`→`64440` journey as the tool run. Passed in 25 requests. ($0.57, 25 requests, 25.7 min)
- Right: Explicitly looked at every boarding after `63300` and why each missed the `64800` deadline (`miss_chk`).
- Right: Read the SVG back with a regex before finishing.
- Mistake: Message 3: parser error on unquoted `at`.
- Mistake: Message 11: `AttributeError` from `d.timetuple().tm_yday`, which the sandbox does not support; replaced with a date subtraction.

### departure_profile

**Tool calling: passed.** Built a backward per-round table (`dp1` to `dp8`) of best arrival per boarding, extracted the Pareto set of departures between `25200` and `28800`, and returned the journeys starting `25327`→`27420`. Passed in 35 requests. ($0.85, 35 requests, 15.3 min)
- Right: Ran the rounds to `dp8` so the frontier was not capped at a small number of changes.
- Right: Verified integer versus floating floor division in the interpolation across all calls (`div_diff`) before trusting times.
- Mistake: Messages 9-14: three consecutive parser errors on the unquoted `at`; it tried `!=`, `<>`, then an `AND/OR` rewrite before quoting `"at"`.
- Mistake: Message 27: `OutOfRangeException: Overflow in multiplication of INT32 (371 * 100000000)` from packing a tie-break key into `arg_min`; rewritten with a window function.
- Mistake: Messages 45-65: about ten queries on leg details and SVG coordinates, several repeating the same `opt_deps` VALUES list.

**Code mode: passed.** Built `best_1` to `best_6` tables in a Python loop over `run_sql`, took the Pareto set, then re-derived it in pure Python from the CSV files and asserted the output. Passed in 31 requests. ($0.87, 31 requests, 11.3 min)
- Right: Used a real loop (`for k in range(2, 7)`) to generate the rounds, and confirmed convergence with `diff_3_6`.
- Right: Independent check in pure Python (messages 45-47) loading the files with `Path.read_text()`.
- Right: Asserted ordering and the `25200`-`28800` window on `final_journeys` before returning.
- Mistake: Message 5: `min(at)` parser error on unquoted `at`.
- Mistake: Message 53: it rebuilt the journey list to change at Postplatz `Pd6ad09b1` for the tram 2 to 9 journeys (the tool run used `P3b6efaff`); same departure and arrival times, and both passed.

### meeting_point

**Tool calling: passed.** Computed earliest arrival per station for each friend with hand-unrolled rounds (`f1_rb0`, `f1_al1`, ...) from `32400`, took the minimum of the later arrival, and returned `Sbb9212fa` at `33701`. Passed in 31 requests. ($0.63, 31 requests, 32.2 min)
- Right: The only run with no SQL error: it loaded with `all_varchar=true` and always wrote `c.at`, so the reserved word never bit.
- Right: Proved the round limit was enough: a fifth-round check returned `improved_before_34000` = 0 for both friends.
- Right: Compared the runner-up (`S29c8f148` at `33780`) before choosing.
- Mistake: Messages 53-58: three large queries (one returning 10,610 characters of station coordinates) only for SVG background.

**Code mode: passed.** One 5,583-character script built the indexed calls and ran the search for both friends; returned `Sbb9212fa` at `33701`, identical to the tool run. Passed in 21 requests versus 31. ($0.48, 21 requests, 11.0 min)
- Right: Batched independent queries per turn (`q1`, `q2`, `q3`), a third fewer requests than tool calling.
- Right: SVG read back and attributes checked.
- Mistake: Message 7: `FILTER (WHERE at = '' ...)` parser error on unquoted `at`; the other queries in the same script still returned, so only one retry.

### timed_tour

**Tool calling: passed.** Defined a `CREATE MACRO run_raptor(src_table)` recursive search, ran a bitmask DP over the four stations with opening windows, and returned a 5-leg tour back at `44160`. Passed in 40 requests, the most expensive tool run at $1.29. ($1.29, 40 requests, 19.2 min)
- Right: Wrapping the search in a table macro let it re-run the same search for each DP layer and for spot checks (`test_poh`, `test_mick`, `test_tu`).
- Right: Tested each segment independently with start times one second later (`40561`, `43261`, `38313`) to confirm no earlier return existed.
- Mistake: Message 15: `FILTER (WHERE at IS NULL OR at = '')` parser error on unquoted `at`, one retry.
- Mistake: Messages 37-65: about fifteen verification queries after the DP had already produced the answer; this is where most of the cost went.

**Code mode: passed.** Drove an 8,422-character script over all 24 orders using `run_sql`, then re-solved in pure Python from the CSV files, and returned the same tour back at `44160`. Passed in 26 requests versus 40 for tools, at $0.80 versus $1.29. ($0.80, 26 requests, 13.3 min)
- Right: Checked all 24 permutations and printed each arrival, not only the best.
- Right: A Python loop replaced about fifteen manual verification queries from the tool run.
- Right: Independent pure-Python solve (messages 35-37) agreed with the SQL result.
- Mistake: Message 5: `KeyError: rows` after `asyncio.gather`, because one of four results was an error dict.
- Mistake: Message 9: parser error on unquoted `at`.

### tour

**Tool calling: passed.** Built a recursive-CTE search and a `perm_dp` table extended level by level to all 120 orders of the five stations, then returned an 11-leg round trip back at `48660`. Passed in 46 requests, the most of any run. ($1.08, 46 requests, 19.7 min)
- Right: Evaluated every permutation rather than a greedy order (`-- Level 5 (120 permutations)`).
- Right: Applied the 15-minute stay as `arr_time + 900` when seeding each next level.
- Mistake: Message 17: parser error on unquoted `at`.
- Mistake: Message 23: `ConversionException: Type DOUBLE with value nan can't be cast ... INT64` in the interpolation (a 0/0 division); message 25 then failed with `Table with name "base_calls_interp" already exists` because the retry omitted `DROP TABLE`.
- Mistake: Messages 59-85: fourteen segment-by-segment re-checks and leg look-ups after the answer was known.

**Code mode: passed.** Moved the search into Python (a connection scan with `bisect` over all 120 orders), hit a 30-second sandbox time-out that reset the session, rebuilt and returned the same 11-leg tour back at `48660`. Passed in 37 requests at $1.15. ($1.15, 37 requests, 19.0 min)
- Right: Evaluated every permutation with `itertools.permutations` and compared walk-rule variants (`solve_platform_dp_fast(zero_within_station, allow_end_walk)`) before settling.
- Right: Final check script (message 71) compared SVG `data-run` values to the legs and reported `errors: []`.
- Mistake: Message 3: `SyntaxError: Unexpected indentation` from a leading space before `res = await run_sql`.
- Mistake: Messages 11-14: two parser errors on unquoted `at`, the second in the very next script.
- Mistake: Message 35: `TimeoutError: feed time limit exceeded: 30.000446583s > 30s`; the session was reset and all Python state lost. It should have split the 7,892-character model-comparison script.
- Mistake: Message 37: the rebuild failed a type check (`Cannot subscript object of type None`), one more retry.
