Integrating AI Platforms: Claude, OpenAI, Gemini and Open Models via APIProduction readiness and capstone · Lesson 17 of 19
Security, data privacy and the production checklist
Video lecture
Security, data privacy and the production checklist
The narrated lecture is in production
Every chapter is scripted and ready. Browse the chapters and read the full transcript now — the video will appear here when it’s published.
Chapters
Transcript of the narration, chapter by chapter.
0:00 Security, privacy, production
Your AI feature works, the demo impressed everyone, and launch is next week. Then the security team asks: what data leaves our systems, where is it stored, for how long, and who can see it? If you can't answer with evidence, launch slips. In this lesson you'll learn the data privacy questions to settle with every provider, the technical controls that protect you, and a production checklist that gets you through review.
0:31 Why it matters
Why does this matter? When you call an AI API, your users' content leaves your systems and goes to a third party processor. That's normal, but it's a responsibility. Think of sending documents to an external translation agency. You'd want a contract, you'd want to know how long they keep copies, where their office is, and you'd black out anything they don't need to see. AI providers deserve exactly the same diligence.
1:02 Four questions per provider
Ask four questions of every provider, product and plan. Training: business APIs from Anthropic, OpenAI and Google say they don't train on your API data by default, but consumer apps and free tiers can differ, so read the terms for the exact product. Retention: providers typically keep inputs and outputs for a limited period for abuse monitoring, and offer zero data retention arrangements for eligible customers. Some features store data by design, like files, batches and caches, and OpenAI's Responses API stores responses unless you set store to false. Location: where processing happens. And agreements: a data processing agreement, subprocessors and certifications.
1:46 Legal context (not legal advice)
Now the legal context, and this isn't legal advice. GDPR and UK GDPR require a lawful basis, data minimization, transparency, processor contracts and safe international transfers. Saudi Arabia's personal data protection law, the UAE's federal law and free zone regimes like DIFC and ADGM add their own requirements, plus sector rules in banking and health. Pakistan has been developing data protection legislation, so check its current status. And the EU AI Act brings phased obligations, like transparency for some AI interactions. Involve your privacy and legal team early.
2:24 Technical controls
Next, technical controls. Minimize: send only what the task needs. Redact personal data before sending where you can. Keep keys on the backend. Defend against prompt injection by treating user content and documents as untrusted, and never letting model output trigger sensitive actions without validation. Handle outputs safely: never render them as raw HTML. Prevent abuse with authentication, rate limits and moderation, and pass a pseudonymous user id where supported, like OpenAI's safety identifier. Log carefully. And keep humans in the loop for consequential decisions.
3:01 Simple example: gym reminders
A simple example of minimization. A gym wants AI to write personalized renewal reminders. The first draft of the code sends each member's full record: name, date of birth, address, phone, payment history and medical notes. The reminder only needs a first name, the membership type and the renewal date. Cutting the payload to those three fields removes most of the risk, cuts tokens, and makes the privacy review a two minute conversation.
3:33 Hands-on: redaction layer
The lesson includes a simple redaction layer. It replaces emails, phone numbers, card numbers, Pakistani CNIC numbers and Emirates ID numbers with placeholder tokens before sending text to a model, and can restore them afterwards if needed. But be honest about its limits. Regular expressions miss names, addresses and free form identifiers, and can over match. Add a named entity detection step, test on real samples, and treat redaction as one layer among several.
4:05 Business example: Lahore fintech copilot
Now a realistic business example. A Lahore fintech built a support copilot that drafts replies for agents. They redact CNIC, card and phone numbers before every call. They chose a provider with a signed data processing agreement and zero data retention on the relevant endpoint. Drafts are never sent automatically, and agents see a label saying the draft was generated with AI. Logs keep metadata for ninety days and redacted text for fourteen. And they run injection tests every quarter using real attack patterns from their inbox. Their security review passed in one cycle, because every item had evidence.
4:48 Production checklist
Finally, the production checklist. Quality: an eval per task with agreed thresholds and per language results. Reliability: error handling, backoff, circuit breaker, tested fallback. Cost: ledger, budgets, cost per outcome. Security: backend keys, secret manager, scanning, injection tests, output sanitization. Privacy: terms reviewed, retention configured, redaction, updated privacy notice. Observability: traces, dashboards and alerts. Operations: versioned config, tested rollback, an owner and a runbook. And compliance: disclosure where required and human oversight for consequential uses.
5:21 Common mistakes
Common mistakes. Sending full records when a few fields would do. Assuming not used for training means not stored. Logging raw prompts with personal data indefinitely. And rendering model output as HTML, which can open you to script injection. Each of these is a common finding in security reviews, and each is easy to fix before launch.
5:46 Answering data questions
What should you do when a customer asks what happens to their data in your AI features? Have a short, accurate answer ready, agreed with legal: which providers process it, for what purpose, how long it's kept, where it's processed, and how they can request deletion. Put it in your privacy notice and your help center. Being able to answer clearly and quickly is one of the strongest trust signals you can give business customers.
6:19 Disclosure and advertising rules
A quick word on disclosure and marketing rules, since many of you will generate customer facing content. Where AI generated content could mislead people, be transparent about it, and follow your market's advertising rules: sponsored posts need clear labels like ad, and claims about health, performance or prices need evidence, whether a human or a model wrote them. Regulators in the UK, the EU, the Gulf and the US all expect marketers to stand behind their claims. Put these rules into your prompts, your validators and your review steps.
6:58 Deeper: the fintech review
Let's deepen the Lahore fintech copilot example. Before launch, the security reviewer asked for evidence on every checklist row. The team provided a data flow diagram showing that CNIC, card and phone numbers were redacted before any provider call, the signed DPA and the zero retention configuration, screenshots of the AI label agents see, log retention settings, and results from their quarterly injection tests using real attack patterns. One gap surfaced: names in free text were not redacted. They added a named entity step and a test set of fifty real, anonymized messages. The review passed in one cycle, and the reviewer reused their checklist as the bank's template for the next AI project.
7:48 Watch me do it: redact() and restore()
Watch me do it. Let's run the redaction layer. Five patterns: email addresses, phone numbers with international prefixes like plus nine two, plus nine seven one or plus nine six six, card numbers, Pakistani CNIC numbers in the five dash seven dash one format, and Emirates ID numbers starting with seven eight four. Redact loops over each pattern, and for every unique match assigns a numbered placeholder such as PHONE one, stores the original in a mapping, and replaces it in the text. Restore swaps the placeholders back, for example after the model drafts a reply that must include the customer's email. I run it on, call Aisha on plus nine seven one fifty, one two three, four five six seven, or her email, about Emirates ID seven eight four and so on. The output replaces the phone, email and ID with placeholders. But Aisha's name is still there, which is exactly why the lesson adds a named entity step.
8:58 Recap + try this now
Quick recap. Ask every provider about training, retention, location and agreements. Know your legal context and involve legal early. Minimize, redact, protect keys, defend against injection and handle outputs safely. And ship with a checklist backed by evidence. Try this now: complete the production checklist for one AI feature, with a link to evidence for every row, add a redaction layer, and review your provider's current data terms and retention settings.
The risk surface of an AI integration
Integrating an AI API adds new data flows (your users' content leaves your systems), new failure modes (hallucinations, refusals, prompt injection) and new costs. A production-ready integration treats these like any other third-party processor plus some AI-specific controls.
Data handling: know what the provider does with your data
Before sending customer or confidential data, confirm for each provider, product and plan:
- Training use: first-party business APIs from Anthropic, OpenAI and Google state that API/business data is not used to train models by default; consumer apps and free tiers may differ (Google's Gemini API terms distinguish unpaid and paid services). Read the current terms for the exact product you use.
- Retention: providers typically retain API inputs and outputs for a limited period for abuse monitoring, and offer zero data retention (ZDR) arrangements for eligible customers and endpoints. Some features (stored responses, files, batches, caches) store data longer by design; OpenAI's Responses API stores responses by default unless you set
store=False. - Location: where data is processed; options such as Anthropic's
inference_geoparameter on supported models, regional deployments on cloud platforms, and data-residency programs. - Subprocessors and agreements: a data processing agreement (DPA), subprocessor list, security certifications (for example SOC 2 reports, ISO 27001).
Legal context (not legal advice)
- GDPR / UK GDPR: lawful basis, data minimization, transparency, processor contracts, international transfer mechanisms, data subject rights.
- Gulf and South Asia: Saudi Arabia's Personal Data Protection Law (PDPL) and its regulations; the UAE's federal PDPL plus free-zone regimes (DIFC, ADGM); sector regulators in banking and health. Pakistan has been developing personal data protection legislation; check the current status.
- AI-specific rules: the EU AI Act's phased obligations (for example transparency for certain AI interactions and generated content, and stricter duties for high-risk uses); advertising and consumer-protection rules for AI-generated marketing (disclose where required, avoid unsubstantiated claims).
Involve your privacy/legal team early, document decisions, and update privacy notices to describe AI processing.
Technical controls
- Minimize: send only what the task needs; strip IDs, emails and phone numbers unless required.
- Redact PII before sending where possible (pattern-based plus a named-entity detector for names and addresses), and re-insert after if needed.
- Secrets hygiene (lesson 2): backend-only keys, secret managers, rotation, scanning.
- Prompt-injection defenses: treat user content, documents and web pages as untrusted; never let model output directly trigger sensitive actions without validation and approval; restrict tools and outbound channels.
- Output handling: never render model output as raw HTML or execute it; sanitize Markdown; validate structured outputs.
- Abuse prevention: authentication, per-user rate limits and quotas, content moderation for user-facing generation, and pass a stable pseudonymous user identifier where the provider supports it (for example OpenAI's
safety_identifier) so abuse can be traced without sending personal data. - Logging with care: log metadata broadly; store full prompts/outputs only where necessary, redacted, access-controlled and with short retention.
- Human oversight for consequential decisions (credit, hiring, medical, legal).
Hands-on: a simple redaction layer
import re
PATTERNS = {
"EMAIL": re.compile(r"[\w.+-]+@[\w-]+\.[\w.]+"),
"PHONE": re.compile(r"(?:\+?\d[\d\s-]{8,}\d)"), # PK +92, UAE +971, KSA +966, UK +44, US +1
"CARD": re.compile(r"\b(?:\d[ -]?){13,19}\b"),
"PK_CNIC": re.compile(r"\b\d{5}-\d{7}-\d\b"),
"UAE_EID": re.compile(r"\b784-?\d{4}-?\d{7}-?\d\b"),
}
def redact(text: str) -> tuple[str, dict]:
mapping, counter = {}, 0
for label, pat in PATTERNS.items():
for m in set(pat.findall(text)):
counter += 1
token = f"[{label}_{counter}]"
mapping[token] = m
text = text.replace(m, token)
return text, mapping
def restore(text: str, mapping: dict) -> str:
for token, original in mapping.items():
text = text.replace(token, original)
return text
clean, m = redact("Call Aisha on +971 50 123 4567 or aisha@example.ae about Emirates ID 784-1990-1234567-1")
print(clean) # names still present: add an NER step (e.g., a local model) for person names and addressesRegexes miss plenty (names, addresses, free-form IDs) and can over-match; treat this as one layer and test it on real samples.
The production checklist
| Area | Ready when |
|---|---|
| Quality | Eval set per task with agreed thresholds; per-language results |
| Reliability | Typed error handling, backoff, circuit breaker, fallback tested |
| Cost | Per-call ledger, budgets and alerts, cost per outcome known |
| Security | Backend-only keys, secret manager, scanning, injection tests, output sanitization |
| Privacy | DPA and terms reviewed, retention settings configured, redaction in place, privacy notice updated |
| Observability | Traces/logs with request IDs, dashboards, alerts on errors, latency and spend |
| Operations | Model IDs and prompts in versioned config, rollback tested, owner and runbook |
| Compliance | Disclosure where required, human oversight for consequential uses, records of decisions |
Worked example: a Lahore fintech's support copilot
The copilot drafts replies for agents. Controls: CNIC numbers, card numbers and phone numbers redacted before calls; provider chosen with a signed DPA and ZDR on the relevant endpoint; drafts never sent automatically; agents see a "draft generated with AI" label; logs keep metadata for 90 days and redacted text for 14; quarterly injection tests using real attack patterns from their inbox. The security review passed in one cycle because every checklist item had evidence.
Pitfalls
- Sending full records when a few fields would do.
- Assuming "not used for training" means "not stored".
- Logging raw prompts with personal data indefinitely.
- Rendering model output as HTML.
Measuring success
Checklist completion with evidence, PII detection rate on test samples, security test pass rate, time to answer a customer data request, and incidents.
Key takeaways
- Confirm training use, retention, location and agreements for each provider product and plan.
- Apply GDPR, UK GDPR, KSA PDPL, UAE PDPL and sector rules with your legal team; watch AI-specific duties.
- Minimize and redact data, keep keys backend-only, defend against injection and sanitize outputs.
- Log with care: metadata broadly, sensitive content redacted, restricted and short-lived.
- Use a production checklist with evidence across quality, reliability, cost, security, privacy and operations.
Check your understanding
Quick questions to lock in the lesson. They don’t count towards your certificate.
Put it into practice
Complete the production checklist for one AI feature with links to evidence, add a redaction layer, and review your provider's current data terms and retention settings.
Enrol for free to save your progress
Reading is always free. Enrol to keep your place, take the final assessment and earn a verifiable certificate.