← Building with AI

Project part 3: testing the bot

Write test cases and an eval runner for your study buddy.

Start this lesson

A project isn't finished until you can show it works. Write test cases that cover each path through the bot: a definition, a quiz, a term that isn't in the notes, a greeting, and private details. Then run them all and report the score. When you later swap in a real model or change the prompt, these tests tell you straight away if something broke.

CASES = [
    ("What is photosynthesis?", ["sunlight"]),
    ("Hello!", ["define"]),
]
for question, must in CASES:
    reply = study_bot(question)
    ok = all(m.lower() in reply.lower() for m in must)
    print("PASS" if ok else "FAIL", question)

Each case is a (question, words-that-must-appear) pair. The same eval idea from the testing unit.

Good test sets cover normal use, edge cases (unknown terms, empty input) and safety (personal data must not appear).

Well done! You now know the core pattern of most AI apps: prompts and messages, structured output, tools, retrieval, testing and safety, all ordinary Python around a model call. To go further, run these programs with a real SDK on your own computer, and read your provider's docs.