Validate Inputs Before Acting
Reject bad arguments with clear messages.
Trust Nothing the Model Sends
The arguments your tool receives come from an AI, which can guess. Validate every input before you touch a file, a database, or an API.
Check First, Act Second
Run your checks at the very top of the function. Confirm the input is sane before doing any real or irreversible work.
@mcp.tool()
def set_age(age: int) -> str:
if age < 0 or age > 130:
raise ValueError("age out of range")All lessons in this course
- Tool Errors the Model Can See
- Protocol Errors vs Tool Failures
- Validate Inputs Before Acting
- Fail Safely, Never Hang