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 12 · 60 minutes

Show evidence for each responsible-AI principle and add two more risks

After this lesson you can
  • Keep one control, owner and evidence file for each responsible-AI principle
  • Release a count with differential privacy and test that a model gives the same decisions twice
  • Add reputational loss and intellectual property to the risk register, each with a control
Lab files of this lesson (62)

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

The board of Harbour Credit asks a third question: "Where is the proof for each principle of responsible AI?" Your answer: one file with a row for each principle, naming the control, the evidence file and the owner, and a check that fails when a row or a file is missing. Two principles have no evidence yet, so you make it. The board also asks about two risks that the register does not name: damage to the name of the company, and the loss of code and licences.

Recall

Lesson 3: a residual score is lower than the inherent score. What must you have before you believe it?

Evidence: a test result, a log or a report.

Lesson 11: which file does the controls check read to find the owner of a control?

people.csv. An owner must be a person who is in that file.

The idea

Responsible AI is a set of principles for a trustworthy system. Each needs evidence, or it is a slogan. This ten-row list is the course's own. Differential privacy is a technique for the privacy principle, and consistency is a test for reliability. A row that does not apply to a system says n/a in the evidence column and gives a reason (step 5). The five OECD principles of lesson 8 map onto the rows: inclusive growth to inclusiveness, human rights (fairness and privacy) to the fairness and privacy rows, transparency and explainability to their two rows, robustness, security and safety to reliability and privacy and security, and accountability to its row.

PrincipleIn plain wordsEvidence
FairnessNo group gets worse outcomes without a reasonFairness report (lesson 4)
Reliability and safetyIt works as intended, fails safely, and a person can step inOversight rule (lesson 7)
TransparencyPeople know that AI is used, what for, and its limitsModel card (lesson 10)
Privacy and securityPersonal data is protected and the system is defendedImpact assessment (lesson 9)
Differential privacyReleased statistics hide any one person's recordNoisy release (step 1)
ExplainabilityA reason can be given for each decisionExplanation records (lesson 5)
InclusivenessIt serves the people who meet it, and the gaps are written downContext map (lesson 7)
AccountabilityA named person answersRACI table (lesson 1)
ConsistencyThe same input gives the same decisionRepeat run (step 2)
Awareness trainingStaff know the rules and the dangersPeople file (lesson 11)
One row of controls.csv
differential privacyitem: a principle or a risk idNoise on released countscontroldp_release.txtevidence: a file that must existChidiowner: a person in people.csvemptyreason: a sentence, if evidence is n/adifferential privacyitem: a principle or a risk idNoise on released countscontroldp_release.txtevidence: a file that must existChidiowner: a person in people.csvemptyreason: a sentence, if evidence is n/a

Worked example

Work in ~/krlab/ai-governance with the environment on. If you joined with kr-lab.sh, run python makedata.py, python explain.py and python mitigate.py > fairness_report.txt first. This lesson uses register.csv of lesson 3 and people.csv of lesson 11.

1. Show differential privacy

A result is differentially private when adding or removing any one person's record changes the chance of each result by at most a factor, and epsilon sets that factor: e to the power epsilon, about 2.7 at epsilon 1. A small epsilon means strong privacy and more noise. To release a count, add noise from a Laplace distribution (a pointed curve) of scale 1 / epsilon: one person changes a count by at most 1, so that is enough. math.copysign(1, u) gives the sign of u. The privacy budget is the total epsilon that you allow for all releases of the same data. The script prints five draws for each epsilon only to show the spread. A real release is one draw, and it spends part of the budget.

dp_count.py

"""dp_count.py: a demonstration of a count released with differential privacy. Usage: dp_count.py data/loans.csv B"""
import csv
import math
import random
import sys


def noisy_count(true_count, epsilon, rnd):
    """Laplace noise of scale 1/epsilon: one person changes a count by at most 1."""
    u = rnd.random() - 0.5
    return true_count - math.copysign(1, u) * math.log(1 - 2 * abs(u)) / epsilon


if __name__ == "__main__":
    with open(sys.argv[1], newline="") as f:
        true = sum(1 for row in csv.DictReader(f) if row["group"] == sys.argv[2])
    rnd = random.Random(5)   # fixed in the lab, so that you get the numbers of the lesson: never fix it in real use
    print(f"true count of group {sys.argv[2]}: {true}")
    for epsilon in (1.0, 0.1):
        draws = [round(noisy_count(true, epsilon, rnd)) for _ in range(5)]
        print(f"epsilon {epsilon}: {draws}")

tee file prints its input and also writes it to the file. That file is the evidence.

python dp_count.py data/loans.csv B | tee dp_release.txt
true count of group B: 408
epsilon 1.0: [408, 409, 409, 410, 409]
epsilon 0.1: [427, 380, 407, 430, 412]

The noise can be negative. With this seed none of the first five draws at epsilon 1.0 is below the true count. At epsilon 1.0 the count is almost exact and one person is only weakly hidden. At epsilon 0.1 it moves by tens and one person is well hidden. People choose epsilon. Repeated releases with fresh noise let an observer average the noise away, so count every release against the budget.

dp_count.py is a demonstration, not a release tool. Its seed is fixed in the lab so that every reader gets the same numbers, and so that the page can check them. In real use the seed must not be fixed and must stay secret: anybody who knows it can compute the noise and subtract it, and the count is no longer hidden. A real release takes the noise from a cryptographic random source and publishes one draw, never the true count that the demonstration prints next to the draws. So dp_release.txt is evidence of the method, not a release. The row applies to LoanScore because the monthly board report of Harbour Credit publishes the number of applicants of each group, and dp_release.txt shows how that count would be released. A system that publishes no statistic marks the row n/a (step 5).

2. Show consistency

For LoanScore, consistency means that the same inputs give the same decisions. Run the decision script twice and keep the fingerprint of decisions.csv after each run. sha256sum file prints a fingerprint of a file (lesson 10 used the same idea). cut -c1-16 keeps 16 characters, sort -u drops repeated lines, and wc -l counts lines.

python explain.py > /dev/null
sha256sum decisions.csv | cut -c1-16 > consistency.txt
python explain.py > /dev/null
sha256sum decisions.csv | cut -c1-16 >> consistency.txt
cat consistency.txt
sort -u consistency.txt | wc -l
4e38154da8456947
4e38154da8456947
1

One distinct fingerprint means that both runs gave the same decisions. A language model such as the one behind HelpBot can answer differently each time: ask it the same question several times and count the different answers.

3. Add two risks: reputation and intellectual property

Reputational loss is harm to the trust that people have in the organisation. It is an impact more than a cause: the bias of R1 or the leak of R2 becomes one when it reaches the public. Intellectual property (IP) is what the organisation owns or may use under a licence: code, documents, data. AI brings two risks. Outbound: staff paste source code into a tool whose terms may allow training on it. Inbound: a tool returns code with a licence that you cannot meet (R4 of lesson 3). Who owns generated output depends on the law and the contract: ask your legal people. Add one risk for each.

echo 'R7,A wrong or unfair decline becomes public,Applicants get no reason and no correction,4,3,Aino,A reason for each decision and a response plan,4,2' >> register.csv
echo 'R8,Source code is pasted into an unlisted AI tool,Free tools accept any text,4,3,Bram,Listed tools only and a no-training term,4,2' >> register.csv
python register.py report register.csv | grep -E "R7|R8|problems"
R7  12    high      8        medium    Aino   A wrong or unfair decline becomes public
R8  12    high      8        medium    Bram   Source code is pasted into an unlisted AI tool
problems: 0

The evidence for R7 is the response plan of lesson 7. The evidence for R8 is the vendor record of lesson 9, whose data_use line is the no-training term.

4. Write the controls check

controls.csv has one row for each principle, and one for R7 and R8: the control, the evidence file and an owner from the people file. The check needs a row for each principle. Any other row must name a risk of the register. A principle that does not apply to a system, such as differential privacy for a system that releases no statistic, may say n/a instead of a file, and then the reason column must hold a sentence of at least five words. A risk row cannot say n/a. Path(folder) / name joins a folder and a file name, and stat().st_size is the size of a file in bytes.

controls_check.py

"""controls_check.py: one control, one owner and one evidence file for each principle.
A principle that does not apply says n/a in the evidence column and gives a reason.
    python3 controls_check.py controls.csv people.csv register.csv"""
import sys
from pathlib import Path

from govlib import finish
from inventory import load

NOT_APPLICABLE = "n/a"
MIN_WORDS = 5
PRINCIPLES = ["fairness", "reliability and safety", "transparency", "privacy and security", "differential privacy",
              "explainability", "inclusiveness", "accountability", "consistency", "awareness training"]


def problems(controls_path, people_path, register_path, folder="."):
    people = {row["person"] for row in load(people_path)}
    risks = {row["id"] for row in load(register_path)}
    rows = load(controls_path)
    found = [f"{p}: no row in the controls file" for p in PRINCIPLES if p not in {row["item"] for row in rows}]
    for row in rows:
        item = row["item"]
        if item not in PRINCIPLES and item not in risks:
            found.append(f"{item}: neither a principle nor a risk of the register")
        if not row["control"].strip():
            found.append(f"{item}: no control")
        if row["owner"] not in people:
            found.append(f"{item}: owner {row['owner']!r} is not in the people file")
        if row["evidence"] == NOT_APPLICABLE:
            if item not in PRINCIPLES:
                found.append(f"{item}: only a principle can be not applicable")
            elif len(row["reason"].split()) < MIN_WORDS:
                found.append(f"{item}: not applicable, and the reason has fewer than {MIN_WORDS} words")
            continue
        evidence = Path(folder) / row["evidence"]
        if not evidence.is_file() or evidence.stat().st_size == 0:
            found.append(f"{item}: evidence file {row['evidence']} is missing or empty")
    return found


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

controls.csv

item,control,evidence,owner,reason
fairness,Ratio tested before each release,fairness_report.txt,Chidi,
reliability and safety,An officer reads every score,oversight.md,Aino,
transparency,Approved model card,model_card.json,Bram,
privacy and security,Impact assessment,dpia.md,Dana,
differential privacy,Noise on released counts,dp_release.txt,Chidi,
explainability,A record of reasons,explanations.jsonl,Chidi,
inclusiveness,Known limits written down,context.md,Bram,
accountability,One A for each activity,raci.csv,Aino,
consistency,Repeat run gives the same decisions,consistency.txt,Femi,
awareness training,Training each year,people.csv,Hugo,
R7,Reasons and a response plan,response.md,Aino,
R8,Listed tools with a no-training term,vendor.json,Bram,
python controls_check.py controls.csv people.csv register.csv
problems: 0

5. Break the controls on purpose

Make a copy without the consistency row, give the training to an unknown person, and hide the evidence of differential privacy. mv a b moves or renames a file (Linux basics).

grep -v "^consistency" controls.csv | sed 's/,Hugo,$/,Zed,/' > controls2.csv
mv dp_release.txt dp_release.old
python controls_check.py controls2.csv people.csv register.csv
mv dp_release.old dp_release.txt
PROBLEM consistency: no row in the controls file
PROBLEM differential privacy: evidence file dp_release.txt is missing or empty
PROBLEM awareness training: owner 'Zed' is not in the people file
problems: 3

The check proves that each principle has a control, an owner and a file. A person must still open the file.

Now mark differential privacy as not applicable, as a team would for a system that releases no statistic. Try it first with no reason, then with a reason. n/a needs a backslash in the sed text, because / ends the pattern.

sed 's/^differential privacy,.*/differential privacy,Nothing is released,n\/a,Chidi,/' controls.csv > na.csv
python controls_check.py na.csv people.csv register.csv
sed 's/^differential privacy,.*/differential privacy,Nothing is released,n\/a,Chidi,This system publishes no count or other statistic/' controls.csv > na.csv
python controls_check.py na.csv people.csv register.csv
PROBLEM differential privacy: not applicable, and the reason has fewer than 5 words
problems: 1
problems: 0

A bare n/a is a way to skip a principle, so the check wants a reason and an owner who answers for it. The page cannot judge whether the reason is true. The approver reads it.

6. The finished file

The finished file: register.csv

register.csv

id,risk,cause,impact,likelihood,owner,control,res_impact,res_likelihood
R1,Loan approvals are biased against group B,Income acts as a proxy in the training data,4,4,Aino,Fairness test before every release,4,2
R2,Customer data leaks through a chatbot prompt,Staff paste records into free tools,4,3,Dana,Vendor check and a block on unlisted tools,4,2
R3,Accuracy drifts as the customer mix changes,The model is not retrained,3,4,Bram,Monthly accuracy report on fresh outcomes,3,2
R4,Generated code copies licensed code,Engineers accept suggestions unread,3,2,Bram,Licence scan before every merge,3,1
R5,An agent acts without approval,The tool has write access to payments,5,2,Femi,A person approves every money move,5,1
R6,Staff use AI tools that nobody listed,Free tools need no purchase,3,5,Dana,Monthly shadow AI report,3,3
R7,A wrong or unfair decline becomes public,Applicants get no reason and no correction,4,3,Aino,A reason for each decision and a response plan,4,2
R8,Source code is pasted into an unlisted AI tool,Free tools accept any text,4,3,Bram,Listed tools only and a no-training term,4,2

Your turn

Release the count of group A in data/screening.csv with your dp_count.py. Then copy controls.csv, change the owner of R8 to Tamsin (who is not in people.csv) and run the controls check on the copy. There are no steps.

Check yourself

The controls check passes and every evidence file exists. What has it not shown?

That each file proves that its control works. A file can exist and say nothing. A reviewer opens it and recomputes one number from raw data, as the build of lesson 13 does.

A report releases a count of 408 for group B at epsilon 0.1, and the same report is released again each day with fresh noise. What goes wrong?

An observer averages the daily values and the noise cancels. The true count appears. Every release spends budget, so the total epsilon of all releases must stay within the budget that people chose.

Two runs give the same decisions today. Is the model consistent?

Only for those inputs and that code. A repeat run is the weakest test. For a model that scores people, also change an input that must not matter, such as a rounding of income, and count the decisions that flip.

Why is the risk "source code pasted into an unlisted AI tool" a register row and not only a line in the training?

A row has an owner, a score, a control and a date. Training is one control. The register shows whether the risk is still high after the training and who answers.

Field notes

  • NIST SP 800-226 (final, March 2025) gives guidelines for evaluating differential privacy guarantees. Take your epsilon and the way to count the budget from the current text.
  • Reputational loss is an impact. Score it for the incident that causes it (a leak, an unfair decline), and keep the response plan of lesson 7 as its control.
  • Ask the legal people two things about IP: what the terms of each listed tool allow it to do with your text, and who owns what the tool generates. Write the answers in the vendor record.
  • Keep controls.csv in the repository with the code, and review it on the date of the management review (lesson 8).