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

# Grok 4.6 on Pydantic AI Transit Planner

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

| Mode         | Score | Tasks passed | Cost   | Requests | Tool calls | Time     |
| ------------ | ----- | ------------ | ------ | -------- | ---------- | -------- |
| Tool calling | 80%   | 8 of 10      | $10.06 | 621      | 775        | 52.7 min |
| Code mode    | 100%  | 10 of 10     | $6.46  | 294      | 294        | 55.9 min |

Each task was run once per mode.

## Review

Written by an LLM from the runs' transcripts.

#### Overall

`gateway/openrouter:x-ai/grok-4.6` passed 18/20 runs: 8/10 in tools and 10/10 in code mode. Both failures exhausted the 80-request limit; neither was a provider failure. Code mode was the stronger choice on these cases, especially for tours.

#### Where it does well

Both modes solved all eight non-tour cases, handling interpolation, repeated-run identifiers, walking, transfer margins, and overnight service-day offsets. Both returned 12 departure-profile journeys and the same optimal meeting time, `33701`.

Code mode supplied useful checks: `arrive_by` tested the one-second boundary between feasible `63360` and infeasible `63361`; `departure_profile` checked all 24 SVG run identifiers; `tour` used `f[mask][i]` dynamic programming and verified additional routing rounds.

#### Mistakes it makes

Unquoted SQL `at` caused errors in 19/20 runs. Repairs sometimes changed surrounding expressions repeatedly instead of quoting the identifier. Other recurring problems included incorrect aliases, schema-field guesses, and unsupported window-function syntax.

Tool mode spent heavily on small exploratory queries and manual routing rounds. `timed_tour` found a return at `44160` but exhausted its budget inspecting schedules before submission. `tour` remained in segment exploration.

Code mode exceeded the 256 MiB sandbox limit twice, resetting `one_change` and `departure_profile`. It recovered, but also tried unsupported `yield`, `del`, imports, filesystem access, and timing functions. Passing results sometimes relied on restricted searches: `departure_profile` capped legs and waiting; `timed_tour` tested selected orders rather than every permutation. The tool-mode `walking_change` SVG also mislabeled departure by one minute.

#### Tool calling compared with code mode

Code mode used fewer requests on every paired case: 294 total versus 621, a 52.7% reduction. Total reported cost fell from $10.0610 to $6.4561, down 35.8%, while completing both tours. Python loops and reusable routing functions reduced conversational overhead, although compact data structures and sandbox-compatible code were necessary.

## Runs

### one_vehicle

**Tool calling: passed.** Found a 399-second initial walk followed by bus `R27f8d4b1+2`, arriving at `30480`. Passed in 27 requests. ($0.39, 27 requests, 3.8 min)
- Right: Distinguished journey departure `29541` from vehicle boarding time `29940`.
- Right: Searched nearby boarding and alighting platforms while retaining the one-vehicle restriction.
- Right: Returned `P0091960a` to `P6e8c05a2` and drew the walk separately from the vehicle leg.
- Mistake: Repeated batches of independent count queries returned only their final result; eventually replaced them with `UNION ALL`.
- Mistake: Untimed-call statistics failed on unquoted `at`.
- Mistake: The first `cand_times` query referenced `cs` outside its subquery scope; the corrected query used the outer alias.

**Code mode: passed.** Used SQL to narrow candidate runs and Python to interpolate and evaluate them. Returned the correct walk-plus-bus journey in 22 requests. ($0.34, 22 requests, 3.3 min)
- Right: Fetched the 34 candidate runs in batches of three and evaluated repeats.
- Right: Verified the initial distance `398.1017457886865` metres, rounded to 399 seconds.
- Right: Returned journey departure `29541`, boarding `29940`, and arrival `30480` on `R27f8d4b1+2`.
- Mistake: One candidate-statistics query failed on unquoted `at`.
- Mistake: Fetched an initial batch of 17 runs, then fetched those runs again in the complete batched collection.
- Mistake: During final filesystem inspection, `Path('/').iterdir()` raised `PermissionError`; this inspection was unnecessary for writing `/out/journey.svg`.

### saturday_direct

**Tool calling: passed.** Returned tram `Rb28d92d7`, boarding at `33484` and arriving at `34560`. Passed, but required 51 requests for a one-leg answer. ($0.71, 51 requests, 3.5 min)
- Right: Applied Saturday service selection and distance-based interpolation for the boarding time.
- Right: Checked walking and transfer alternatives rather than assuming the direct tram was optimal.
- Right: Marked `P7fa04a55`, `P1093f876`, and the run in the SVG.
- Mistake: Four schema queries requested nonexistent `column_type`.
- Mistake: Repeatedly changed expressions around bare `at`—including `coalesce(at, -1)`, `ifnull(at, -1)`, `typeof(at)`, and `min(at)`—without fixing the reserved identifier. Qualification as `c.at` finally worked.
- Mistake: Later reintroduced bare `at` in interpolation and queried nonexistent `arr` instead of `arrival` during verification.

**Code mode: passed.** Found and verified the direct tram journey `33484..34560`. Passed in 16 requests, the fewest in either mode. ($0.32, 16 requests, 2.7 min)
- Right: Handled Saturday services, repeat expansion, access flags, and distance-based interpolation.
- Right: Ran additional routing rounds to check whether transfers improved the direct arrival.
- Right: Generated the SVG with `data-run="Rb28d92d7"` and both required platform markers.
- Mistake: Initial SQL statistics used `COUNT(at)`, causing a parser error.
- Mistake: Loaded the SQL tables and then reread the timetable files into Python, duplicating ingestion.

### one_change

**Tool calling: passed.** Found the permitted two-vehicle journey departing at `27669` and arriving at `28440`. Passed in 55 requests. ($0.93, 55 requests, 4.8 min)
- Right: Selected `Rafeef850` and `R620ec7d9`, with a 72-second walk between `P66c27b1c` and `P3b6efaff`.
- Right: Enforced `board_time >= alight_time + 120 + walk`; the connection had 48 seconds beyond the required margin.
- Right: Queried for feasible earlier arrivals and found none in the constructed two-leg candidates.
- Mistake: Both statistics and the first interpolation query failed on unquoted `at`.
- Mistake: Used unsupported DuckDB syntax `LAST_VALUE(timed_s) IGNORE NULLS OVER (...)` during interpolation.
- Mistake: Inspected numerous individual runs before constructing the first-leg/second-leg join, increasing request use.

**Code mode: passed.** Recovered from a memory reset and found the correct two-tram journey arriving at `28440`. Passed in 33 requests. ($0.49, 33 requests, 5.1 min)
- Right: Rebuilt active calls as compact tuples after the reset.
- Right: Compared one-vehicle and two-vehicle options, improving arrival from `29160` to `28440`.
- Right: Verified the 72-second walk and readiness at `28152` for the `28200` connection.
- Mistake: An exploratory SQL query used unquoted `at`.
- Mistake: Service setup included `active_services.add_if = None`, which raised `AttributeError`.
- Mistake: Indexing 233358 expanded calls exceeded the 256 MiB memory limit and reset state.
- Mistake: The rebuilt `expand_ids` used unsupported `yield`; replacing it with a list resolved the error.

### walking_change

**Tool calling: passed.** Found bus `R76d2117b+4` followed by tram `R3a0dccd4+54`, arriving at `63480`. Passed in 62 requests. ($0.99, 62 requests, 2.5 min)
- Right: Computed the Prager Straße-to-Altmarkt walk as 341 seconds.
- Right: Verified `61920 + 120 + 341 = 62381`, before the second boarding at `62458`.
- Right: Checked additional routing rounds and earlier tram alternatives.
- Mistake: Repeated untimed-call queries with unquoted `at`, causing three parser errors.
- Mistake: Later requested `"at"` from `day_calls_interp`, which exposed `arr` instead.
- Mistake: The final SVG title said `17:05`, although the submitted departure `61560` is `17:06`.

**Code mode: passed.** Found the same two-leg journey as tool mode, departing at `61560` and arriving at `63480`. Passed in 21 requests. ($0.47, 21 requests, 5.4 min)
- Right: Used a spatial walking index and iterative routing; arrival reached `63480` in round 2 and stopped improving by round 4.
- Right: Explicitly verified `61920 + 120 + 341 = 62381 <= 62458`.
- Right: Generated the correct run/platform SVG, with the departure label correctly showing `17:06`.
- Mistake: Initial SQL inspection used bare `at` in both null checks and `MIN(at)/MAX(at)`, causing parser errors.
- Mistake: Loaded SQL tables and then reread all timetable files into Python before routing.

### after_midnight

**Tool calling: passed.** Expanded Friday and Saturday services, shifted Friday times by `-86400`, and found the two-bus journey arriving at `6420`. Submitted the journey and SVG successfully in 60 requests. ($0.88, 60 requests, 5.2 min)
- Right: Used `run_sql` to interpolate untimed calls and expand repeat identifiers.
- Right: Returned `R93fefd15` from `P99202dfd` at `5280` to `P96dc02de` at `5492`, then `R900bf42f+2` from `P983fcb99` at `5700` to `P453df67b` at `6420`.
- Right: Checked earlier destination arrivals and additional transfers before calling `write_file` and `final_result`.
- Mistake: During initial inspection, `run_sql` rejected `WHERE at IS NULL`; the next request repeated it unchanged. Quoting `"at"` fixed it.
- Mistake: Early batches contained multiple independent `SELECT` statements although only the last result was returned, prompting additional queries.

**Code mode: passed.** Used Python routing over Friday and Saturday trips and returned the same `5280..6420` journey as tool mode. Passed in 34 requests. ($0.74, 34 requests, 6.0 min)
- Right: Explicitly applied `FRI_SHIFT = -86400` and interpolated the relevant base runs.
- Right: Built a spatial walking index and searched 936 trips within its selected horizon.
- Right: Verified the two bus legs and wrote the required SVG.
- Mistake: Early `run_sql` statistics repeatedly used unquoted `at`.
- Mistake: `expand_run_ids` used unsupported `yield`; recovered by returning a list.
- Mistake: After routing found `6420`, spent many further calls inspecting alternative trips and distances individually.

### arrive_by

**Tool calling: passed.** Found the latest departure, `63360`, with arrival `64440`, before the `64800` deadline. Passed after 62 requests. ($0.88, 62 requests, 3.1 min)
- Right: Constructed first and last legs, ranked candidates by `departure DESC, arrival ASC`, and checked later-departing three-leg alternatives.
- Right: Selected `R1aabe4da+29` followed by `Rfd6f9e2d+67`; verified the transfer walk was 64 seconds.
- Right: Wrote the SVG with both runs and all four boarding/alighting platforms.
- Mistake: Initial statistics used unquoted `at`, causing a parser error.
- Mistake: Repeat expansion used `JOIN generate_series(1, 200) g(k) ON k.k <= rp.count`; `k.k` was invalid and should have been `g.k`.
- Mistake: During final verification, queried `place` from `places`, whose identifier column is `ref`.

**Code mode: passed.** Combined a Python routing function with binary search to find latest departure `63360` and arrival `64440`. Passed in 28 requests. ($0.50, 28 requests, 4.2 min)
- Right: Tested the boundary explicitly: starting at `63360` succeeded, while `63361` produced arrival `64860`, beyond the deadline.
- Right: Reconstructed `R1aabe4da+29` and `Rfd6f9e2d+67` and checked the 64-second transfer walk.
- Right: Generated the SVG and submitted the correct journey.
- Mistake: `sorted(Path('/data').iterdir())` failed because the sandbox could not compare `PosixPath` objects; adding `key=str` fixed it.
- Mistake: Repeated bare-`at` SQL variants across three exploration calls before quoting the identifier.
- Mistake: Loaded tables with `run_sql`, then reread timetable files into Python, duplicating ingestion.

### departure_profile

**Tool calling: passed.** Returned 12 nondominated journeys, from departure/arrival `25327/27420` through `28620/30780`. Passed, but used 76 of the 80 available requests. ($1.33, 76 requests, 8.3 min)
- Right: Applied departure/arrival dominance before restricting the answer to `25200..28800`.
- Right: Compared two-vehicle candidates with three-vehicle alternatives and checked walking and transfer margins.
- Right: Produced the full journey list and SVG.
- Mistake: Schema inspection requested nonexistent `information_schema.columns.column_type`; the correct field was `data_type`.
- Mistake: The initial call-count query used `COUNT(at)` without quoting the identifier.
- Mistake: The first Pareto query put a window function in `WHERE`; corrected it using nested queries and `LAG(min_arr_so_far)`.
- Mistake: Materialized 227688 same-platform and 1224027 walking-transfer combinations, followed by many separate counts and verification queries, leaving little request headroom.

**Code mode: passed.** Recovered from a sandbox memory reset and returned all 12 required journeys. Passed in 41 requests. ($1.07, 41 requests, 9.2 min)
- Right: Rebuilt using compact base-run records and repeat offsets after exceeding memory.
- Right: Evaluated 311 initial boarding options through `36000`, including departures after the requested window, before applying dominance.
- Right: Checked the SVG programmatically: no required platforms or runs were missing, with 24 run identifiers present.
- Mistake: Building expanded timetable indexes exceeded the 268435456-byte limit and reset the session.
- Mistake: Recovery attempted unsupported `del`, unavailable `heapq`, referenced undefined `board_deps`, and later imported unavailable `OrderedDict`.
- Mistake: The replacement search imposed `MAX_LEGS = 3` and `MAX_WAIT = 2400`, restrictions absent from the question. They did not prevent this pass, but the search was not generally exhaustive.

### meeting_point

**Tool calling: passed.** Computed station arrival times for both passengers and selected Albertplatz, `Sbb9212fa`, at `33701`. Passed in 68 requests. ($0.98, 68 requests, 6.2 min)
- Right: Minimized the later of the two station arrivals.
- Right: Returned `Rc0124950` arriving at `33701` and `Rfa439a34` arriving at `33692`.
- Right: Ran successive reachability rounds until no further trips could be caught and verified the selected runs.
- Mistake: Initial untimed-call statistics failed on unquoted `at`.
- Mistake: The first meeting-ranking query selected `m.station` from `CROSS JOIN (SELECT 1) m(station)`, returning a dummy identifier; the next query correctly selected `a.station`.
- Mistake: The coordinate query used ambiguous `east` and `north`; qualifying them with `tc` fixed it.
- Mistake: Manually repeated many SQL reachability rounds and inspected several alternatives after identifying the meeting.

**Code mode: passed.** Computed arrivals from both origins and minimized `max(sa1[s], sa2[s])`, selecting Albertplatz at `33701`. Passed in 32 requests. ($0.71, 32 requests, 4.7 min)
- Right: Compared station arrivals for 1120 stations reachable by both passengers.
- Right: Verified interpolated arrivals `33701` and `33692` against original calls.
- Right: Simplified the first reconstructed route to boarding `Rc0124950` directly at the origin at `33300`, retaining the optimal meeting time.
- Mistake: Initial SQL inspection repeated unquoted `at` in null checks.
- Mistake: The first reconstructed route unnecessarily rode `R465985dd`, walked, and then boarded `Rc0124950`; later inspection found the simpler direct boarding used in the final answer.
- Mistake: Continued inspecting several alternative trips after determining the optimal meeting station.

### timed_tour

**Tool calling: error.** Found the sequence Prohlis → Technische Universität → Pohlandplatz → Mickten and a return at `44160`, but never submitted it. The run exhausted all 80 requests with no final output. ($1.59, 80 requests, 8.3 min)
- Right: Built interpolated, repeated timetable events and walking connections.
- Right: Identified the five runs used by the passing code-mode solution, including `Rf679205e+8` and the return `R20f18e60+34`.
- Right: Confirmed the return arrival `44160` in both direct and additional-round queries.
- Mistake: Spent roughly the first 40 requests on loading, exploratory statistics, and helper tables before starting routing.
- Mistake: Repeated unquoted-`at` errors and initialized `raptor_arr` from nonexistent `platforms.place` instead of `ref`.
- Mistake: After finding the complete candidate, continued inspecting departures and full run schedules; the last call listed `R20f18e60+34`. It should have reserved requests for visit-time validation, `write_file`, and `final_result`, and consolidated the search.

**Code mode: passed.** Returned a five-leg tour through Prohlis, Technische Universität, Pohlandplatz, and Mickten, arriving back at `44160`. Passed in 36 requests. ($1.01, 36 requests, 8.5 min)
- Right: Used `max(arrival, opening) + 900` and rejected visits whose required stay exceeded closing time.
- Right: Accounted for the 117-second initial walk from Prohlis when reporting visit departure `35523` before boarding at `35640`.
- Right: Verified selected calls, interpolation, return options, and produced the SVG.
- Mistake: Repeated unquoted-`at` statistics, attempted forbidden root-directory listing, and called unsupported `time.time()`.
- Mistake: Tested 13 handpicked order entries, including two duplicates, rather than all 24 permutations. The selected order passed, but the conversation did not establish an exhaustive order search.
- Mistake: Created an initial SVG string and then generated the final SVG in a separate call.

### tour

**Tool calling: error.** Built routing tables and explored individual tour segments, but exhausted 80 requests before completing the round trip. No answer or SVG was submitted. ($1.36, 80 requests, 6.9 min)
- Right: Implemented service filtering, interpolation, repeat expansion, walking links, and the 120-second change margin.
- Right: Constructed visit-order permutations and explored connections between the required stations.
- Mistake: Preprocessing encountered bare-`at` errors, a missing `sat_calls_raw` table following failed creation, invalid `IGNORE NULLS` placement, and ambiguous `station`.
- Mistake: Ranked visit orders using a fixed `tmat` derived from departures at `36000`, then manually explored an order. Those durations do not account for later departures after visits; a time-dependent subset search was needed.
- Mistake: Near the end, a walk query referenced unjoined `p.name`; the final query still investigated Waldschlößchen-to-Altpieschen connections.
- Mistake: Should have consolidated routing and order evaluation and reserved calls for reconstruction and submission.

**Code mode: passed.** Used time-dependent routing and subset dynamic programming to choose the five-stop order, returning at `48660`. Passed with 11 vehicle legs in 31 requests. ($0.82, 31 requests, 6.8 min)
- Right: Implemented `f[mask][i]` for earliest arrival after visiting a subset, with `STAY = 900`.
- Right: Selected Julius-Vahlteich-Str. → Altpieschen → Waldschlößchen → Marienberger Straße → Wasaplatz.
- Right: Reconstructed all segments and verified that increasing routing rounds from 8 to 12 did not change their arrivals.
- Right: Detected that the Julius-to-Altpieschen segment improved from `40440` with two rounds to `40320` with three.
- Mistake: Initial call statistics failed on unquoted `at`.
- Mistake: A routing benchmark attempted unsupported `time.time()`; rerunning without timing recovered.
- Mistake: Built the SVG twice, adding station markers in the second version.
