Write the tool definitions (~15 min)
tool_schemas.py is a warehouse assistant. The three handlers (check_stock, create_transfer, set_reorder_points) and the loop are written, but TOOLS is empty, so the model can't call anything. Two of the tools change state, and the model sometimes sends inputs that don't match a schema, so inputs must be checked before a handler runs.
Part 1. Fill in TOOLS with one definition per handler (name, description, input_schema) that follows this contract:
| Tool | Parameter | Type | Required | Notes |
|---|---|---|---|---|
check_stock | skus | list of strings | yes | e.g. ["SKU-100", "SKU-300"] |
warehouse | string: tokyo, osaka or all | no | defaults to all | |
create_transfer | sku | string | yes | |
quantity | integer | yes | at least 1 | |
from_warehouse | string: tokyo or osaka | yes | ||
to_warehouse | string: tokyo or osaka | yes | ||
note | string | no | ||
set_reorder_points | points | object mapping a SKU to a whole number | yes | e.g. {"SKU-100": 20, "SKU-300": 12} |
No other parameters are allowed. Write descriptions the model can act on.
Part 2. Implement validate_input(tool, tool_input) -> list[str], driven by the tool's input_schema, and call it in the loop before any handler runs. An input with problems is not executed: the model gets an is_error result listing them, so it can fix the call. It must catch:
- a required parameter that's missing,
- a parameter that isn't in the schema,
- a top-level value of the wrong JSON type (
string,integer,number,boolean,array,object; in PythonTrueis anint, buttrueis not a JSON integer), - a value that isn't in the parameter's
enum.
Each problem names the parameter. You don't need to check inside arrays or objects, or minimum; the handlers already reject bad values by raising.
Keep the loop's existing behaviour: an unknown tool or a handler that raises is an is_error result, and max_turns raises RuntimeError. run_agent(prompt, client=None, max_turns=10) -> str and the module-level STOCK / TRANSFERS / REORDER_POINTS must stay.
Be ready to explain why you validate even though the model was given the schema, and what strict: true on a tool definition would change.
Try it: python -m tool_schemas
Check it: pytest tests/test_tool_schemas.py