Skip to content
Start free

Late stops or late routes?

An AI says 4 routes ran late. Count at the grain the question asks for and check it a second way.

7 min

Free course. Your Maestro, an AI, .

Before looking at today's table, recall Module 1: when your rerun of an AI's calculation matches the number it reported, what does that match leave unproven? Answer in one sentence before you read on.

Operations asked: "How many routes had at least one late stop yesterday?" The AI answered 4 and shared the code in the exercise below. Its stops table has 9 rows across 5 delivery routes (R1 to R5); each row holds a route_id, a stop number along that route, and whether late is True or False. One row is one delivery stop, while Operations asked about routes.

On this table, three quick counts give three different numbers: the rows left after the filter, the distinct routes in the whole table, and the distinct routes among the filtered rows. Only one answers the question, and a second, independent check should agree with it. If you want to talk through which count matches which question, ask your Maestro.

Try it

Run the AI's code below. Repair the count so it answers the question about routes, then add a check that reaches the same number another way, for example by grouping the stops by route.

Your turn

Run the AI's code. Repair the count so it answers the question, and add an independent check. You're done when your count and your check agree.

When your script runs, check that your repaired count prints 3, your unique list shows ['R1', 'R3', 'R4'], and the grouped any() check marks True for those same 3 routes out of 5. Seeing R1 once in the grouped output confirms why the AI's row count of 4 was one too high: stop 2 and stop 3 on R1 both passed the filter, yet they belong to a single route. If your count and your grouped check disagree, paste your output to your Maestro.

Check yourself: Operations looks at the stops table and asks why the AI reported 4 instead of 3. Which explanation accurately describes what the AI's code did?