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 03 · 40 minutes

Assess AI risk with a scored register

After this lesson you can
  • Record AI risks with a cause, an impact, a likelihood, an owner and a control
  • Score each risk with a fixed table, before and after its control
  • Report the risks worst first and catch a register with gaps
Lab files of this lesson (17)

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 risk committee of Harbour Credit meets on Friday. It wants one page that lists the AI risks of the company, ranks them, and shows what is already done about each. Today the risks live in the heads of five people. You get the task to build a register as a file, a script that scores it with one fixed table, and a report that puts the worst risk first.

Recall

Lesson 2: a match for a domain shows that a laptop contacted it. What does it not show?

It does not show what data was sent, or whether the person was allowed to use the service. It is a lead for a question, not proof of a breach.

Lesson 2: why test an AI rule on a name that looks like an AI domain?

A rule can match too much. The decoy shop.mylumina-ai.example showed 23 false hits for a plain text search. A rule that gives false hits loses the trust of the people who read its report.

The idea

A risk register is a table of what could go wrong. Each row holds the risk, its cause, its impact, its likelihood, an owner, a control and the risk that remains after the control. You scored risks in the course "Security fundamentals" (lesson 1). Here you use the same method on AI systems, and you keep it in a file that a script reads.

The score is likelihood times impact, each from 1 to 5. The inherent score is the risk before any control. A control is something that lowers the likelihood or the impact. The residual score is what remains after the control. The bands below are fixed for this course. Your organisation sets its own, and they are a choice that people must make.

ScoreRating
15 to 25critical
10 to 14high
5 to 9medium
1 to 4low
Value12345
Likelihoodrareunlikelypossiblelikelyalmost certain
Impactminorlimitednoticeableserioussevere

AI adds risks that an ordinary register does not have. These six are in the register of this lesson.

RiskHow it shows upA control
BiasA group gets worse outcomes than anotherA fairness test before each release (lesson 4)
Data leakageStaff paste records into a promptA vendor check and a block on unlisted tools (lesson 9)
Accuracy driftThe world changes and the model does notA monthly accuracy report on fresh outcomes
Intellectual propertyGenerated code copies licensed codeA licence scan before each merge
Autonomous actionAn agent acts without approvalA person approves every money move
Shadow AIUnlisted tools handle company dataThe shadow AI search of lesson 2, run each month

Prompt injection, which appears in the scenario test and in the Your turn below, is hidden text in the input of a language model that tells it to do something else. The course "AI security fundamentals" covers it.

One row of the register
RiskInherent scoreControlResidual scoreDecisionlikelihood x impactwhat lowers itwhat remainsaccept or add a controlRiskInherent scoreControlResidual scoreDecision1234
  1. Risk → Inherent score: likelihood x impact
  2. Inherent score → Control: what lowers it
  3. Control → Residual score: what remains
  4. Residual score → Decision: accept or add a control

Worked example

Work in ~/krlab/ai-governance with the environment on.

1. Save the register

Each row is one risk, and the last two columns hold the scores that remain after the control. Save register.csv.

Risk R1 of register.csv, in parts
Loan approvals are biased...riskIncome acts as a proxy...cause4impact4likelihoodAinoownerFairness test...control4res_impact2res_likelihoodLoan approvals are biased...riskIncome acts as a proxy...cause4impact4likelihoodAinoownerFairness test...control4res_impact2res_likelihood

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

2. Write the scorer and the report

int("4") turns the text 4 into the number 4. "4".isdigit() is true when a text holds only digits, so a blank cell is not a number, and the code scores it 0 and reports it, as it must, and does not crash. next(...) takes the first value that a generator gives, or the second argument when it gives none. sorted(rows, key=...) sorts rows by a rule. lambda r: ... is a one-line function without a name, and here it gives the sort key of a row r. In the key, a minus sign in front of a number sorts from high to low, and a second value breaks ties. f"{x:<6}" writes x left-aligned in 6 characters.

The BANDS list is the fixed table. The checker flags four kinds of gap: a value that is not a whole number from 1 to 5 (a blank cell is one), a row with no owner, a medium or worse risk with no control, and a residual score above the inherent score (a control cannot make a risk worse; the check skips a row whose inherent score is missing, as that row has its own problem).

register.py

"""register.py: score an AI risk register and print it, worst first.

    python3 register.py report register.csv
"""
import csv
import sys

from govlib import finish

# score = likelihood x impact, both from 1 to 5. The bands are the fixed table of this course.
BANDS = [(15, "critical"), (10, "high"), (5, "medium"), (1, "low")]


def rating(score):
    return next((name for floor, name in BANDS if score >= floor), "unscored")


def number(text):
    """A whole number, or 0 for a blank or other cell, so that problems() can report it."""
    return int(text) if text.strip().isdigit() else 0


def load(path):
    with open(path, newline="") as f:
        rows = list(csv.DictReader(f))
    for row in rows:
        row["score"] = number(row["impact"]) * number(row["likelihood"])
        row["res_score"] = number(row["res_impact"]) * number(row["res_likelihood"])
    return rows


def problems(path):
    found = []
    for row in load(path):
        for field in ("impact", "likelihood", "res_impact", "res_likelihood"):
            if not 1 <= number(row[field]) <= 5:
                found.append(f"{row['id']}: {field} must be a whole number from 1 to 5")
        if not row["owner"].strip():
            found.append(f"{row['id']}: no owner")
        if not row["control"].strip() and row["score"] >= 5:
            found.append(f"{row['id']}: {rating(row['score'])} risk with no control")
        if row["score"] and row["res_score"] > row["score"]:
            found.append(f"{row['id']}: residual risk {row['res_score']} is above the inherent risk {row['score']}")
    return found


def report(path):
    print(f"{'id':<4}{'score':<6}{'rating':<10}{'after':<9}{'rating':<10}{'owner':<7}risk")
    for r in sorted(load(path), key=lambda r: (-r["score"], r["id"])):
        print(f"{r['id']:<4}{r['score']:<6}{rating(r['score']):<10}{r['res_score']:<9}{rating(r['res_score']):<10}{r['owner']:<7}{r['risk']}")


if __name__ == "__main__":
    report(sys.argv[2])
    finish(problems(sys.argv[2]))
python register.py report register.csv
id  score rating    after    rating    owner  risk
R1  16    critical  8        medium    Aino   Loan approvals are biased against group B
R6  15    critical  9        medium    Dana   Staff use AI tools that nobody listed
R2  12    high      8        medium    Dana   Customer data leaks through a chatbot prompt
R3  12    high      6        medium    Bram   Accuracy drifts as the customer mix changes
R5  10    high      5        medium    Femi   An agent acts without approval
R4  6     medium    3        low       Bram   Generated code copies licensed code
problems: 0

3. Read the report

LoanScore's bias risk (R1) has the highest score: likelihood 4 times impact 4 is 16, critical. After its control (the fairness test) the residual score is 4 times 2, which is 8, medium. R6, shadow AI, is the second worst before its control, and its residual score of 9 is the highest residual in the register. A committee looks at the after column first. No control removes a risk, and only R4 ends below medium.

The report ends with problems: 0, so the register has no gaps. That does not prove that the scores are right. It proves that every row is complete.

4. Break the register on purpose

cp copies a file. >> adds text at the end of a file and keeps what was there. | (pipe) hands the output of the command on its left to the command on its right. tail -4 prints the last four lines of what it receives. Make a copy with three faults: a new risk with no owner and no control, a residual score that is higher than the inherent one, and a blank impact. The copy drops the line of R4 with grep -v (lesson 1) and adds R4 again with a higher residual likelihood.

cp register.csv test.csv
grep -v "R4,Generated code" test.csv > test2.csv
echo "R4,Generated code copies licensed code,Engineers accept suggestions unread,3,2,Bram,Licence scan before every merge,3,3" >> test2.csv
echo "R9,An agent reads private files,Too many permissions,4,3,,,4,3" >> test2.csv
echo "R8,Model files are kept for ever,No retention rule,,3,Kit,Delete after one year,2,2" >> test2.csv
python register.py report test2.csv | tail -5
PROBLEM R4: residual risk 9 is above the inherent risk 6
PROBLEM R9: no owner
PROBLEM R9: high risk with no control
PROBLEM R8: impact must be a whole number from 1 to 5
problems: 4

The checker finds four problems: R9 has no owner, R9 is a high risk with no control, R4's residual score of 9 is above its inherent score of 6, and R8 has a blank impact. The blank cell is reported as a problem, and it does not stop the program.

Your turn

The HR department of Harbour Credit brought its own register for the CV screener and the HR chatbot. Save it as register-hr.csv and run the report. There are no steps: read what the report and the checker say.

register-hr.csv

id,risk,cause,impact,likelihood,owner,control,res_impact,res_likelihood
H1,The CV screener ranks group B lower,Past hiring data is biased,5,3,Ines,Blind review of a sample each month,5,2
H2,The chatbot invents a leave policy,The model has no handbook,3,4,,Answer only from the handbook text,3,2
H3,Interview recordings are kept too long,No deletion job,4,3,Joss,,4,2
H4,The vendor changes its data terms,Terms are not watched,2,3,Kit,Review the terms every year,2,4
H5,Hidden text in a CV steers the screener,Prompt injection through the CV file,4,4,Lou,Strip hidden text before scoring,4,3

Then write the line that you would say to the committee about H3: the checker fails it for one reason, and the fix needs a person to decide something that code cannot decide. What is it?

Check yourself

Why does the register keep an owner for each risk?

A risk without an owner has nobody who decides on a control or accepts what remains. The owner is the person who answers (lesson 1). A register with unowned rows is a list of worries.

A control "lowers the likelihood". Where does the register show it, and what must you do to believe it?

It shows in the residual columns. To believe it you need evidence that the control works: a test result, a log, a report. A residual score is a claim until a record backs it, and lessons 4 and 5 show records of this kind.

Why can a fixed scoring table mislead?

Multiplying two guessed numbers gives a number that looks exact. A rating of 12 is only a little worse than 10, and the bands put them in the same group. Use the table to rank and to start a conversation. Do not use it as a measurement.

Which row of the AI table in this lesson would you re-score first if a customer-data leak happened at a vendor?

Data leakage. Its likelihood was a guess and the event is evidence that it is higher. Raise it, check that the control still holds, and write the incident in the response plan (lesson 7).

Field notes

  • Write the cause of a risk in a way that a control can address. "Staff paste records into free tools" can be controlled. "People are careless" cannot.
  • Residual risk is accepted by a named person with the authority to accept it, and the register should record who and when. A high residual risk that nobody accepted is an open decision.
  • Likelihood for AI risks can use data. The monthly selection-rate ratio and the accuracy on fresh outcomes are measurements that raise or lower a score. Use them where you have them.
  • The NIST AI Risk Management Framework and its generative AI profile (lesson 7) and ISO/IEC 42001 (lesson 8) both ask the organisation to assess AI risks and to keep a record of the result. A register like this one is that record.
  • Review the register on a schedule and after every incident. List the register in the records of lesson 8, as the AI risk assessment is, and the overdue check will report it when its review date has passed.