Secure and responsible AI
Professional Machine Learning Engineer · Lesson 18 of 19 · 2:20:49
YouTube loads only after you press play. This chapter opens at its timestamp in the full course. Watch on YouTube ↗
Learning with these videos? Subscribe for new courses and exam-style questions.
Subscribe on YouTube (opens in a new tab)In this lesson
Prepare for the Google Cloud Professional Machine Learning Engineer exam, on the official exam guide. In this lesson: least privilege, VPC Service Controls, private endpoints, customer-managed encryption keys, Sensitive Data Protection with custom infoTypes, Model Armor, Gemini safety filters, data and model bias metrics by slice, and explanations at inference time. Includes three original practice questions, with Cymbal Insurance, a fictional car and home insurer, as the example.
Study notes
The text of this lesson, to read at your own pace. Information as of November 2026.
Three warnings
One evening, a user told Cymbal Insurance's chatbot to ignore its instructions and list other customers' claims. A week later, an audit found that the fraud model flagged far more claims in rural areas. And the regulator now asks why each claim was flagged.
Securing data and models
Start with least privilege: grant each person and each service account only the roles it needs on data, models, and endpoints. VPC Service Controls draws a perimeter around projects and services, which helps prevent data exfiltration, like copying training data or a model out of the project. Private endpoints with Private Service Connect keep inference traffic off the public internet, and customer managed encryption keys apply when compliance demands them. Sensitive Data Protection finds and masks personal data before training, including your own formats, like policy numbers, described with a custom infoType and a regular expression. And never write raw prompts full of personal data into logs.
Guarding generative AI
Model Armor screens both prompts and responses, with settings kept in templates. It detects prompt injection and jailbreak attempts, harmful content by category and confidence level, malicious URLs, and sensitive data, through Sensitive Data Protection. Gemini also applies safety filters: some cannot be configured, like those for child abuse material and sensitive personal data, while content filters let you set a blocking threshold for each harm category. And system instructions steer the model toward safe, on topic answers.
Responsible AI and bias
Responsible AI starts with measuring how a model treats different groups, called slices, such as regions or age bands. Before training, data bias metrics compare the slices, like the difference in population size, or in the share of positive labels. After training, model bias metrics compare the model's behavior per slice, like the accuracy difference or the recall difference. Fixes include more representative data, removing features that act as a proxy for a protected group, and reviewing decision thresholds. And for decisions that affect people, keep a human in the loop.
Explanations at inference time
A model deployed with an explanation configuration can return feature attributions with each inference. Sampled Shapley fits models that are not differentiable, like ensembles of trees, while integrated gradients fits differentiable models, like neural networks, and XRAI explains regions of images. Example based explanations return similar training examples instead. These attributions also feed monitoring, to spot attribution drift, as lesson nineteen will show.
Recap
Let's recap. Least privilege, VPC Service Controls against exfiltration, private endpoints, and encryption keys protect data and models. Sensitive Data Protection masks personal data, including custom formats defined by a regular expression. Model Armor screens prompts and responses for injection, harmful content, malicious URLs, and sensitive data, alongside Gemini's safety filters. Data and model bias metrics compare slices, like the recall difference. And explanations return feature attributions with each inference, with Sampled Shapley, integrated gradients, or XRAI.
Quick checks for this lesson
The 3 questions of this lesson, as plain text. The button above runs them with shuffled choices and the reason behind every choice.
Users sometimes tell the claims chatbot to ignore its instructions and reveal other customers' data. The team wants such prompts caught before they reach the model. What should it add?
- A larger Gemini model
- A friendlier system instruction
- Model Armor screening of prompts
- A weekly review of chatbot answers
Show the answer
Model Armor screening of prompts
Model Armor screens each prompt, and detects prompt injection and jailbreak attempts before the model sees them. “A larger Gemini model” would only make the model slower, not safer. “A friendlier system instruction” would only change the wording of answers, not stop the attack. And “A weekly review of chatbot answers” would only look at the answers afterward, too late for the users affected.
The fraud model seems to flag far more rural claims than urban ones. The team wants to know whether it catches real fraud equally well in both groups. What should it measure?
- The recall difference between the two slices
- The overall accuracy
- The endpoint's latency
- The number of claims in each slice
Show the answer
The recall difference between the two slices
The recall difference between the rural and urban slices shows whether the model catches real fraud equally well in both. “The overall accuracy” is one number for everyone, which can hide a gap between groups. “The endpoint's latency” only measures speed. And “The number of claims in each slice” only describes the data's size, not how the model behaves.
For every claim it flags, the claims app must show the three factors that weighed most. The model is a custom boosted tree ensemble, served from an endpoint. What should the team set up?
- Explanations with integrated gradients
- XRAI explanations
- A confusion matrix per month
- Explanations with Sampled Shapley
Show the answer
Explanations with Sampled Shapley
Explanations with Sampled Shapley suit a tree ensemble, and return the attribution of each feature with every inference. “Explanations with integrated gradients” suits differentiable models, and a tree ensemble is not differentiable. “XRAI explanations” explains image regions, not claim features. And “A confusion matrix per month” would show how good the model is overall, not why one claim was flagged.