MCP Academy · Lesson

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

  1. Tool Errors the Model Can See
  2. Protocol Errors vs Tool Failures
  3. Validate Inputs Before Acting
  4. Fail Safely, Never Hang
← Back to MCP Academy