Validate a tool argument before execution
Check the accepted domain before running a tool.
Check the accepted domain before running a tool. Here a square function accepts a non-negative integer. Python treats bool as a subclass of int, so an exact type check excludes True.
Work through the example
The input domain is the set of integers x >= 0. Inputs 3, -1 and True yield valid, invalid and invalid.
Run the example as a separate Python file. The inputs are synthetic so you can change them and see exactly which assumption affects the result.
Run the example
def valid(x):
return type(x) is int and x >= 0
print([valid(x) for x in [3, -1, True]])
Expected output
[True, False, False]
Reference: https://docs.python.org/3/library/functions.html#type
The team guide · My original notes on testing coding agents · Working with Lightbulb Partners