---
title: "Kimi K3.1 Pro 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 90%; rank 15 of 32."
canonical: https://models.pydantic.dev/models/kimi-k3.1-pro/transit_planner/
---

# Kimi K3.1 Pro 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 90%; rank 15 of 32.
>
> Markdown copy of https://models.pydantic.dev/models/kimi-k3.1-pro/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/kimi-k3.1-pro.md

| Mode         | Score | Tasks passed | Cost  | Requests | Tool calls | Time     |
| ------------ | ----- | ------------ | ----- | -------- | ---------- | -------- |
| Tool calling | 80%   | 8 of 10      | $7.41 | 331      | 440        | 51.7 min |
| Code mode    | 90%   | 9 of 10      | $5.73 | 270      | 279        | 70.9 min |

Each task was run once per mode.

## Review

Written by an LLM from the runs' transcripts.

#### Overall

Kimi-K3.1-Pro passed 17 of 20 runs: 8 of 10 with tool calling and 9 of 10 in code mode. Both `tour` runs failed, and `departure_profile` failed with tool calling. Total cost was $7.41 for tools (331 requests) and $5.73 for code mode (270 requests).

#### Where it does well

- **Reads the rules.** Every run built repeats, service-day bitmasks, untimed-call interpolation, 400 m walks and the 120 s margin. `after_midnight` loaded the previous service day with a -86400 shift in both modes.
- **Proves optimality.** It rarely stopped at the first feasible journey. Most runs iterated a label search until no state improved, or checked 3, 4 and 5 rides.
- **Catches its own bugs.** Examples: a text sort of `n` and a wrong start time (07:40 read as 28200) in `one_change` code mode, and a board before 10:00 in `tour` code mode.

#### Mistakes it makes

- **SQL window bug, unverified.** In `departure_profile` (tools), `first_value(... IGNORE NULLS) OVER (ORDER BY n DESC ROWS UNBOUNDED PRECEDING)` took the run's last timed call as the "next" one. Times were off by up to 26 s, and it never hand-checked one interpolated value.
- **Poor request budgeting on `tour`.** The tools run spent about 35 requests pasting search rounds, had 50012 by request ~73, then hit the 80-request limit with no SVG or answer. Code mode submitted 50012 and was marked wrong; the reason is not visible. It had flagged two untested doubts about its search.
- **Repeated avoidable errors.** Bare `at` (a DuckDB keyword) caused a parser error in nearly every run. Multi-statement `run_sql` calls returned only the last result and sometimes rolled back.
- **Sandbox limits ignored.** `heapq`, `time`, `yield`, `bytearray`, `next()` on generators and `html` all failed. Three code-mode runs hit the 256 MB limit and lost state.

#### Tool calling compared with code mode

Code mode was cheaper and more accurate where it moved the search into Python: `walking_change` took 13 requests against 25, `arrive_by` 18 against 35, and `departure_profile` passed because the Python interpolation was correct. Where it only wrapped single SQL calls in `run_code` (`one_change` 29 against 21, `one_vehicle` 31 against 19) it was slower and more error-prone. Tool calling with SQL alone handled single journeys well but could not finish `tour` within 80 requests.

## Runs

### one_vehicle

**Tool calling: passed.** Found no run serving both stations, widened to platforms within 400 m, and returned bus 66 `R27f8d4b1+2` from Strehlener Platz `P0091960a` at 29940 to `P6e8c05a2` at 30480 after a 399 s walk. Passed in 19 requests. ($0.38, 19 requests, 2.8 min)
- Right: Did not stop at the empty station-to-station result; applied the start-walk and end-walk rule.
- Right: Worked out the repeat index: base 27540, every 1200, earliest boardable after 29400 + 399 is `+2` at 29940.
- Right: Re-ran the search with interpolated untimed calls to confirm nothing arrives before 30480.
- Right: Reported `departure` 29400, the set-off time including the walk.
- Mistake: Three failed queries (`CROSS JOIN ... ON`, bare `at` in `CASE`, a wrong alias `o.owalk`).
- Mistake: One validation query joined the wrong place (`bp` to the destination call) and reported 1508 m as the start walk; it noticed and reran.

**Code mode: passed.** Reached the same bus 66 `R27f8d4b1+2` answer (leave 29400, board 29940, arrive 30480) but after about ten failed cells. Passed in 31 requests against 19 in tools mode. ($0.44, 31 requests, 3.2 min)
- Right: Applied start and end walks after finding no direct station-to-station run.
- Right: Rechecked with interpolated untimed calls because 68 candidate pairs had a null time at TU.
- Right: Verified the SVG markers and run by reading the file back.
- Mistake: Failed cells at messages 12, 24, 26, 28, 36, 46, 48, 54 and 56: missing `asyncio` import, `generate_series` returning a list, wrong column names, bare `at`, a wrong alias, wrong result indices, and a missing `math` import.
- Mistake: Overwrote its query string variable `q` with a test query and had to rebuild it.
- Mistake: Again used Python only to wrap SQL calls.

### saturday_direct

**Tool calling: passed.** Found the direct tram 9 `Rb28d92d7` boarding `P7fa04a55` at the interpolated time 33484 and arriving 34560, then ran four label rounds to show nothing is earlier. Passed in 19 requests but cost $0.87. ($0.87, 19 requests, 2.5 min)
- Right: Read the service bitmask correctly: `V0fbcf1ab` (64) is Sunday only and `V479271d1` (31) is Monday to Friday, so those runs were excluded on Saturday.
- Right: Interpolated the untimed origin call and audited it with a query showing `prev_departure`, `s_a`, `next_a` and the step distances.
- Right: Caught a search bug where the frontier allowed a second walk before the first ride, and rebuilt the initial labels.
- Mistake: Parser error from bare `at` in `max(CASE WHEN at IS NOT NULL ...)`.
- Mistake: Several multi-statement calls hid the counts it wanted, so convergence needed extra rounds (`improved_places` 0 only seen on round 4).
- Mistake: Highest cost of the single-journey cases for a one-leg answer.

**Code mode: passed.** A first SQL check on timed calls suggested 34320 to 35460; the Python search with interpolated calls then found `Rb28d92d7` boarding at 33484 and arriving 34560. Passed in 21 requests at half the tools cost. ($0.42, 21 requests, 8.5 min)
- Right: The search over interpolated calls corrected the earlier timed-only answer, which was 15 minutes later.
- Right: Inspected the full run in SQL to confirm the untimed origin call.
- Right: Search settled after 128 states.
- Mistake: The first direct query filtered on non-null `at` and would have given a wrong answer (35460) if trusted.
- Mistake: Imported `heapq`, which the sandbox does not have; also `next()` on a generator expression. Two failed cells.
- Mistake: Two SQL binder errors (`USING(run)`, wrong `c.service`).

### one_change

**Tool calling: passed.** Built `active_runs`, `base_calls`, `journey_calls` and `walks` tables, compared the best direct option (29160) with all two-vehicle options and returned tram 10 `Rafeef850` then tram 12 `R620ec7d9` arriving 28440. Passed in 21 requests. ($0.27, 21 requests, 3.0 min)
- Right: Counted untimed calls (163359 total, 114014 timed) and implemented the interpolation before searching.
- Right: Included start walks (14 boarding platforms) and end walks (52 pairs) in both the direct and two-vehicle queries.
- Right: Final audit query returned `faster_two_vehicle_options` 0 and `faster_direct_options` 0 with 48 s of transfer slack.
- Right: Checked the 72 s walk `P66c27b1c` to `P3b6efaff` (71.3 m) separately.
- Mistake: Two parser errors from `count(at)` at the end of multi-statement calls; it was unsure whether the earlier statements had run.

**Code mode: passed.** Did the whole search in SQL through `run_code`, fixed two of its own errors on the way (a text sort of `n` and a wrong start time), and returned the 28440 arrival. Passed in 29 requests, more than twice the tools cost. ($0.61, 29 requests, 5.9 min)
- Right: Noticed impossible results (arrival 27335 before departure 28320) and traced them to `ORDER BY n` on a varchar column; recast `n` and rebuilt.
- Right: Checked that previous-day runs end by 05:08 and cannot matter.
- Right: Recomputed the origin interpolation (27669) from coordinates by hand.
- Mistake: Read 07:40 as 28200 (that is 07:50) in the first message and searched from there, getting a 29040 arrival; only at message 41 did it rerun with 27600 and find 28440.
- Mistake: Loaded `calls` with all columns as text, which caused the lexicographic `n` ordering.
- Mistake: Used `run_code` only as a wrapper for single `run_sql` calls, so code mode gave no saving; 29 requests against 21 in tools mode.

### walking_change

**Tool calling: passed.** Found bus 62 `R76d2117b+4` to Pirnaischer Platz, a 78 m walk, then tram 2 `R3a0dccd4+54` arriving 63480, and ran label rounds to a fixed point. Passed in 25 requests, cost $0.72. ($0.72, 25 requests, 2.8 min)
- Right: When the same-platform transfer query returned nothing, it built `walk_pairs` and found the 78 s walk `P6e794064` to `P72ccec8b`.
- Right: Iterated `next_frontier` until `improved_labels` was 0 with a strict bound below 63480.
- Right: Checked the margin: 62040 + 120 + 78 = 62238 \<= 62520.
- Mistake: Four failed queries (bare `at`, a self-referenced alias `d`, `WITH` before `CREATE`, and a missing table after a rolled-back batch).
- Mistake: Tried `read_text` on `/out/journey.svg`; not readable.

**Code mode: passed.** Read the files in Python, wrote its own binary heap, ran Dijkstra over 80347 on-board calls and got the bus 62 then tram 2 journey arriving 63480. Passed in 13 requests, the fewest of any case. ($0.40, 13 requests, 8.7 min)
- Right: One search cell returned the answer; reconstruction and a check that interpolation differences were empty followed.
- Right: Wrote a custom heap when `heapq` was not available.
- Right: Reported departure 61560 from the origin platform `Pff25da30`; the search's 48 m intra-station start walk was correctly left out.
- Mistake: Two failed cells: the `heapq` import and a print error after the SVG had already been written.

### after_midnight

**Tool calling: passed.** Loaded service days 2026-338 and 2026-339 (previous day shifted by -86400), found bus 360 `R93fefd15` then bus 63 `R900bf42f+2` arriving 6420, and proved it with a layered label search to a fixed point. Passed in 30 requests. ($0.60, 30 requests, 6.0 min)
- Right: Handled the after-midnight rule: built run instances for both service days with a `-86400` shift for 2026-338.
- Right: Spotted duplicate rows from the two-day join and fixed the instance key before searching.
- Right: Ran the label-improvement rounds until `current_layer` was 0 (126 states), so the 6420 arrival was shown optimal for any number of changes.
- Right: Checked the 76 m transfer walk and the 120 s margin (5492 + 120 + 76 \<= 5700).
- Mistake: First load used several statements in one `run_sql` and only the last result came back, so services had to be re-queried.
- Mistake: Two parser errors from bare `at` (a DuckDB keyword) before quoting it as `"at"`.
- Mistake: Five separate round-by-round `run_sql` calls plus count calls to reach the fixed point; about ten requests of manual iteration.

**Code mode: passed.** Built both service days in SQL, pulled the 1712 calls in the 4000 to 6420 window into Python, ran a simple earliest-arrival search and got the same two-bus journey arriving 6420. Passed in 21 requests. ($0.53, 21 requests, 4.8 min)
- Right: Counted runs per day (10398 for 2026-338, 6852 for 2026-339) and kept previous-day runs with shifted times.
- Right: Verified the interpolation of `R93fefd15` call 100 by hand (previous departure 91800, next arrival 92160, distances 3558, 4424, 6939).
- Right: Checked the SVG markers and runs by reading the file back.
- Mistake: Fetched all 3655 places through paged `run_sql` calls (limit 200 rows) instead of reading the file in Python.
- Mistake: Two runtime errors in the search cell (`settled` used before assignment, a function not defined after a failed cell).
- Mistake: The search window was capped at the arrival it already knew (6420), so the search could only confirm, not find, the answer.

### arrive_by

**Tool calling: passed.** Built an interpolated expanded timetable, found the latest two-vehicle journey leaving 63360 (tram 9 `R1aabe4da+29`, then tram 13 `Rfd6f9e2d+67`, arriving 64440), then checked three rides and a forward closure for later departures. Passed in 35 requests. ($0.60, 35 requests, 6.0 min)
- Right: Checked that no later departure works with 3 rides (`middle_segments` join returned no rows) and then ran a frontier closure from departures after 63360 until `candidate_places` was 0.
- Right: Chose the line 13 option arriving 64440 over the line 10 option arriving 64500 for the same departure.
- Right: Verified the 64 m walk between `P3b6efaff` and `P6ea0167f` against coordinates.
- Mistake: Six failed `run_sql` calls early on: bare `at` and `days` aliases, a wrong `r.run` column, a wrong `oc.run_id` column, and a missing `s` column in the interpolation join.
- Mistake: A failed multi-statement load left no tables (`Table with name places does not exist`), so the whole load was repeated twice.
- Mistake: Tried `read_text` on `/out/journey.svg`, which is not readable; one wasted request.

**Code mode: passed.** Interpolated and expanded active runs in Python (1165 relevant runs, 30163 calls), ran a backward search and returned the 63360 departure with tram 9 then tram 13 arriving 64440. Passed in 18 requests, about 60% of the tools cost. ($0.36, 18 requests, 3.2 min)
- Right: One search cell produced the answer (`ride options 130997`, `terminal rides 1806`).
- Right: Cross-checked the chosen runs against raw calls, repeats and services in SQL.
- Right: Read the SVG back and checked the four platform markers.
- Mistake: Three runtime errors: a wrong `run` column, `next()` on a generator expression (not supported in the sandbox), and an indexing error while printing raw calls.
- Mistake: Never created the expanded tables it planned in SQL; the first attempt errored and it moved on.

### departure_profile

**Tool calling: failed.** Returned 12 journeys with the right runs and pattern, but the interpolated times are wrong (for example first departure 25353 where the passing code-mode run has 25327, and arrival 27820 against 27828). Failed. ($0.80, 37 requests, 6.2 min)
- Right: Understood the dominance rule and compared against journeys leaving after 08:00 as well.
- Right: Checked 3-, 4- and 5-ride profiles (`profile3`, `profile4`, `profile5`) and saw the 12-row frontier unchanged.
- Right: Subtracted the start walk to get the set-off time, as the question defines departure.
- Mistake: In the `base_calls` CTAS (message 19) the next timed call was taken with `first_value(CASE WHEN z."at" IS NOT NULL THEN z."at" END IGNORE NULLS) OVER (PARTITION BY run ORDER BY n DESC ROWS UNBOUNDED PRECEDING)`. In descending order that frame starts at the run's last call, so it returns the final timed call of the run, not the nearest timed call after the untimed one. `next_s` has the same fault. It should have used `last_value` over that frame, or `first_value` with `ORDER BY n ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING`.
- Mistake: Never checked one interpolated time by hand against the DATA.md formula, as it did in `one_change` and `saturday_direct`; the final check only compared the answer with its own `acalls` table (`mismatches` 0).
- Mistake: Because of the wrong times, transfers were chosen at `Pd6ad09b1` where the code-mode run changes at `P3b6efaff` for the line 2 journeys.
- Mistake: Spent 6 requests on extra-ride proofs of a profile built on wrong times.

**Code mode: passed.** Read the files in Python, ran a backward sweep with a segment tree over boarding events, got 107 departures in the window and kept 12, then validated every leg against a SQL interpolation. Passed in 25 requests. ($0.75, 25 requests, 6.7 min)
- Right: Times match the timetable (first journey leaves 25327, arrives 27420), where the tools run was off by up to 26 s.
- Right: Validated all 24 legs with an independent SQL interpolation (`status` OK) after the first check compared against raw `at` values that were null.
- Right: Found and fixed a reconstruction bug where `departure` was taken from the last board, caught by its own `assert`.
- Mistake: First full build exceeded the 256 MB sandbox limit and reset the session; it rebuilt with only active runs and calls in the time range.
- Mistake: Used `time.monotonic()` and a generator function with `yield`, both unsupported; two failed cells.
- Mistake: A broken triple-quoted string caused a Python syntax error in the validation cell.

### meeting_point

**Tool calling: passed.** Computed earliest arrivals from both origins with a cutoff, found Albertplatz `Sbb9212fa` at 33701 with two direct trams (`Rc0124950` and `Rfa439a34`), and ran frontier rounds to a fixed point. Passed in 24 requests. ($0.41, 24 requests, 3.7 min)
- Right: Started from the direct-ride meeting time 33701 as an upper bound, then showed 2-ride, 3-ride and further rounds gave no earlier common station (`improvements` 0 on the third round).
- Right: Included end walks when turning platform arrivals into station arrivals (`best_stations`).
- Right: Preferred boarding at the origin platform `Pda4a5390` at 33300 over a 353 m walk to board the same run earlier.
- Mistake: Two parser errors from bare `at` inside `FILTER` and `CASE` before quoting it.
- Mistake: Unsure what `departure` should mean; reported the first board times 33300 and 32460, while the code-mode run reported 32400 for both and also passed.

**Code mode: passed.** Ran a Python earliest-arrival search from each origin (about 2.2 million relaxations each) and found Albertplatz at 33701, both friends on direct trams. Passed in 18 requests. ($0.41, 18 requests, 12.6 min)
- Right: Full-day search from both origins without a cutoff, then intersected station arrivals.
- Right: Checked the interpolated Albertplatz time for `Rc0124950` in both Python and SQL.
- Right: Confirmed that no station is reached by both before 33701 (`intersection 0`).
- Mistake: Reported `departure` 32400 for both journeys although the trams leave at 33300 and 32460; it passed.
- Mistake: Two failed cells: a quote typo and `time.monotonic()`.
- Mistake: Ran a SQL expansion (`expanded_calls` 160366) and then redid the same work in Python.

### timed_tour

**Tool calling: passed.** Chained direct-leg queries by hand into a six-leg tour (Prohlis, TU, Pohlandplatz, Mickten) returning at 44160, and argued optimality from Mickten opening at 11:45. Passed in 41 requests. ($0.84, 41 requests, 6.2 min)
- Right: Saw that Mickten cannot be left before 43200 and that tram 9 `R20f18e60+34` at 43260 arrives 44160, then showed no return with up to 2 changes beats it.
- Right: Found the Wasaplatz connection (tram 13 arriving 36300, bus 61 `R2f82e7ea+4` at 36838) that gets to TU at 37200.
- Right: Final check query confirmed `stay_ok` and `window_ok` for all four visits.
- Mistake: The route was assembled leg by leg from the model's own guesses about the order, not by a search over orders; it worked because the last visit's opening time fixes the return. The code-mode run found a five-leg tour with the same arrival.
- Mistake: One validation query used guessed `n` values and returned wrong platforms; redone.
- Mistake: Five failed queries (bare `at`, a `LATERAL` syntax error, a missing table after a rolled-back batch, a missing column `s`, an ambiguous `kind`).

**Code mode: passed.** After a memory reset, built a connection-scan routine and a dynamic programme over (visited set, last station) with the opening windows, giving a five-leg tour back at 44160. Passed in 29 requests. ($0.85, 29 requests, 8.3 min)
- Right: Searched all visit orders: states for 2, 3 and 4 visits were enumerated before picking the return.
- Right: Found a five-leg tour (bus `Rf679205e+8` straight from Prohlis to TU) where the tools run used six legs.
- Right: Used the start walk: 320 m to `P9cd5b9a9`, boarding at 32743.
- Mistake: First Dijkstra attempt hit the 256 MB memory limit and reset the session.
- Mistake: Seven more failed cells: a syntax error, `yield`, a tuple index mix-up (`a[1]` was the time, not the place), `time.time`, `bytearray`, `next()` on a generator, and `import html`.
- Mistake: After the reset it did not use `run_sql` again and read the files directly.

### tour

**Tool calling: error.** Ran a label-setting search in SQL over (platform, visited mask) states, reached a candidate return of 50012 after about 75 requests, and hit the 80-request limit while validating it and before writing the SVG. No output. ($1.93, 80 requests, 12.6 min)
- Right: Built a working state search in DuckDB with a bitmask per visited station and a distance-based lower bound (`tour_lb`) to order the pending states.
- Right: Kept improving the bound: 57120, then 51956, 50460, 50340 and 50012, and emptied `pending`.
- Right: Noticed it had dropped mask-31 states from `pending` and that visits reached by a walk were missing, and added both.
- Mistake: Each search round was one hand-pasted `run_sql` script; about 35 requests went on rounds of 1000 to 4000 states.
- Mistake: Around 12 failed calls: missing `ELSE`, CTAS with column types (three times), a `DECIMAL` cast in the recursive CTE, a wrong `rem`/`vis` recursion giving 5 bounds, missing `travel_dist`, a malformed final query (twice), and `by` syntax on the last call.
- Mistake: The first focused pass (messages 39 to 72) explored only states with 3 visits, found 57120 and 51956, and had to be redone from the paused frontier.
- Mistake: Did not write a provisional `/out/journey.svg` or call `final_result` once it had 50012 at request ~73; it started a new validation table instead. The code-mode run submitted the same 50012 arrival and was marked wrong, so this run would probably have failed anyway.

**Code mode: failed.** Ran a Python label search over (platform, visited mask) in batches of `search_step(5000)`, fixed a start-time bug, and submitted an 11-leg tour returning at 50012. Marked as failed; the conversation does not show which check it failed. ($0.97, 65 requests, 9.0 min)
- Right: A greedy pass gave an upper bound of 53083 in 34 pops, which pruned the exact search.
- Right: Caught that the first result (49472) boarded at 35964, before the 10:00 start, because the initial `ready` was set to 36000 - 120; fixed it and reran.
- Right: Validated every leg, walk, 120 s margin and 900 s stay (`valid` true), and checked 11 `data-run` lines and 27 markers in the SVG.
- Mistake: Submitted 50012 as optimal while its own notes (messages 91 and 121) said the model might lack visits reached on foot and that the dominance on (platform, mask) might be flawed; neither was tested. The tools run reached the same 50012 with a different search, so the fault may lie elsewhere.
- Mistake: About 25 requests were single `search_step(n)` calls; the whole search was run twice (about 56,000 pops each) because of the start-time bug.
- Mistake: Memory limit exceeded once (message 42), losing all state; several more failed cells (`del`, `map`, `bytearray`, `next`).
