Courses3 levels
Level 1 · Foundations11 courses
Level 2 · Core5 courses
Level 3 · Advanced5 courses
Labs8 topics
Library Practice exams AI Range Pricing Start free

Lesson 01 · 40 minutes

Say who is accountable for an AI system, and prove it with a check

After this lesson you can
  • Write a RACI table that gives every AI system one accountable owner per activity
  • Check the table with a script that finds missing and doubled owners
  • Write an AI use policy with required sections and check it with a script
Lab files of this lesson (10)

The lab folder as it stands after this lesson. Unzip it in ~/krlab.

More

The zip holds every file that the course has printed up to here. To start this lesson with the files of the earlier lessons only, take the zip of the lesson before. Type the code yourself first: you learn more.

Scenario

Harbour Credit is an invented lender with two AI systems. LoanScore ranks loan applications. HelpBot answers customer questions. An auditor asks one plain question: "Who answers for LoanScore?" Three people in the room each say that somebody else does. Your lead gives you the task: write down who does what for each system, make a script that fails when the answer is unclear, and write a short policy that the script can check too.

The idea

Governance means that a decision has a person behind it. For an AI system four jobs matter, and the course uses four role names for them.

RoleDoesActivity in the table
OwnerAnswers for the system and its resultsrun
BuilderMakes or buys the systembuild
ReviewerTests it and reports what they findreview
ApproverDecides that it may go liveapprove

A RACI table says, for each activity, who is Responsible (does the work), Accountable (answers for it and has the last word), Consulted (is asked first) and Informed (is told after). The one rule that matters: each activity has exactly one A. With zero, nobody answers. With two, each one thinks the other answers. A second rule protects the decision: the approver must not be a person who builds the same system.

Who answers for LoanScore
Build and reviewDecide and runAuditBuilderReviewerOwnerApproverAuditor12345Build and reviewDecide and runAuditBuilderReviewerOwnerApproverAuditor12345
  1. Builder → Reviewer: here is the system
  2. Reviewer → Approver: here is the test evidence
  3. Approver → Owner: approved, or not
  4. Owner → Builder: fix what the reviewer found
  5. Auditor → Owner: who answers for LoanScore?

A policy is a short document that says what is allowed and who decides. A policy that a script can check is more useful than one that nobody reads: the script finds a missing section or an old review date. In this lesson a policy is a Markdown file (a text file with simple marks: # makes a title and ### makes a section heading) with three header lines and five sections. The course uses ### for sections, so that the files stay simple to print inside lessons.

Worked example

Work in ~/krlab/ai-governance with the environment on (source .venv/bin/activate).

1. Save the helper that ends every checker

Every checker of this course prints its problems, then a count, and sets an exit code: a number that a program gives back when it ends. 0 means success and 1 means failure. A script, or a later lesson, reads that number. Save govlib.py.

govlib.py

"""govlib.py: the end of every checker in this course. Print the problems, then set the exit code."""
import sys


def finish(problems):
    for problem in problems:
        print("PROBLEM", problem)
    print(f"problems: {len(problems)}")
    sys.exit(1 if problems else 0)

2. Write the RACI table

A CSV file (comma-separated values) is a text file with one row on each line and the values split by commas. Save raci.csv. Each system has four activities. Aino owns both systems, Bram builds, Chidi tests, Dana is accountable for the review, Elif approves, and Femi runs them day to day. One row says who has which part in which activity.

One row of raci.csv
LoanScoresystemreviewactivityDanapersonAraci: accountable, has the last wordLoanScoresystemreviewactivityDanapersonAraci: accountable, has the last word

raci.csv

system,activity,person,raci
LoanScore,build,Bram,R
LoanScore,build,Aino,A
LoanScore,review,Chidi,R
LoanScore,review,Dana,A
LoanScore,approve,Elif,A
LoanScore,run,Femi,R
LoanScore,run,Aino,A
HelpBot,build,Bram,R
HelpBot,build,Aino,A
HelpBot,review,Chidi,R
HelpBot,review,Dana,A
HelpBot,approve,Elif,A
HelpBot,run,Femi,R
HelpBot,run,Aino,A

3. Write the checker

csv.DictReader reads each row as a dictionary with the column names as keys. defaultdict(list) is a dictionary that makes an empty list for a new key. A set ({...}) holds each value once, and & gives the values that two sets share. sys.argv[1] is the first word after the script name on the command line. {s for s, _ in cells} builds a set of the first item of each pair, and _ means "ignore the second item". [p for p, r in people if r == "A"] is a short loop that keeps the p of each pair whose r is A.

raci_check.py

"""raci_check.py: check a RACI table. Usage: python3 raci_check.py raci.csv"""
import csv
import sys
from collections import defaultdict

from govlib import finish

ACTIVITIES = ["build", "review", "approve", "run"]


def problems(path):
    cells = defaultdict(list)                      # (system, activity) -> [(person, raci), ...]
    with open(path, newline="") as f:
        for row in csv.DictReader(f):
            cells[(row["system"], row["activity"])].append((row["person"], row["raci"]))
    found = []
    for system in sorted({s for s, _ in cells}):
        for activity in ACTIVITIES:
            people = cells.get((system, activity), [])
            accountable = [p for p, r in people if r == "A"]
            if len(accountable) != 1:
                found.append(f"{system} {activity}: {len(accountable)} accountable, need exactly 1")
            if activity != "approve" and not any(r == "R" for _, r in people):
                found.append(f"{system} {activity}: nobody is responsible")
        builders = {p for p, r in cells.get((system, "build"), []) if r in ("A", "R")}
        approvers = {p for p, r in cells.get((system, "approve"), []) if r == "A"}
        for person in sorted(builders & approvers):
            found.append(f"{system}: {person} builds and approves")
    return found


if __name__ == "__main__":
    finish(problems(sys.argv[1]))

$? is the shell's name for the exit code of the last command. echo prints text, so this second line shows the number.

python raci_check.py raci.csv
echo "exit code $?"
problems: 0
exit code 0

4. Break the table on purpose

A checker that has never failed is not proven. sed 's/old/new/' file prints a file with the first old of each line changed to new. grep -v text file prints the lines that do not hold text. > writes the output of a command into a file instead of the screen. Make two broken copies.

sed 's/HelpBot,approve,Elif,A/HelpBot,approve,Bram,A/' raci.csv > broken1.csv
grep -v "LoanScore,run,Aino" raci.csv > broken2.csv
python raci_check.py broken1.csv
python raci_check.py broken2.csv
PROBLEM HelpBot: Bram builds and approves
problems: 1
PROBLEM LoanScore run: 0 accountable, need exactly 1
problems: 1

The first copy lets Bram build and approve HelpBot. The second copy leaves LoanScore with nobody accountable for run. The checker found both.

5. Write the policy and its checker

text.split("### ") cuts a text at every ### and returns a list of the pieces. head, *parts = pieces puts the first piece in head and all the others in parts. line.partition(":") cuts a line at the first colon into three values: before, the colon, and after. date.fromisoformat turns a text such as 2027-05-21 into a date, and raises ValueError when the text is not a real date. Save the policy first.

policy.md

# AI use policy of Harbour Credit

Owner: Aino
Version: 1.0
Next review: 2027-05-21

### Purpose

This policy says who may use AI systems at Harbour Credit, for which work, and who answers for the result.

### Scope

It covers every AI system that staff build, buy or use for company work, including free tools used in a browser.

### Roles

Every system has one owner, who answers for it. A builder makes it. A reviewer tests it. An approver decides about launch and never builds the same system.

### Rules

Each system is listed in the inventory before first use. Each system has a risk register entry. A system that decides about people is tested for fairness and keeps a reason for each decision. Personal data goes only to a provider that passed the vendor check.

### Review

The owner of this policy reads it every six months and records the new version number and the date of the next review.

Then the checker. It needs the three header lines with a real review date, the five sections, and at least 12 words in each section, because a heading with one line under it is not a policy.

policy_check.py

"""policy_check.py: check that a policy file has the header lines and the required sections."""
import sys
from datetime import date

from govlib import finish

REQUIRED = ["Purpose", "Scope", "Roles", "Rules", "Review"]
MIN_WORDS = 12


def problems(path):
    text = open(path, encoding="utf-8").read()
    head, *parts = text.split("### ")              # the header lines, then one piece for each section
    header = {}
    for line in head.splitlines():
        label, _, value = line.partition(":")
        header[label.strip()] = value.strip()
    sections = {}
    for part in parts:
        name, _, body = part.partition("\n")
        sections[name.strip()] = body
    found = []
    for label in ("Owner", "Version", "Next review"):
        if not header.get(label):
            found.append(f"header line missing: {label}")
    if header.get("Next review"):
        try:
            date.fromisoformat(header["Next review"])
        except ValueError:
            found.append(f"Next review is not a date like 2027-05-21: {header['Next review']}")
    for name in REQUIRED:
        if name not in sections:
            found.append(f"section missing: {name}")
        elif len(sections[name].split()) < MIN_WORDS:
            found.append(f"section too short (under {MIN_WORDS} words): {name}")
    return found


if __name__ == "__main__":
    finish(problems(sys.argv[1]))
python policy_check.py policy.md
problems: 0

Your turn

The team of Tern Logistics (invented) sent you a table and a policy draft. Save both files, then use your two checkers. There are no steps: find out what is wrong and fix it.

raci-team.csv

system,activity,person,raci
DeskSum,build,Ola,R
DeskSum,build,Pia,A
DeskSum,build,Quin,A
DeskSum,review,Rhea,R
DeskSum,review,Sol,A
DeskSum,approve,Tamsin,A
DeskSum,run,Ola,R
DeskSum,run,Pia,A
CvSort,build,Uma,R
CvSort,build,Vik,A
CvSort,review,Uma,R
CvSort,approve,Vik,A
CvSort,run,Wen,R
CvSort,run,Vik,A

policy-draft.md

# AI use policy of Tern Logistics

Owner: Ravi
Next review: 2027-02-30

### Purpose

This policy sets the rules for AI tools at Tern Logistics, so that staff know what is allowed and who decides.

### Scope

It covers AI tools that staff buy, build or use, on company laptops and on private phones used for work.

### Rules

List every tool. Ask the owner.

### Roles

Each tool has an owner. The owner answers for the tool and for the data that goes into it.

Fix both files until both checkers exit with code 0. For the questions, use the files as they are printed above, before your fixes.

Last, write down in one sentence why the checker for approve asks for an A but not for an R.

Check yourself

An activity has two accountable people, Pia and Quin. Why does the checker call this a problem?

When two people are accountable, each can assume that the other one answers. In a failure, nobody acts first. One A means one name to ask, one name to inform and one name to blame for a gap. If two people share the work, make both of them R and choose one A.

Why must the approver not be a person who builds the system?

The approver decides whether the system is safe enough to launch. A builder who approves their own work has a reason to see no problem. The rule is called separation of duties. In a very small team, ask a person from another team to approve.

The policy checker demands 12 words in each section. What does it prove, and what not?

It proves that the section has some text. It does not prove that the text is true or wise. A script can check form: header lines, sections, dates. A person must check the meaning. Use the script to remove the cheap mistakes before the review.

Why is the exit code of a checker important, and not only its printed text?

Another program reads the exit code. A build job or a pack check (lesson 13) stops when a checker gives 1. A printed sentence is for people, and an exit code is for machines. A checker that always gives 0 protects nothing.

Field notes

  • Use a named person or a named mailbox for an A, never "the team". A team cannot be asked why a decision was taken.
  • Keep the RACI table and the policy in the same repository as the code, and run the checkers in the build. A table in a wiki goes out of date without a sound.
  • Accountable does not mean "to blame". It means that the person decides, has the means to act, and answers to others. Give the A to someone with the authority to stop the system. Prefer an approver who did not review the system either: the checker blocks only a builder, so this rule is yours to keep.
  • The roles here are internal. Laws and standards use their own role words: lesson 6 explains the roles of the EU AI Act (provider and deployer), which are not the same as these four roles.
  • Review the table when people leave. A RACI that names a person who left the company has an owner on paper only.