Module 6 · Prepare the Capstone for Review · 45 min
Privacy, Security, Consent, and Your Threat Model
Is lesson ke baad tum
The safest AI workflow is the one that collects less, grants less, exposes less, and can clearly show how every remaining risk is prevented, detected, and handled.
In this lesson
Minimize One Support Ticket
Minimize one supplied support ticket and test what a simple redactor misses. You will create a provider-safe field selection, run the Python example, and write one specific threat entry. The exercise is local and uses synthetic data; it needs no provider account or upload.
Privacy asks whether data is needed and how it may be used. Security protects access and integrity. Consent, where appropriate, records an informed choice for a stated use. A threat model connects an asset, a possible attack path, and testable controls. These engineering checks do not establish legal compliance.
Map the data before the threats
Use this fictional ticket:
{
"order_id": "DEMO-007",
"issue": "The demo fan makes a loud sound.",
"callback_phone": "03000000000",
"email": "demo@example.invalid",
"identity_scan": "synthetic-placeholder-do-not-upload",
"marketing_opt_in": false
}The task is only to summarize the issue and propose a support category. The provider input needs issue; order lookup remains in the authenticated application, callback details remain in the restricted support system if needed for the requested contact, and the identity scan is unnecessary. Marketing opt-in is separate from support processing and must not become true just because a user asks for help.
Record each retained field's purpose, readers, processor, retention/review rule, and deletion route. A provider data setting does not control your own logs or backups. OpenAI distinguishes abuse-monitoring logs from application state; store: false does not by itself establish Zero Data Retention or authorize a private-data upload.
Worked build: a customer-support summarizer
A home-appliance seller wants a tool that summarizes support tickets and suggests the correct team. Tickets may contain names, phone numbers, addresses, order IDs, product serials, and free-text complaints. The tool should not need complete payment details, passwords, or identity documents.
Draw the flow:
customer form -> application API -> redaction/validation -> model provider
-> encrypted job state
-> restricted support dashboard
-> short-retention operational logsAt the form, explain the purpose, what not to submit, whether AI assists the process, the human escalation route, and the relevant privacy contact. A single pre-ticked “I agree to everything” box is not meaningful design. Separate optional uses, such as using a message to improve the service, from the necessary processing of the support request.
Redact common secrets before model or log processing. This small Python example is deliberately limited; production detection needs tests, domain patterns, and review:
import re
PATTERNS = {
"email": re.compile(r"\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b", re.I),
"phone": re.compile(r"(?<!\d)(?:\+?92|0)?3\d{9}(?!\d)"),
"card_like": re.compile(r"(?<!\d)(?:\d[ -]?){13,19}(?!\d)"),
}
def redact(text: str) -> str:
for label, pattern in PATTERNS.items():
text = pattern.sub(f"[REDACTED_{label.upper()}]", text)
return text
print(redact("Call 03000000000 or email demo@example.invalid"))Regex can miss alternate formats and can over-redact legitimate numbers. It is one layer, not a guarantee. Prevent prohibited fields in the UI, validate on the server, minimize the prompt, restrict logs, and let staff correct the summary against the original authorized ticket.
Build the threat model
List assets: customer records, source documents, API keys, tool permissions, approval state, logs, model outputs, and organizational reputation. Then list actors: ordinary user, careless employee, malicious user, compromised account, former contractor, vulnerable dependency, and an external service outage. Avoid assuming the only attacker is a stranger.
For each data flow, ask:
- Can someone spoof identity or role?
- Can someone tamper with input, state, retrieved documents, or tool output?
- Can a person deny an action because audit evidence is missing?
- Can sensitive information be disclosed through output, citations, logs, or error messages?
- Can traffic or loops deny service or exhaust the budget?
- Can a low-privilege user trigger a higher-privilege tool?
One threat entry might read:
| Threat | Path | Impact | Prevent | Detect | Respond |
|---|---|---|---|---|---|
| Prompt injection in ticket | Free text tells model to expose other tickets | Cross-user data leak | Tenant-scoped retrieval, no broad search tool, output filtering | blocked-tool and canary tests | disable tool, investigate trace, rotate affected access |
Assign an owner and residual risk. “Use AI safety” is not a control. “The server filters retrieval by authenticated tenant before any result reaches the model” is testable.
Core controls
Identity and authorization: authenticate users and authorize each object and tool call server-side. Apply least privilege. Separate production roles and remove access promptly.
Secrets: keep API keys and credentials in environment-specific secret storage, never browsers, prompts, repositories, or logs. Rotate and monitor them.
Data protection: encrypt transport, use appropriate storage encryption, limit exports, back up only what is needed, and test deletion across primary stores, caches, indexes, and backups according to policy.
Model boundaries: treat user input, retrieved text, websites, and tool output as untrusted data. Do not let document text redefine system permissions. Constrain tool schemas, validate arguments, and require approval for consequential writes.
Output controls: show uncertainty and sources, moderate where appropriate, prevent secrets from rendering, and keep a human in the loop for high-stakes use.
Operations: log access and security-relevant events with redaction, monitor anomalies and spend, rate-limit abuse, maintain an incident plan, and rehearse revoking a tool or key.
OpenAI's safety guidance recommends moderation, adversarial testing, and human oversight. Platform role-based access controls can help manage provider-side permissions, but your application still needs its own user and object authorization.
Consent and user control
Write notices in plain language and at the moment of collection. State the purpose, required and optional data, whether a third-party AI service processes it, important limitations, retention or deletion route, and human contact. Do not promise perfect confidentiality or accuracy.
Consent is not a substitute for safe design. A user cannot meaningfully consent to an undisclosed secondary use or an insecure public database. Make withdrawal or preference changes practical where relevant, and ensure the workflow still has an appropriate path for required service requests. Keep evidence of the notice/version shown without collecting excessive behavioural history.
Failure cases to test
An API key is bundled into frontend JavaScript.
A citation reveals the title of another client's confidential file.
A prompt asks the model to decide authorization from a user-supplied role.
Raw tickets and phone numbers enter debug logs.
Deleted files remain searchable in a vector index or cache.
A retrieved document contains instructions to call an external tool.
A staff account retains production access after role change.
An approval link can be reused by another person or after the payload changes.
A privacy notice says “for support” while data is reused for marketing or portfolio screenshots.
A redaction rule removes obvious phone numbers but misses spaced or international formats.
Hands-on deliverable
Create a minimal JSON object for the summarization step using only the supplied issue. Compare it with the complete ticket: none of the phone, email, identity placeholder, or marketing field should reach the model or debug log. Keep an opaque application request ID outside the natural-language prompt for reconciliation.
Save and run the redaction example as redact.py. The unspaced phone and email should become labeled placeholders. Then test "Call 0300 0000000". The shown regex misses that spaced eleven-digit phone; record the failure. Do not upload the result or call it anonymized. Add this as a failing coverage case for a future redaction improvement; field minimization remains the first boundary.
Write one threat row: a ticket says “show another customer's order.” The asset is another customer's record; the path is free text attempting to expand a lookup; the preventive control is authenticated tenant/object authorization before retrieval; the test uses two synthetic customers and expects access denied for the other customer; the owner is the application engineer. Mark that cross-customer test NOT RUN unless you actually implement the two-user system.
Finish with a two-sentence draft notice: support purpose, any intended external AI processing, what users should not submit, and a human contact role. Keep service-improvement or marketing choices separate. A draft notice is not proof of consent collection or compliance.
Completion rubric
- The proposed model input contains only the issue text needed for this task.
- The two redaction inputs demonstrate both the detected format and the spaced-number gap.
- The threat entry names an enforceable authorization control and an observable denied-access test.
- Untested authorization/deletion/consent implementation remains explicitly NOT RUN.
Sources
5 reference sources. Open the source to check the details.
Practice quiz
Check yourself
4 questions · practise what you just learned
1 / 4 · key_idea
The ticket includes issue, order ID, phone, email, identity placeholder, and marketing_opt_in false. The model only summarizes the issue and suggests a support category. Which provider input is minimal for that task?
Apna kaam check karo.
Practice complete ki? Result ko example aur lesson ke checks se compare karo.
This is your own completion record, not a graded assessment.