---
title: "Gemma 4 31B 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 0%, code mode 0%; rank 38 of 44."
canonical: https://pydantic.dev/models/list/gemma-4-31b-it/sql_data_analysis/
---

# Gemma 4 31B 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 0%, code mode 0%; rank 38 of 44.
>
> Markdown copy of https://pydantic.dev/models/list/gemma-4-31b-it/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/gemma-4-31b-it/pydantic_ai.md

| Mode         | Score | Tasks passed | Cost  | Requests | Tool calls | Time      |
| ------------ | ----- | ------------ | ----- | -------- | ---------- | --------- |
| Tool calling | 0%    | 0 of 10      | $0.17 | 161      | 161        | 6.2 min   |
| Code mode    | 0%    | 0 of 10      | $0.48 | 158      | 164        | 125.1 min |

Each task was run once per mode.

## Review

Written by an LLM from the runs' transcripts.

#### Overall

Gemma-4-31B failed all 20 cases (10 with tool calling, 10 in code mode). It wrote no SVG in any case. Most answers are empty or made up:

- **Empty placeholders, 12:** no legs, with times copied from the question (for example `departure = arrival = 29400`) or `arrival: 0`.
- **Made-up legs, 6:** run, platform and time ids that do not fit together.
- **Crash, 1:** code-mode `departure_profile` hit the retry limit.
- **Empty list, 1:** tool-calling `departure_profile` returned `journeys: []`.

#### Where it does well

- It usually finds the station platforms with a correct `places.txt` query.
- It converts clock times to seconds correctly (07:40 → 27600, 17:05 → 61500).
- In a few runs it filtered services by weekday bits correctly (`days & 16` for Friday, `days & 8` for Thursday).
- Code-mode `walking_change` correctly found that no direct run exists.

#### Mistakes it makes

- **Looping instead of working (tool calling):** it re-read `/data/DATA.md` dozens of times. `after_midnight` spent about 15 of 31 requests on it. `saturday_direct` and `meeting_point` ran no timetable queries at all before giving placeholder answers.
- **Giving up when the first query fails:** `departure_profile` and `one_vehicle` only looked for direct runs. When those came back empty it stopped, instead of searching with changes or walks.
- **Logic bugs it never found:** `one_vehicle` (tools) filtered `access = 'Y'` on a two-letter field, so all 8 or so joins were empty. Code-mode `one_change` and `meeting_point` reran searches that returned `inf` without debugging them.
- **Making up answers:** in `after_midnight` it combined `R1e2f6180`'s departure with `Red17208f`'s arrival. In `walking_change` it took 71220 from a different run's row. `saturday_direct` (code) submitted a leg after its own search printed `Best arrival: inf`. Code-mode `after_midnight` and `arrive_by` used ids that do not exist (`R//8`, `P1`, `P2`).
- **Ignoring the question's rules:** `arrive_by` arrives at 73800, after the 64800 deadline. Neither mode used service-day 2026-338 runs for `after_midnight`.

#### Tool calling compared with code mode

Both modes scored 0/10. Code mode cost more (about $0.48 against $0.17 in total) and failed differently:

- **Made-up GTFS files:** in 4 runs it assumed `stops.csv` and `stop_times.csv`. Those `CREATE TABLE` calls failed silently, so `timed_tour` looped about 10 times on `Table with name stops does not exist`.
- **Syntax and type errors:** it often wrote broken string quoting, and `departure_profile` ended after 8 type-check retries.
- **Real search attempts:** code mode is the only mode where it actually wrote Python route searches, but none of them returned a usable journey.

Tool-calling runs were cheaper but mostly stalled on reading the docs or on unfiltered `calls.txt` dumps.

## Runs

### one_vehicle

**Tool calling: failed.** Loaded tables and ran many direct-run joins, all of which came back empty because of a filter bug. It answered no legs at 29400. ($0.021, 26 requests, 73 s)
- Right: Loaded all tables in one `CREATE TABLE` batch
- Right: Found the correct Wednesday services (`days & 4`, 2026-336)
- Mistake: Filtered on `c1.access = 'Y'` and `c2.access = 'Y'`, but `access` holds two letters (`YY`), so every query returned nothing. It needed `LIKE 'Y%'` and `LIKE '_Y'`
- Mistake: Ran the same failing join about 8 times without finding the cause
- Mistake: Ignored walks to other platforms within 400 m
- Mistake: Gave an empty answer and no SVG

**Code mode: failed.** Looked up platforms and searched for runs serving both stations, which came back empty (`Direct base runs: rows []`). It submitted no legs at 29400. ($0.022, 15 requests, 32.5 min)
- Right: Correctly identified Wednesday 2026-336 and the 29400 start
- Right: Found platforms and the lines that call there
- Mistake: Its direct-run query returned nothing, and it did not consider walking to platforms within 400 m or check its filters
- Mistake: Gave an empty answer and no SVG

### saturday_direct

**Tool calling: failed.** Spent 8 requests reading DATA.md in pieces and never ran SQL on the timetable. It answered no legs, with departure and arrival both 33150. ($0.0024, 8 requests, 7 s)
- Mistake: Ran no queries at all
- Mistake: Answered 33150, which is earlier than the 09:15 start (33300) and has no legs, so the time is invented
- Mistake: Wrote no SVG

**Code mode: failed.** Wrote a search that printed `Best arrival: inf` twice, then submitted run `Ra7402f8f` from `P7fa04a55` at 34320 to `P1093f876` at 35460 without checking it. ($0.038, 16 requests, 15.3 min)
- Right: Recovered from a wrong `read_csv(path, ';')` call and loaded the data
- Right: Found that `Ra7402f8f` departs `P7fa04a55` at 34320
- Mistake: Its own search found no journey, yet it submitted one. The alighting platform and the 35460 arrival never came from any tool output
- Mistake: Wrote no SVG

### one_change

**Tool calling: failed.** Looked up platforms and dumped calls at those platforms with no service or time filter, then returned no legs with a made-up departure 27600 and arrival 31800. ($0.0035, 7 requests, 13 s)
- Right: Correctly converted 07:40 to 27600
- Right: Found the platforms of both stations
- Mistake: Never linked boarding and alighting calls on the same run, and never filtered by service day
- Mistake: Answered with arrival 31800 and an empty `legs` list, which matches no journey in the data
- Mistake: Wrote no SVG

**Code mode: failed.** Spent 24 requests on Python searches that always returned `[None, inf]`, then submitted no legs at 27600. ($0.093, 24 requests, 15.8 min)
- Right: Read DATA.md and parsed the `.txt` files itself
- Mistake: Its search never found any journey, and it reran the same code instead of finding the bug
- Mistake: Answered no legs with arrival 27600, the start time
- Mistake: Wrote no SVG. Its 24 requests cost $0.09

### walking_change

**Tool calling: failed.** Found the Friday services and the calls at the platforms of both stations, then made up a direct leg: `R07d1bb9e` boarding at 70560 and alighting at 71220. ($0.025, 20 requests, 48 s)
- Right: Filtered services correctly with Friday `days & 16` and day 2026-338
- Right: Found the platforms of both stations
- Mistake: Used 71220 as the alighting time, but in its own query result 71220 belongs to `R361a39d1` at the Chemnitzer Straße platform `Pff25da30`, not to `R07d1bb9e` at Marienberger Straße. Code mode later showed there is no direct run between these stations
- Mistake: Chose a 19:36 departure for a 17:05 start, so the answer is not the earliest
- Mistake: Ignored the walking change the case is built around
- Mistake: Wrote no SVG

**Code mode: failed.** Over 28 requests it built several searches and confirmed there is no direct run (`Direct runs across all days: []`). Its last search printed nothing, and it submitted no legs at 61500. ($0.17, 28 requests, 18.1 min)
- Right: Computed the 17:05 start correctly as 61500
- Right: Correctly found that no run serves both stations directly, which shows a change is needed
- Mistake: Never got a search with a walking change to work
- Mistake: Gave an empty answer and no SVG. At $0.17 it was the most expensive case

### after_midnight

**Tool calling: failed.** Read `/data/DATA.md` about 15 times and ran a few `run_sql` queries with no service-day filter. It then answered with a single leg on `R1e2f6180`, using an arrival time taken from a different run. ($0.052, 31 requests, 62 s)
- Right: Found the platforms of both stations with a correct `places.txt` query
- Right: Filtered the boarding letter with `access LIKE 'Y%'`
- Mistake: Wasted about 15 of its 31 requests calling `read_text` on `/data/DATA.md` with `start_line: 1` over and over
- Mistake: Never looked at service-day 2026-338 runs whose times are past 86,400, which is the whole point of the case. It also never filtered by service
- Mistake: At k=35–46, queries showed `R1e2f6180` makes no call at Wasaplatz (empty results). It still answered `R1e2f6180` board 13140, alight `P4605535d` at 13740, and 13740 is `Red17208f`'s arrival. The leg is made up
- Mistake: Wrote no SVG

**Code mode: failed.** Printed DATA.md once, then immediately submitted a made-up leg on run `R//8` that departs at 3660 (before the 01:10 start) and alights at `P531e34da`, which is the station id with a P in front. ($0.0008, 2 requests, 4 s)
- Right: Read DATA.md in its first call
- Mistake: Ran no queries at all before answering
- Mistake: Made up the run id `R//8` and the platform `P536829e4`. It also gave alighting place `P531e34da`, a station id with S changed to P
- Mistake: Departure 3660 is before the 4200 start
- Mistake: Wrote no SVG

### arrive_by

**Tool calling: failed.** Re-read DATA.md 7 times, ran one platform query and one service-filtered call query, then answered `R6b6c9e94` departing 71400 and arriving 73800, which misses the 18:00 (64800) deadline. ($0.0066, 12 requests, 20 s)
- Right: Filtered services correctly with Thursday bit `days & 8` and day `2026-344`
- Mistake: Its answer arrives at 73800 (20:30), after the 'by 18:00' limit. It never checked a departure window of 59400–64800
- Mistake: Never built a journey from the call list. It picked one run without checking that it serves both stations in order
- Mistake: Wrote no SVG

**Code mode: failed.** Assumed GTFS files (`stops.csv`, `stop_times.csv`) that do not exist. After listing `/data` and reading DATA.md, it submitted a placeholder leg `R2f1a2b3c` from `P1` to `P2`. ($0.024, 14 requests, 66 s)
- Right: Eventually listed `/data` and read `places.txt` columns
- Mistake: Made up GTFS table names, and its `CREATE TABLE` calls failed silently (empty `{}` results) 4 times
- Mistake: Never queried the real `calls.txt` and `runs.txt` once it knew the real file names
- Mistake: Submitted invented ids `R2f1a2b3c`, `P1` and `P2`
- Mistake: Wrote no SVG

### departure_profile

**Tool calling: failed.** Loaded tables and tried direct-run joins between the two stations. Some failed because `at` is a reserved word, and the rest came back empty. It returned `journeys: []`. ($0.044, 28 requests, 1.8 min)
- Right: Created DuckDB tables once with `CREATE TABLE ... AS SELECT * FROM read_csv(...)`
- Right: Found the platform ids of both stations
- Mistake: Only ever looked for direct runs. When they came back empty it should have searched with a change instead of giving up
- Mistake: Got a `ParserException` from an unquoted `at` column in a CTE, then repeated the same query
- Mistake: Ran identical queries again (k=29/31, 49/51/53) and called `SELECT 1` for no reason
- Mistake: Returned an empty list and no SVG

**Code mode: error.** Read DATA.md and found platforms, then wrote a large search script. It failed the sandbox type check (`not-subscriptable` on an `int`) again and again until the run stopped after 8 retries. ($0.055, 14 requests, 21.0 min)
- Right: Read DATA.md and queried the platforms of both stations
- Mistake: Resubmitted nearly the same code after each `Cannot subscript object of type int` type error instead of fixing line ~114–121
- Mistake: The run ended with `UnexpectedModelBehavior: Tool 'run_code' exceeded max retries count of 8`

### meeting_point

**Tool calling: failed.** Re-read DATA.md 5 times and never queried the timetable. It answered the first friend's start station `S2a8c1b68` at 09:00 with empty journeys. ($0.0020, 7 requests, 8 s)
- Mistake: Ran no route search at all. It only read the docs
- Mistake: Gave a placeholder: the second friend cannot be at Waldschlößchen at 32400 with no legs
- Mistake: Wrote no SVG

**Code mode: failed.** Started with made-up GTFS tables, then wrote a Python search over the real files. The search reached nothing (`[null, 'inf', {}, {'Sc29ca723': 32400}, ...]`), and it submitted a placeholder meeting at the first friend's start station. ($0.071, 23 requests, 9.9 min)
- Right: Eventually switched to reading the real `.txt` files
- Mistake: Assumed `stops.csv` and `stop_times.csv` at the start
- Mistake: Its search reached only the start station. It ran the same failing code twice without debugging it
- Mistake: Answered `S2a8c1b68` at 32400 with empty legs, which is impossible for the second friend
- Mistake: Wrote no SVG. Its 23 requests cost $0.07

### timed_tour

**Tool calling: failed.** Ran `SELECT * FROM calls.txt` twice with no filter, read DATA.md, then returned an empty tour with arrival 0. ($0.0047, 7 requests, 10 s)
- Mistake: Its only data queries were unfiltered dumps of `calls.txt`
- Mistake: Never tried to plan the visits
- Mistake: Gave an empty answer and no SVG

**Code mode: failed.** Tried more than 10 times to create made-up GTFS tables (`stops.csv`, `transfers.csv`). It hit `Table with name stops does not exist` over and over, then submitted an empty tour. ($0.0081, 17 requests, 10.9 min)
- Mistake: Never read DATA.md or listed `/data`, so it never learned the real file names
- Mistake: Repeated the same failing `CREATE TABLE` script about 10 times
- Mistake: Gave an empty answer and no SVG

### tour

**Tool calling: failed.** Over 15 requests it never built any search, and returned an empty tour with arrival 0. ($0.0078, 15 requests, 17 s)
- Mistake: Gave up without trying the multi-stop route
- Mistake: Gave an empty answer and no SVG

**Code mode: failed.** Read DATA.md, listed the platforms of the 6 stations, then submitted an empty tour after 5 requests. ($0.0032, 5 requests, 31 s)
- Right: Read DATA.md and fetched the station platforms
- Mistake: Gave up right after getting platforms, without searching
- Mistake: Gave an empty answer and no SVG
