AI Red Teaming course · lesson 14 of 26
- 1What Is AI Red Teaming?
- 2Ethics, Authorization, and Rules of Engagement
- 3AI and Machine Learning Basics for Red Teamers
- 4Security Principles and AI Threat Modeling
- 5Build a Safe AI Red Team Test Lab
- 6Jailbreaks and Safety Filter Bypasses
- 7Prompt Injection: Direct and Indirect
- 8Code Injection and Tool Abuse
- 9System Prompt and Data Leakage
- 10Countermeasures for Prompt Attacks
- 11Data Poisoning and Backdoors
- 12Adversarial Examples
- 13Model Extraction and Weight Theft
- 14Model Inversion and Privacy Leaks
- 15Model Manipulation and the AI Supply Chain
- 16AI Infrastructure, Deserialization, and Remote Code Execution
- 17API Authentication and Authorization
- 18Black, Grey, and White Box Testing
- 19Manual, Automated, and Continuous AI Testing
- 20AI Red Teaming Tools, Frameworks, and Datasets
- 21Write Your Own AI Security Test Harness
- 22Report AI Security Findings and Track Fixes
- 23Defense in Depth for AI Systems
- 24Red Teaming LLM Applications and Agents
- 25Disclosure, Law, Careers, and What's Next
- 26Capstone: Red Team a Practice App
After this lesson, you will be able to distinguish model memorization, model inversion, and membership inference, run a small membership test with synthetic records, and identify privacy controls that reduce exposure. The lab uses fabricated record IDs and a deliberately leaky score fixture. It does not contain personal data or query a real model.
Training a model on sensitive examples can affect what the model later reveals. Sometimes a model repeats a specific detail it has memorized. Sometimes a person can use model behavior to infer whether one record was included in training. Other methods try to reconstruct a private feature or example from a model's outputs. These are different privacy questions, and a useful test names the one it is checking.
NIST's Adversarial Machine Learning taxonomy includes privacy attacks against both predictive and generative models. Its glossary defines a membership-inference attack as an attempt to determine whether a data sample appeared in a model's training set. A membership result can itself be sensitive. If a training set was built from a confidential group, learning that a person's record was included may reveal something even when no text or image is reproduced.
Three related privacy risks
Memorization happens when a model retains details from examples it saw during training and may reproduce them in an output. A model that repeats a rare phrase, a private note, or a unique combination of facts may expose more than a general pattern. Memorization is influenced by the data, training process, model, and prompt. It is not the same as a model deliberately storing a searchable copy of every training record, and a model's output can also be an inaccurate reconstruction.
Model inversion is a family of attacks that uses access to a trained model to infer or reconstruct information about its training data. A result might be an inferred sensitive attribute, a representative example for a class, or a reconstruction that resembles part of a training sample. NIST describes the related objective of data reconstruction as recovering sensitive training data from aggregate information. The phrase can cover different goals and methods. A reconstructed output is not automatically an exact copy of one person’s record, and a plausible result is not proof that a particular individual had a particular attribute. The privacy risk is that the model's behavior may reveal information that should have remained private.
The early model-inversion research by Fredrikson, Jha, and Ristenpart examined how confidence information could support inferences about sensitive attributes. Later work explores different model types and settings. The exact information an attack can infer varies with the model, the data, the access available, and what the evaluator already knows. Keep the lesson's examples conceptual and test only in an approved environment with synthetic data.
Membership inference asks a narrower question: did this candidate record contribute to training? The answer is often described as “member” or “non-member.” It does not, by itself, recover the record's contents. But membership may reveal sensitive participation, such as whether a person was in a particular study or whether a confidential example was included in a training set.
The three risks can overlap. A model that memorizes examples may give a membership test a useful signal. An inversion result may reveal an attribute without identifying whether an exact record was included. A membership attack may disclose participation without reproducing any content. When writing a finding, describe the evidence and the privacy question precisely instead of using “the model leaked data” for every outcome.

Why model behavior can reveal a signal
A model learns statistical patterns from the examples it is trained on. If it fits some training examples unusually closely, its responses on those examples may differ from responses on similar examples it did not see. One observable difference might be a confidence score. Another might be a tendency to repeat a distinctive sequence. These are potential signals, not guaranteed evidence of membership or memorization.
The original membership-inference study by Shokri and colleagues examined whether differences between a model's behavior on training and non-training examples could help answer the membership question. This provides a useful testing frame: compare records whose membership is known, examine what signal is visible, and measure both correct guesses and false alarms. The paper's findings do not imply that every model exposes a useful signal or that a result transfers to a different model or dataset.
Access affects the test. A person may see only the final answer, or may also see confidence scores, multiple candidate outputs, embeddings, intermediate values, or a local model's parameters. More access can create more ways to examine behavior. The test must state which access path was used and what was observable. Do not assume a published result applies to a different interface or that hiding a confidence value alone solves privacy risk.
Run the synthetic membership test
The lab contains a small mock signal. Two fabricated IDs are marked as synthetic training members; two others are held out as non-members. The mock returns a high score for a planted member and a lower score for any other synthetic ID. A simple threshold turns that score into a membership guess. The example intentionally exposes membership so that the test's job is easy to see.
Save the lesson code
Save these 2 files in the lab folder you created in the safe lab lesson.
membership_lab.py
1"""Synthetic membership signal for a privacy-testing lesson.
2
3This fixture does not train a model. It deliberately gives planted synthetic
4members higher scores so learners can test a membership decision safely.
5"""
6
7from __future__ import annotations
8
9from collections.abc import Sequence
10
11
12SYNTHETIC_MEMBERS = frozenset({"synthetic-record-101", "synthetic-record-202"})
13SYNTHETIC_NONMEMBERS = ("synthetic-record-303", "synthetic-record-404")
14MEMBER_SCORE = 0.96
15NONMEMBER_SCORE = 0.62
16MEMBERSHIP_THRESHOLD = 0.80
17
18
19def toy_confidence(record_id: str) -> float:
20 """Return the deliberately exaggerated mock score for a synthetic record."""
21 if not isinstance(record_id, str) or not record_id.strip():
22 raise ValueError("record_id must be non-empty text")
23 return MEMBER_SCORE if record_id in SYNTHETIC_MEMBERS else NONMEMBER_SCORE
24
25
26def guess_membership(confidence: float, threshold: float = MEMBERSHIP_THRESHOLD) -> bool:
27 """Guess membership from the toy score threshold."""
28 if not 0.0 <= confidence <= 1.0:
29 raise ValueError("confidence must be between zero and one")
30 if not 0.0 <= threshold <= 1.0:
31 raise ValueError("threshold must be between zero and one")
32 return confidence >= threshold
33
34
35def evaluate_membership_guesses(candidates: Sequence[str]) -> dict[str, int]:
36 """Count correct member guesses and false positives in a synthetic set."""
37 if not candidates:
38 raise ValueError("at least one candidate is required")
39
40 true_positive = 0
41 false_positive = 0
42 true_negative = 0
43 false_negative = 0
44 for record_id in candidates:
45 actual_member = record_id in SYNTHETIC_MEMBERS
46 guessed_member = guess_membership(toy_confidence(record_id))
47 if actual_member and guessed_member:
48 true_positive += 1
49 elif actual_member:
50 false_negative += 1
51 elif guessed_member:
52 false_positive += 1
53 else:
54 true_negative += 1
55
56 return {
57 "true_positive": true_positive,
58 "false_positive": false_positive,
59 "true_negative": true_negative,
60 "false_negative": false_negative,
61 }test_membership.py
1"""Synthetic membership inference tests; no real records are used."""
2
3import unittest
4
5from membership_lab import (
6 MEMBERSHIP_THRESHOLD,
7 MEMBER_SCORE,
8 NONMEMBER_SCORE,
9 SYNTHETIC_MEMBERS,
10 SYNTHETIC_NONMEMBERS,
11 evaluate_membership_guesses,
12 guess_membership,
13 toy_confidence,
14)
15
16
17class MembershipLabTests(unittest.TestCase):
18 def test_planted_synthetic_member_has_the_mock_high_score(self) -> None:
19 member = next(iter(SYNTHETIC_MEMBERS))
20
21 self.assertEqual(toy_confidence(member), MEMBER_SCORE)
22 self.assertTrue(guess_membership(toy_confidence(member)))
23
24 def test_synthetic_nonmember_stays_below_the_mock_threshold(self) -> None:
25 nonmember = SYNTHETIC_NONMEMBERS[0]
26
27 self.assertEqual(toy_confidence(nonmember), NONMEMBER_SCORE)
28 self.assertFalse(guess_membership(toy_confidence(nonmember)))
29
30 def test_threshold_is_explicit_and_validated(self) -> None:
31 self.assertFalse(guess_membership(MEMBERSHIP_THRESHOLD - 0.01))
32 self.assertTrue(guess_membership(MEMBERSHIP_THRESHOLD))
33 with self.assertRaises(ValueError):
34 guess_membership(1.2)
35
36 def test_summary_reports_correct_guesses_on_synthetic_candidates(self) -> None:
37 result = evaluate_membership_guesses((*SYNTHETIC_MEMBERS, *SYNTHETIC_NONMEMBERS))
38
39 self.assertEqual(
40 result,
41 {"true_positive": 2, "false_positive": 0, "true_negative": 2, "false_negative": 0},
42 )
43
44 def test_fixture_rejects_empty_input(self) -> None:
45 with self.assertRaises(ValueError):
46 toy_confidence(" ")
47 with self.assertRaises(ValueError):
48 evaluate_membership_guesses([])
49
50
51if __name__ == "__main__":
52 unittest.main()Run the focused tests from the lab folder:
1cd ai-red-teaming-lab
2python3 -m unittest -v test_membershipThe tests check that a known synthetic member receives the mock high score and is guessed as a member, while a synthetic non-member remains below the threshold. The summary test checks the counts for the small candidate set. No real example, external model, or provider is involved.

Then run the full course lab suite:
1python3 -m unittest -vAll five membership tests passing means the toy fixture and its assertions work as written. Because the mock score is intentionally different for members and non-members, the test does not show that a trained model leaks membership. It demonstrates the shape of a test: known synthetic membership labels, an observable signal, a decision rule, and counts that include both correct guesses and false positives.
Read membership results carefully
The threshold is the score above which the toy labels a candidate a member. A lower threshold could flag more true members, but it could also incorrectly flag more non-members. A useful test reports both. A false positive is a non-member incorrectly called a member; a false negative is a member incorrectly called a non-member. In a real privacy assessment, also track how many cases were evaluated and how the threshold was chosen.
An inference result is not certainty about an individual. A score may reflect the model's general fit or confidence rather than record membership. A test may perform well on one dataset and poorly on another. If the underlying record is rare or the reference examples are not comparable, a simple decision rule can be misleading. Use a trusted evaluation set with known membership and keep it separate from the model's training data.
Avoid presenting a single accuracy number without its assumptions. A highly imbalanced candidate set can make a guess look accurate by always choosing the common class. Include member and non-member performance, false-positive rates, the access level, model and dataset versions, and the threshold or decision rule. For repeated or randomized model behavior, run enough trials to describe the variation and report the range rather than selecting only the clearest result.
Membership can be sensitive even when the attack confidence is imperfect. A finding should explain the possible consequence without overstating the evidence. For example, “under these test conditions, the score signal separated most known members from non-members” is more precise than “the model remembers every patient.” Have a privacy or domain owner review the interpretation before testing or reporting claims about real people.
Prepare an authorized privacy test
Before testing, define whose privacy unit matters: an individual record, a person with several records, or a group. State what the candidate membership would reveal in context. A record being present in a public training set may have a different consequence from presence in a confidential health study. The red team should describe that possible impact without collecting more personal information than it needs.
Use a test set with known membership labels and keep it separate from training. Include comparable member and non-member examples, and decide how scores or outputs will be observed. If the real application returns only a category, do not base conclusions on confidence values that the product never exposes. If the model is randomized, evaluate repeated responses under the authorized interface and note the variation. A locally inspected model and a remote API are different access settings, so report which one you tested.
Keep the evidence small and protected. A test record ID, model version, access mode, score category, and aggregate result may be enough; retaining the underlying private text or image could create another exposure. Decide who may see the results, how long they are kept, and what the team will do if an unexpected detail appears. For the course lab, the synthetic IDs are safe to print because they contain no information about real people.
What inversion can and cannot establish
Inversion results need careful interpretation. A reconstruction may be a class representative, an attribute estimate, a blend of patterns, or a noisy approximation. It might resemble real training examples because the model learned common features, not because it copied one exact record. A model can also generate convincing but false personal details. Do not treat an output as verified information about a real person without independent evidence and a clear lawful basis to handle that evidence.
The strongest privacy questions often concern a specific data path. Was the value part of training, included in a fine-tune, returned from retrieval, repeated from conversation context, or written to a log? Lesson 9 covered leakage through hidden context, retrieval, and logs. Here the question is whether information learned during training or reflected in model behavior can be inferred. A privacy incident may involve more than one path, so establish the system boundary before assigning a cause.
Tests should use synthetic records or data approved for this purpose. Do not use a real person's health, financial, employment, identity, or other private information as a canary. Do not query a public model to see whether it memorized a named person's details. If a system owner authorizes a production evaluation, agree on data minimization, access, retention, stopping rules, and evidence handling first. Use a controlled dataset and test accounts whenever possible.
Reduce privacy exposure
Start by using less sensitive data. Data minimization means collecting and sending only the information needed for the task. Remove unnecessary fields before training or fine-tuning, avoid keeping raw conversations by default, and limit who can access datasets and trained models. If the model does not need a personal identifier, exclude it before data enters the pipeline. Data that is not collected or retained cannot be extracted from that copy later.
Review training examples for sensitive content and unusual duplication before training. Track source, purpose, permissions, transformation, and retention. A privacy review should consider whether the training use was expected and authorized, whether an example can be removed from later runs, and whether derived artifacts retain information from it. De-identifying or replacing a name may reduce direct identification, but does not guarantee privacy if the remaining details can be linked back to a person.
Limit what the model returns. Provide the output detail needed by the product, restrict access to sensitive models, and avoid exposing intermediate scores or debug interfaces without a clear need. Monitor unusual access and keep logs lean. These controls can reduce opportunities to infer information, but output filtering and rate limits alone do not remove information already learned by a model.
Differential privacy as one mitigation
Differential privacy is a mathematical framework for bounding how much an individual's contribution can affect the result of an analysis or trained model. NIST's SP 800-226 Guidelines for Evaluating Differential Privacy Guarantees explains how to assess a claimed guarantee and the hazards that can arise in implementation. In broad terms, a differentially private training method aims to make the released model's behavior similar whether one person's data was included or not, under a precisely defined privacy unit and guarantee.
Differential privacy is not a switch that can be enabled after training to erase memorized data. It must be implemented as part of a suitable data analysis or training process, with its privacy parameters and accounting understood. The privacy unit matters: a guarantee about one row is not automatically a guarantee about all records belonging to one person. Repeated training or releases also consume privacy budget under the chosen accounting method. Stronger privacy can reduce model utility, so the team must evaluate both the protection and the impact on the task.
NIST's guidance is useful because it focuses on evaluating what a differential privacy claim actually covers, not just repeating a parameter in a product description. Ask which records or people the guarantee protects, what data and steps are included, how multiple runs are accounted for, and how utility was measured. Differential privacy can bound some kinds of information learned from training data, but it does not protect data leaked through a separate retrieval system, an exposed log, a compromised account, or an unsafe product workflow.
The AI Agents course discusses practical collection and handling controls in Privacy, Bias, and Red Teaming. This lesson adds the model-focused red-team questions: what training information may be revealed, what signal is observable, what the test can establish, and what privacy guarantee or control applies to that path.
Mistakes beginners make
- Treating membership inference, model inversion, and memorization as interchangeable terms.
- Assuming a membership guess proves a person’s record was used, even when the test has false positives.
- Equating a plausible reconstruction with an exact copy of an individual's training record.
- Calling an output a leak without checking whether it came from training, retrieval, the current prompt, or a log.
- Using real private data in a test when a synthetic record would demonstrate the signal safely.
- Reporting only overall accuracy and hiding the false-positive rate or class balance.
- Assuming a model that performs well on normal tasks cannot expose privacy signals.
- Treating a model output filter or API rate limit as a complete privacy solution.
- Claiming differential privacy without stating the privacy unit, parameters, accounting, and scope of the guarantee.
Recap and try it yourself
Memorization is a model retaining specific details; model inversion infers or reconstructs information about training data; membership inference asks whether a record was included. Their results can overlap, but each needs a different test and careful interpretation. Use synthetic membership labels, measure false positives and false negatives, and report the tested model and access path. Reduce exposure through data minimization, dataset review, access control, limited outputs, and privacy-aware training. Differential privacy can provide a formal bound when correctly implemented, but it does not cover unrelated data paths or guarantee zero disclosure.
Try this in the local lab: run the membership tests and write down what the mock threshold reveals about the synthetic candidates. Then list three assumptions that make the result unrealistic for a trained model. Sketch where training examples enter and where outputs leave in a system you own or a fictional one. Mark which controls protect training data, which control model access, and which control logs or retrieval. Keep all test data synthetic.