Lesson 09 · 50 minutes
Evaluate a model provider and check where your data goes
- Record a due-diligence check of a model provider as a structured file
- Score the provider with a fixed table and read the result
- Check a table of data flows against a rule for the location of each data class, and require a signed assessment for personal data
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
HelpBot sends customer questions to ModelHost, a hosted language model. Procurement wants a signed due-diligence record before the contract is renewed, and the data protection officer asks a second question: "Does any personal data of ours leave the regions we allowed?" You know from the course "AI security fundamentals" (lesson 8) which questions to put to a provider. Here you keep the answers in a file, score them, and check the data flows with a script.
Recall
Lesson 8: what does the field every_days of the management records mean?
It is the interval after which a record is due again. The due date is last_done plus every_days, and the script reports a record whose due date is before the date of the run.
Lesson 2: why does each system in the inventory have a data class?
The data class says how sensitive the data is. This lesson uses it to decide where the data may go: personal data has a narrower list of regions than public data.
The idea
A model provider is a third party: it handles your data and its behaviour is outside your control. A due-diligence record is a short file that states what you asked, what the provider answered, who judged it and when. Providers change their terms, so a dated record shows what you knew when you signed, and a review date (lesson 8) makes you ask again. Six questions cover most of the risk.
| Question | Why it matters |
|---|---|
| Is our data used to train the model? | A model can repeat what it was trained on |
| How long do they keep it? | Kept data can leak or be demanded |
| Where is it processed? | The region decides which rules and authorities apply |
| Who are the sub-processors? | They handle your data too |
| How fast do they tell us about an incident? | Your own duties can start with their notice |
| Can we audit them, or see an independent report? | A claim without evidence is only a claim |
The last row is about third-party evaluation: evidence from somebody other than the provider, such as an audit report, a certificate or your own test. A page that says "we are secure" is not evidence.
Data location needs two words. Data residency says in which region the data is stored and processed. Data sovereignty says whose laws and authorities can reach the data. A provider whose servers are in your region can still be subject to the law of another country, so a region check is necessary and not sufficient. Your legal and security people decide which regions are allowed for each kind of data. The script only enforces the decision.
A public model is a service that any customer reaches over the internet, under terms that you accept as they are. A private model runs only for you: a dedicated instance at a provider, or a model on your own servers. Three questions separate them: what leaves the organisation (every prompt, with any personal data in it), who may train on it (data_use in step 1), and where it runs. A dedicated instance is still a third party, so ask it the six questions too. A model on your own servers moves the patching to you. A sound policy line: personal data and confidential code go only to a private model or to a public service with a signed no-training term.
- Questions → Scoring table: six answers in one record
- Scoring table → Decision: accept, conditions or reject
- Decision → Flow check: each data flow against regions
- Flow check → Pack: record and check as evidence
Worked example
Work in ~/krlab/ai-governance with the environment on.
1. Save the record of the provider
The data_class is the most sensitive data that HelpBot sends. data_use is one of no_training, opt_out (training unless you opt out) and training. subprocessors is listed_with_notice, listed or not_listed. audit_right is full, report_only or none. ModelHost is an invented provider.
vendor.json
{
"vendor": "ModelHost",
"service": "Hosted language model for HelpBot",
"data_class": "personal",
"data_use": "no_training",
"retention_days": 30,
"regions": ["eu-west", "eu-north"],
"subprocessors": "listed",
"incident_notice_hours": 48,
"audit_right": "report_only",
"reviewed": "2026-11-02",
"reviewer": "Dana"
}2. Save the location rule
The rule maps each data class to the regions that are allowed. The region names are invented.
location_rules.json
{
"personal": ["eu-west", "eu-north"],
"internal": ["eu-west", "eu-north", "us-east"],
"public": ["eu-west", "eu-north", "us-east", "ap-south"]
}3. Write the scorer
Each question gives 0, 1 or 2 points. A dictionary maps each answer to its points. by_limit(value, good, fair) gives 2 up to the first limit, 1 up to the second, and 0 above it. all(...) is true when every item is true. The decision: 10 points or more with no zero is accept, 7 or more is conditions, and anything else is reject. The table is fixed for this course, and your organisation sets its own. A single zero is a red flag even when the total is high. A record that cannot be scored (a field is missing, or an answer is not in the table) is reported first, and the score is not printed.
vendor.py
"""vendor.py: score a model provider and check where data flows.
python3 vendor.py score vendor.json location_rules.json
python3 vendor.py flows flows.csv location_rules.json
"""
import csv
import json
import sys
from govlib import finish
REQUIRED = ["vendor", "data_class", "data_use", "retention_days", "regions", "subprocessors",
"incident_notice_hours", "audit_right", "reviewed", "reviewer"]
# The fixed scoring table. Each question gives 0, 1 or 2 points. Your own table can differ.
DATA_USE = {"no_training": 2, "opt_out": 1, "training": 0}
SUBPROCESSORS = {"listed_with_notice": 2, "listed": 1, "not_listed": 0}
AUDIT = {"full": 2, "report_only": 1, "none": 0}
def by_limit(value, good, fair):
return 2 if value <= good else 1 if value <= fair else 0
def score(record, allowed):
"""Return {question: points}. Location is 2 points if every region is allowed for the data class, else 0."""
where = all(region in allowed[record["data_class"]] for region in record["regions"])
return {
"data use": DATA_USE[record["data_use"]],
"retention": by_limit(record["retention_days"], 30, 90),
"location": 2 if where else 0,
"sub-processors": SUBPROCESSORS[record["subprocessors"]],
"incident notice": by_limit(record["incident_notice_hours"], 24, 72),
"audit right": AUDIT[record["audit_right"]],
}
def decision(points):
total = sum(points.values())
return "accept" if total >= 10 and 0 not in points.values() else "conditions" if total >= 7 else "reject"
def record_problems(record, allowed):
"""Why a record cannot be scored: a field is missing, or an answer is not in the table."""
found = [f"vendor record: field missing: {name}" for name in REQUIRED if name not in record]
if found:
return found
for name, table in (("data_use", DATA_USE), ("subprocessors", SUBPROCESSORS), ("audit_right", AUDIT),
("data_class", allowed)):
if record[name] not in table:
found.append(f"vendor record: {name} {record[name]!r} is not one of {list(table)}")
return found
def vendor_problems(record, allowed):
found = record_problems(record, allowed)
if found:
return found
points = score(record, allowed)
if decision(points) == "reject":
found.append(f"{record['vendor']}: rejected, {sum(points.values())} of 12 points")
return found
def flow_problems(path, allowed):
with open(path, newline="") as f:
return [f"{r['system']} sends {r['data_class']} data to {r['destination']} in {r['region']}"
for r in csv.DictReader(f) if r["region"] not in allowed[r["data_class"]]]
if __name__ == "__main__":
with open(sys.argv[3]) as f:
allowed = json.load(f)
if sys.argv[1] == "flows":
finish(flow_problems(sys.argv[2], allowed))
with open(sys.argv[2]) as f:
record = json.load(f)
if not record_problems(record, allowed):
points = score(record, allowed)
for question, got in points.items():
print(f"{question:<17}{got}")
print(f"total {sum(points.values())} of 12: {decision(points)}")
finish(vendor_problems(record, allowed))python vendor.py score vendor.json location_rules.jsondata use 2
retention 2
location 2
sub-processors 1
incident notice 1
audit right 1
total 9 of 12: conditions
problems: 0ModelHost scores 9 of 12. It gives a report instead of full audit rights, it lists its sub-processors without a promise of notice, and it tells about incidents within 48 hours. Nothing scores zero, so the decision is conditions. People write the conditions: notice of new sub-processors, and 24 hours for incident notice.
A check must report a record that it cannot score, and not stop with an error. The first copy below has an answer that the table does not know, and the second has no regions line. Neither prints a score.
sed 's/"no_training"/"none"/' vendor.json > bad1.json
grep -v '"regions"' vendor.json > bad2.json
python vendor.py score bad1.json location_rules.json
python vendor.py score bad2.json location_rules.jsonPROBLEM vendor record: data_use 'none' is not one of ['no_training', 'opt_out', 'training']
problems: 1
PROBLEM vendor record: field missing: regions
problems: 14. Check the data flows
Each row of flows.csv says which system sends which class of data to which destination and region. The drawing shows the two flows of personal data. Its last arrow is the test of the second run below: the backup of LoanScore moves to us-east.
- HelpBot → ModelHost eu-west: personal data, allowed
- LoanScore → CloudBox eu-north: backup of personal data, allowed
- LoanScore → CloudBox us-east (blocked): the same backup after the move
flows.csv
system,data_class,destination,region
HelpBot,personal,ModelHost,eu-west
LoanScore,personal,CloudBox backup,eu-north
Nova Chat,internal,NovaChat,us-east
CodePal,internal,CodePal Ltd,us-eastpython vendor.py flows flows.csv location_rules.json
sed 's/CloudBox backup,eu-north/CloudBox backup,us-east/' flows.csv > moved.csv
python vendor.py flows moved.csv location_rules.jsonproblems: 0
PROBLEM LoanScore sends personal data to CloudBox backup in us-east
problems: 1The second run tests the check: a backup that moves to us-east takes personal data out of the allowed regions, and the check names it.
5. Require an assessment for personal data
In the EU, the GDPR asks for a data protection impact assessment (DPIA) before a use of personal data that is likely to put people's rights at high risk. The pack can do one simple thing: when the inventory says that a system holds personal data (lesson 2), the pack must hold a written assessment, so that nobody has to remember it. Save dpia.md. It has header lines and ### sections, like the policy of lesson 1.
dpia.md
# Data protection impact assessment of LoanScore
Owner: Aino
Reviewed by: Dana, 2026-11-05
### Purpose
LoanScore ranks consumer loan applications for a credit officer, who makes the decision.
### Data
Income, debt ratio and years of credit history of loan applicants. The group label is kept apart from the model inputs and is used only to measure fairness.
### Risks to people
An applicant can be declined because of a wrong or unfair score. A leak of application data would harm applicants. Applicants may not know that a score was used.
### Measures
Fairness test each month (lesson 4). A reason for each decision (lesson 5). Access to the group label is limited. Applicants are told about the score in the loan letter. Data is deleted when the contract says so.The checker finds the system in the inventory. If its data class is not personal, nothing is required. Otherwise dpia.md must exist, hold the four sections with at least eight words each, and have a Reviewed by: line with a name. It splits the text as policy_check.py does. next(..., None) gives the first match, or None when there is none.
dpia_check.py
"""dpia_check.py: a system with personal data needs a written data protection impact assessment.
python3 dpia_check.py FOLDER SYSTEM (the folder holds inventory.csv and dpia.md)
"""
import sys
from pathlib import Path
from govlib import finish
from inventory import load
SECTIONS = ["Purpose", "Data", "Risks to people", "Measures"]
MIN_WORDS = 8
def problems(folder, system):
folder = Path(folder)
row = next((r for r in load(folder / "inventory.csv") if r["name"] == system), None)
if row is None:
return [f"{system} is not in the inventory"]
if row["data_class"] != "personal":
return []
if not (folder / "dpia.md").is_file():
return [f"{system} holds personal data, and dpia.md is missing"]
head, *parts = (folder / "dpia.md").read_text().split("### ")
sections = {part.partition("\n")[0].strip(): part.partition("\n")[2] for part in parts}
found = [f"dpia.md: section missing or too short: {name}"
for name in SECTIONS if len(sections.get(name, "").split()) < MIN_WORDS]
if not any(line.startswith("Reviewed by:") and line.partition(":")[2].strip() for line in head.splitlines()):
found.append("dpia.md: no 'Reviewed by' line")
return found
if __name__ == "__main__":
finish(problems(sys.argv[1], sys.argv[2]))Check LoanScore, then check a copy of the folder where the Reviewed by line is gone. mkdir -p and cp are from lessons 0 and 3.
python dpia_check.py . LoanScore
mkdir -p dpia-test
cp inventory.csv dpia-test/
grep -v "^Reviewed by" dpia.md > dpia-test/dpia.md
python dpia_check.py dpia-test LoanScoreproblems: 0
PROBLEM dpia.md: no 'Reviewed by' line
problems: 1The check forces the file to exist and to be signed. A person must still judge what it says.
Your turn
Procurement also looks at QuickInfer, a cheaper provider for document summaries. Save its record and the flows of the summary service. There are no steps: score the provider and check the flows.
vendor-b.json
{
"vendor": "QuickInfer",
"service": "Hosted model for document summaries",
"data_class": "personal",
"data_use": "opt_out",
"retention_days": 90,
"regions": ["eu-west", "us-east"],
"subprocessors": "not_listed",
"incident_notice_hours": 24,
"audit_right": "none",
"reviewed": "2026-11-10",
"reviewer": "Nico"
}flows-b.csv
system,data_class,destination,region
DocSum,personal,QuickInfer,eu-west
DocSum,personal,QuickInfer,us-east
DocSum,internal,QuickInfer,us-east
Archive,personal,ColdStore,eu-north
Archive,public,ColdStore,ap-south
Review,personal,SlideAI,ap-southLast, write three lines to procurement: what you would ask QuickInfer to change before you would look at it again.
Check yourself
HelpBot's questions hold personal data. What do you check before you choose a public model, and what changes if you choose a private one?
For a public model: the data_use answer (no training), the retention, the regions and the sub-processors, in a signed contract. For a private model the training question goes away, but you own the patching, the access control and the monitoring. The data class of the inventory (lesson 2) decides which kind you may use.
Why does a single zero make the result a red flag even when the total is high?
A total can hide a fatal answer. A provider that trains on your personal data may score well on the other five questions and still be unacceptable for that data. Look at the zeros before you look at the sum.
A provider keeps all its servers in your region. Does that settle the question of data sovereignty?
No. Residency says where the data is. Sovereignty says whose laws and authorities can reach it, and a company in your region can be owned by, or bound to, a body in another country. The region check is a start. Ask your legal team about the rest.
What is the weakness of a score from a table like this one?
The answers come from the provider, and the points hide the size of a difference. 30 days of retention and 31 days are one point apart in the table and nothing apart in life. Use the score to compare and to find the questions to ask again.
Field notes
- Ask for evidence and keep it. An independent audit report or a certificate is worth more than a questionnaire answer. Check that its scope covers your service.
- Test the provider yourself too. A small set of questions with known answers, run each month, shows a change of behaviour that no document announces (lesson 7 of "AI security fundamentals" names this control).
- Put the answers into the contract: the training clause, the retention, the regions, the sub-processor notice, the incident time. A record without a contract clause is a hope.
- Plan the exit: if the provider is rejected next year, which system stops?
- The rule of this lesson is about regions only. Rules about transfers of personal data, and who may access data, are legal questions. Take the allowed list from your legal team, and keep it in a file that has an owner and a review date. Your data protection officer decides whether the assessment of step 5 is needed and what it must hold.