---
title: "GLM 5.3 on Pydantic AI - SQL data analysis"
description: "Planning journeys by querying a real Dresden public transport timetable with SQL, with an SVG map of each answer. Tool calling 50%, code mode 70%; rank 25 of 44."
canonical: https://pydantic.dev/models/list/glm-5.3/sql_data_analysis/
---

# GLM 5.3 on Pydantic AI - SQL data analysis

> Planning journeys by querying a real Dresden public transport timetable with SQL, with an SVG map of each answer. Tool calling 50%, code mode 70%; rank 25 of 44.
>
> Markdown copy of https://pydantic.dev/models/list/glm-5.3/sql_data_analysis/. Index for agents: https://pydantic.dev/models/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://pydantic.dev/models/api/select` with a JSON body such as `{"description": "what the agent does"}`. It returns up to five ranked models with reasons. Format: https://pydantic.dev/models/select.md
- Search models by name: `GET https://pydantic.dev/models/api/search?query=<text>`
- List, filter and sort models: `GET https://pydantic.dev/models/api/models`, for example `?weights=open&max_price=2&sort=efficiency`
- One model in full: `GET https://pydantic.dev/models/api/models/<slug>`
- Any other question about the models: `GET https://pydantic.dev/models/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://pydantic.dev/models/mcp`. More: https://pydantic.dev/models/usage.md

About the benchmark: https://pydantic.dev/models/benchmarks/sql_data_analysis.md. The model on every Pydantic AI benchmark: https://pydantic.dev/models/list/glm-5.3/pydantic_ai.md

| Mode         | Score | Tasks passed | Cost   | Requests | Tool calls | Time      |
| ------------ | ----- | ------------ | ------ | -------- | ---------- | --------- |
| Tool calling | 50%   | 5 of 10      | $12.87 | 531      | 626        | 175.1 min |
| Code mode    | 70%   | 7 of 10      | $14.22 | 466      | 466        | 217.2 min |

Each task was run once per mode.

## Review

Written by an LLM from the runs' transcripts.

#### Overall

GLM-5.3 passed 5 of 10 cases with normal tool calling and 7 of 10 in code mode. Both modes got the single-ride and simple cases right: one_vehicle, saturday_direct, arrive_by and one_change. Both failed the two multi-stop tours, tour and timed_tour. Runs were expensive, often $0.85–$3 and 35–80 requests per case.

#### Where it does well

- It understands the timetable model. Service days running past midnight are converted correctly (`t - 86400` for day 338 runs), as are `+k` repeat names and distance-based interpolation of untimed calls.
- It checks its own work. It verifies legs against the raw calls and re-derives interpolated times by hand. One_change in tools mode noticed at message 59 that `read_text` had cut lines longer than 300 characters, then recovered the full rules with `read_csv`.
- The SVGs always carried the required `data-run` and `data-place` attributes.

#### Mistakes it makes

- **Missing the transfer rules (3 tools failures).** The `read_text` tool cut off the DATA.md rules. In after_midnight, meeting_point and walking_change the agent never saw "at least 120 seconds plus the walk" or "`N` and `R` calls cannot be used". It gave journeys with changes that were too short:

  - meeting_point: a 76 s change.
  - after_midnight: 150 s for a walk of about 125 m, which needs at least 245 s. It had already found the valid answer, arriving at 6420, and threw it away.
  - walking_change: a 180 s change that included a walk.

  Saturday_direct also skipped the rules but passed, because a direct ride has no change.

- **Running out of requests (3 cases).** Tools tour and timed_tour ran out while still tracing parent pointers or fixing SQL errors. Code-mode departure_profile had already worked out the journeys but ran out while assembling the SVG piece by piece.

- **Wrong tour answers (2 code-mode cases).** In tour, the final answer matched the first seed order exactly, after a DP that had over-pruned. In timed_tour, the answer came from an A\* search the agent itself called heuristic. Both were rejected, and the conversations do not show the exact flaw.

#### Tool calling compared with code mode

Code mode read the whole of DATA.md in one `pathlib` call. That alone turned the three failures caused by missing rules into passes: after_midnight, meeting_point and walking_change. It also finished one of the tours instead of running out of requests, though with a wrong answer.

Code mode is not cheaper. Costs were similar or higher (timed_tour $3.06, departure_profile $3.03), and it sometimes used more requests on trivial cases (one_vehicle: 41 against 26). It also lost departure_profile, which tools mode passed, by spending its last requests on the SVG.

## Runs

### one_vehicle

**Tool calling: passed.** It found the single bus ride `R27f8d4b1+2` from `P0091960a` at 29940 to `P6e8c05a2` at 30480. Passed cheaply (26 requests, $0.35). ($0.35, 26 requests, 8.6 min)
- Right: Efficient and correct, with the same answer as code mode

**Code mode: passed.** Gave the same single ride as tools mode, `R27f8d4b1+2`. Passed. ($0.68, 41 requests, 13.5 min)
- Right: Correct
- Mistake: 41 requests, against 26 in tools mode, for a trivial query

### saturday_direct

**Tool calling: passed.** It found the direct tram 9 run `Rb28d92d7`, departing 33484 and arriving 34560. Passed. ($0.95, 39 requests, 16.5 min)
- Right: Correct direct journey, the same as code mode
- Mistake: Never read the rules section, so the pass was partly luck: a single ride needs no change margin

**Code mode: passed.** Found the direct tram 9 `Rb28d92d7`, departing 33484 and arriving 34560. Passed. ($0.96, 33 requests, 19.4 min)
- Right: Correct in 33 requests

### one_change

**Tool calling: passed.** At message 59 it found that `read_text` had cut lines longer than 300 characters, re-read DATA.md through `read_csv`, and then found the 2-tram journey arriving at 28440. Passed, after 53 requests. ($0.88, 53 requests, 12.9 min)
- Right: Noticed DATA.md was cut off and recovered the full rules with SQL
- Right: Used a 72 m walk between platforms at Straßburger Platz correctly, inside the margin
- Mistake: Spent about 58 messages working without the rules before finding them

**Code mode: passed.** Gave the same journey as tools mode, arriving at 28440. Passed, with fewer requests (36). ($0.80, 36 requests, 15.9 min)
- Right: Correct and more efficient than in tools mode
- Mistake: The SVG was over 100 KB because it plotted background dots for every platform. Harmless, but bloated.

### walking_change

**Tool calling: failed.** It answered bus `R76d2117b+4`, then `Rd49d751b+59` boarding `P72ccec8b` 180 s after alighting at `P6e794064`, arriving at 63180. Failed: code mode passed with a later connection at 62520, arriving at 63480. ($0.73, 51 requests, 14.0 min)
- Right: Found the right first leg and the right transfer platforms
- Mistake: Never read the change-margin or walking rules: '120 seconds' does not appear in its conversation
- Mistake: Its 180 s change includes a walk between two platforms. It needed 120 s plus the walk time and did not leave enough, so it caught a vehicle one departure too early.

**Code mode: passed.** It found `R76d2117b+4` then `R3a0dccd4+54`, boarding at 62520 so that the 120 s plus walk margin holds, arriving at 63480. Passed. ($0.84, 35 requests, 16.7 min)
- Right: Applied the change margin with the walk correctly, the point of this case
- Mistake: The SVG was about 165 KB of background platform dots

### after_midnight

**Tool calling: failed.** It built service-day, interpolation and repeat tables in DuckDB and ran rounds of station relaxation. It answered a 3-leg journey arriving at 5460, but the tram 11 → tram 13 change at Lennéplatz breaks the 120 s plus walk change margin. Failed. ($0.85, 36 requests, 16.5 min)
- Right: Worked out correctly that Friday (day 338) runs with times above 86,400 give the night network, and converted them to Saturday times (`abs = t - 86400`)
- Right: Interpolated untimed calls correctly and expanded `+k` repeats
- Mistake: Message 3: `read_text` cut DATA.md off just after the first rule, and the agent never read the rest. It never saw the 120 s change margin, the 400 m walk limit, or that `R` calls cannot be used. In message 19 it chose to treat `R` as allowed.
- Mistake: Its leg 2 arrives at `P6601f03b` at 4980 and leg 3 boards `P0a9e487a` at 5130. That is only 150 s, and the platforms are about 125 m apart, so it needed at least 245 s. The correct answer was the 2-leg journey arriving at 6420 (`R93fefd15` → `R900bf42f+2`), which the agent had already found in round 2 and then discarded.

**Code mode: passed.** It read the full DATA.md with `pathlib` and found bus 360 `R93fefd15` then bus 63 `R900bf42f+2`, arriving at 6420. Passed. ($1.20, 40 requests, 20.3 min)
- Right: Read the whole rules file in its first call
- Right: Handled the Friday service day running past midnight correctly

### arrive_by

**Tool calling: passed.** It read the full rules and found the latest departure at 63360 that still arrives by 18:00: `R1aabe4da+29` then `Rfd6f9e2d+67`, arriving at 64440. Passed, after 56 requests. ($0.91, 56 requests, 12.6 min)
- Right: Got the full rules text, including the change margin
- Right: Gave the same answer as code mode
- Mistake: 56 requests is a lot for a 2-leg arrive-by query

**Code mode: passed.** Gave the same answer as tools mode (`R1aabe4da+29` then `Rfd6f9e2d+67`, departing 63360). Passed, after 52 requests. ($0.98, 52 requests, 14.9 min)
- Right: Correct latest departure
- Mistake: Request count was no lower than in tools mode

### departure_profile

**Tool calling: passed.** It listed the Pareto-optimal journeys between 07:00 and 08:00, alternating the `R77afbc0f+k` and `R45005fd8+k` first legs. Passed, but it was the most expensive tools run that finished ($2.06, 68 requests). ($2.06, 68 requests, 23.4 min)
- Right: Applied the 'leaves no earlier and arrives no later' dominance rule correctly over many departures
- Right: Saw the rules section of DATA.md
- Mistake: Used 68 of the 80 allowed requests, close to the limit

**Code mode: error.** It worked out the profile journeys, then spent its last requests building the SVG in pieces, with errors such as `'list' object has no attribute 'append'`. It hit the 80-request limit before submitting. ($3.03, 80 requests, 31.9 min)
- Right: Its search reached the SVG stage, so the routing was done
- Mistake: Spent many late requests assembling and re-checking the SVG piece by piece instead of submitting
- Mistake: Never called `final_result` before the limit, at a cost of $3.03

### meeting_point

**Tool calling: failed.** It answered a meeting at Pirnaischer Platz (`S11373b25`) at 33600, but the second friend's change takes only 76 s. Failed; code mode's answer was 33701 at `Sbb9212fa`. ($0.89, 42 requests, 15.3 min)
- Right: Set up the problem correctly: the meeting time is the later of the two arrivals, minimised over stations
- Mistake: Never read the rules section of DATA.md: '120 seconds' does not appear anywhere in its conversation
- Mistake: The second journey alights at `P07fc86e4` at 33060 and boards `R367f07a7` at 33136, which breaks the 120 s minimum change time. This made the meeting look earlier than any valid one.

**Code mode: passed.** It found a meeting at `Sbb9212fa` at 33701, with one ride for each friend. Passed. ($1.10, 38 requests, 20.6 min)
- Right: Applied the change margin and walks correctly, unlike in tools mode

### timed_tour

**Tool calling: error.** It tried to solve the 4-station tour with opening windows through repeated SQL relaxation. It was still checking segments and fixing SQL errors (`window function calls cannot be nested`, missing column `at`) when it hit the 80-request limit, with no answer. ($2.38, 80 requests, 25.4 min)
- Right: Saw the full rules
- Mistake: Used many small SQL steps for a search over visit orders. A set of tables covering every visit order, or a more compact search, was needed to finish within budget.
- Mistake: Still hitting SQL errors at requests 77–79

**Code mode: failed.** It wrote an A\* search over (platform, mask) states with the opening windows and cross-checked it with a second run without the risky heuristics. It returned a 6-leg tour back at 48960. The grader rejected it. ($3.06, 62 requests, 36.6 min)
- Right: Built a rule-by-rule validator for the itinerary and checked the repeat offsets
- Right: Checked that /out persisted between calls
- Mistake: Its search relied on heuristics it called 'aggressive' and risky. Both the main run and the cross-check share the same visit and window state machinery, so the cross-check could not catch an error in how it modelled visits. The conversation does not show which rule or optimum it missed.
- Mistake: Cost $3.06, the most expensive case

### tour

**Tool calling: error.** It ran a (platform, visited-set mask) label search in SQL. It was tracing parent pointers back from a found solution, one query at a time, when it hit the 80-request limit. No answer, $2.88. ($2.88, 80 requests, 29.8 min)
- Right: The state design with a visited mask and margin flag was sound
- Mistake: Reconstructed the path one parent per request near the end, which used up the remaining budget

**Code mode: failed.** It ran a connection-scan search with a DP over visit orders and returned a 12-leg tour back at 48660. That was exactly the return time of its first hand-picked seed order. The grader rejected it. ($1.57, 49 requests, 27.5 min)
- Right: Caught its own mistake converting 10:05 to seconds by hand and rebuilt the legs from the program's output
- Right: Checked untimed-call interpolation by hand
- Mistake: Message 53: the DP at first found no full-mask state at all, because the seed's return time was used as a strict bound. After the fix it simply re-confirmed the seed time, and the agent did not check whether pruning was hiding a better tour.
- Mistake: The final answer is not optimal or not valid, and the conversation does not show which
