Lesson 3 of 4
Check a Tool Reply Against the Shape You Expect
Estimated time: 10 minutes
Checking a tool reply against the shape you built for
A tool call can answer with success while its reply no longer carries the field the caller reads. The writer changed the shape, the call still answers, and the run reads a missing value as empty and moves on. The problem then appears far from the tool, as a wrong decision.
Name the fields you depend on
Write down the fields each call reads and the type each one should have. A caller that reads three fields has a shape of three fields, whether or not anyone wrote it down.
Check before you read
Test the reply against that list before using it. A missing field should raise at the call, where the tool name is still in hand, rather than fall back to an empty value.
def check(reply, expected):
missing = [f for f in expected if f not in reply]
return {"ok": not missing, "missing": missing}
Treat a changed shape as a new version
A field that moves or is renamed is a new version of the tool, not an accident to work around at the call site. Matching the old name onto the new shape keeps two versions alive with no record of the change, and hides the day the old name stops working.
Record the shape you saw
Keep the observed shape beside the call so the next reader can see what changed and when. A check with no record only says the call fails now, not what it wanted before.