Always free. For everyone.
Course outline
Module 02 of 20 · Workflow foundations

Work with records and decisions

Use small Python functions to clean inputs and route work. This module has 3 lessons and takes about 1h 50m. Each lesson has a practice exercise that runs real Python in your browser and a short quiz.

Start module 02 in the Learning Lab
LESSON 1 OF 3

Clean a text field

25 minAI automation
WHAT YOU WILL DO

Return trimmed lowercase text for a string and an empty string for other input types.

A record groups facts about one item. A dictionary can hold an id, topic, and message. Cleaning should remove accidental whitespace while preserving what the person meant.

The str.strip method removes surrounding whitespace. lower normalises a category for comparison. Use isinstance to check a type before calling string methods.

Do not silently turn missing values into invented facts. An invalid topic becomes an empty string in this exercise.

See it in action

example.pyPython 3
def solve(value):
    if not isinstance(value, str):
        return ""
    return value.strip().lower()
print(solve("  Repairs  "))
Keep this in mind

Do not silently turn missing values into invented facts. An invalid topic becomes an empty string in this exercise.

LESSON 2 OF 3

Build a new record

25 minAI automation
WHAT YOU WILL DO

Return a new dictionary with only id and trimmed message. Use None for a missing id and empty text for a missing or non-string message.

Workflow steps often need only a few fields. Keep the original record for diagnosis and return a new record for the next step. This avoids changing data that another step still uses.

Read a missing field with dict.get. A new dictionary lets you copy the id and cleaned message while leaving unused fields behind. This exercise accepts dictionary records only.

A transformation should have a clear contract: which fields it accepts, which fields it produces, and how it treats missing data.

See it in action

example.pyPython 3
def solve(record):
    text = record.get("message", "")
    return {"id": record.get("id"), "message": text.strip() if isinstance(text, str) else ""}
print(solve({"id": "r1", "message": " Hello ", "private_note": "omit"}))
Keep this in mind

A transformation should have a clear contract: which fields it accepts, which fields it produces, and how it treats missing data.

LESSON 3 OF 3

Practical: Route a small request queue

60 minAI automation
WHAT YOU WILL DO

For records with an id, return (id, queue) tuples in input order. Map repair to service, training to learning, and everything else to review.

A route decides where an item goes next. Our fictional workshop accepts repair and training enquiries. Missing topics go to review rather than disappearing.

Loop through the list in order. Use an exact category mapping for known topics and a default review queue for anything else. Keep each id with its destination.

Routing is not completion. A record assigned to a queue still needs someone or another step to handle it.

GUIDED PRACTICAL · 60 MIN

Your experiment plan

Use the browser editor or the notebook. All records and AI responses are fictional. No network calls, credentials, or real messages are used.

  1. Draw the two known routes and one fallback route.
  2. Run the example and predict its result before changing it.
  3. Complete the function in Practice and run the checks. Add your own normal, empty, and failure cases.
  4. Add a new category and observe the fallback before changing the mapping.
  5. Save the notebook with your observations and explain one limitation of the simulation.

What to hand in

  • A routing function and a table showing every input destination.
  • A test table with inputs, expected outputs, actual outputs, and one revision.
Reflect on your results

Who owns the review queue?

The automatic exercise checks the core code behaviour. Review observations and written deliverables yourself or with a mentor.

See it in action

example.pyPython 3
def solve(records):
    routes = {"repair": "service", "training": "learning"}
    return [(row["id"], routes.get(row.get("topic"), "review")) for row in records]
print(solve([{"id":"r1","topic":"repair"},{"id":"r2","topic":"other"}]))
Keep this in mind

Routing is not completion. A record assigned to a queue still needs someone or another step to handle it.

ABOUT THE LEARNING LAB

Free, open and run by a nonprofit.

This page is part of AI Automation, a free course of 20 modules and 60 lessons in the engineering.fit( ) Learning Lab. The Learning Lab is built and run by engineering.fit( ), a nonprofit founded by Abdullateef Opeyemi Bakare that helps African engineering students gain research experience. You do not need an account or pay a fee to learn.

Course outline · Project lab · Visit engineering-fit.org