Same request.
Different prediction.
A model returns a plausible number. Is that enough evidence? Try this small Python boundary bug, then use the teaching prompts with a colleague or class.
What changes when the keys move?
The request always means 4 km with a traffic index of 0.5. The intended formula is 3 + 2 × distance + 10 × traffic.
{"distance_km": 4, "traffic_index": 0.5}
def predict(payload):
distance, traffic = payload.values()
return 3 + 2 * distance + 10 * traffic
Predict the result before pressing the buttons.
Bind values to their meaning.
Python dictionaries preserve insertion order. That does not make insertion order a sound field contract.
def predict(payload):
distance = payload["distance_km"]
traffic = payload["traffic_index"]
return 3 + 2 * distance + 10 * traffic
This small repair addresses ordering for these valid fixture inputs. A real boundary also needs an explicit contract for missing fields, extra fields, types, non-finite values and ranges.
The useful question comes after the answer.
Reveal the explanation
The intended result is 16 minutes. Reversing the request makes the flawed function calculate 44 minutes: it binds 0.5 to distance and 4 to traffic. The named-field version returns 16 in either order.
The synthetic formula is a demonstration, not a trained taxi model or evidence of predictive accuracy.
Facilitator prompt: can two matching results still be wrong?
Ask one learner to defend this claim: “Both key orders now return the same result, so the prediction is correct.” Ask a partner to construct a counterexample.
A constant function returning zero is order-invariant too. Combine an invariance check with a known-answer test: for this fixture, both orders must return 16. Then ask what those two tests still do not establish.
Use a five-minute teaching route
- One minute: predict the result silently.
- One minute: reverse the fields and explain the discrepancy.
- One minute: inspect the named-field repair.
- Two minutes: design a test that rejects a constant answer, and state one remaining unknown.
These are suggested timings, not measured classroom results. The exercise tests reasoning about a narrow behavior, not professional competence or production readiness.
Copy the claim–evidence worksheet
Claim: Equivalent requests preserve the prediction.
Counterexample: Reverse field insertion order without changing names or values.
Known answer: Both must return 16 for this fixture.
Result: Record the output and version tested.
Limit: This does not establish model accuracy, useful business outcomes or complete input validation.
Want to teach all five failure cases?
ML Validation Workshop is a USD 29 one-time downloadable Python workshop: five repair exercises, 20 behavioral tests, learner workbook, separate instructor plan and answer key and editable text. Suggested 120-minute route. Python 3.10+, no packages or APIs. MIT reuse, including classroom adaptation; no per-student fee.
The purchase delivers offline files, not a hosted interactive course, live instruction, consulting or certification. This edition has not been classroom validated. The free lesson above remains useful without buying.
See the five-case workshop — $29