CurriculumPython, data & AI · Week 07

Week 07 / Task steps · input validation · narrow actions

Give the helper useful tools.

The idea

A useful helper does a small number of understandable things. Validate what a person asks for, choose an allowed operation, and show the result for review. Do not let free-form model text become an unchecked action.

Validate before looking up

def lookup_score(team, games):
    if not isinstance(team, str) or not team.strip():
        return {"error": "Enter a team name"}
    matches = [g for g in games if team.lower() in
               (g["home_team"].lower(), g["away_team"].lower())]
    return {"matches": matches}

Build it

Work through these steps in your own project. Check them off as you go; your checklist stays in this browser.

What can the helper do, what is outside its scope, and where does a person review?

Notes save in this browser.