← All Google Cloud AI guidesSection 6 · 6.1, 6.2

Security, responsible AI, explainability and monitoring

Section 6: securing AI systems (Model Armor, safety filters, Sensitive Data Protection, VPC Service Controls), responsible AI and fairness, Explainable AI methods, and Model Monitoring for training-serving skew, drift, concept drift and attribution drift, plus monitoring gen AI in production. Includes a monitoring lab.

1. Security, responsible AI and explainability

Securing AI systems

RiskControl
Prompt injection, jailbreaks, malicious URLs in prompts or retrieved documentsModel Armor: screens prompts and responses for injection and jailbreak attempts, sensitive data, malicious URLs and harmful content; works across models and can be enforced through templates and floor settings
Harmful generated contentGemini safety filters: harm categories (hate speech, harassment, sexually explicit, dangerous content) with configurable block thresholds; plus non-configurable protections
Users pasting PII or secrets into an LLM, or the model echoing themSensitive Data Protection inspection and de-identification (also inside Model Armor), regular expressions for simple fixed patterns, output filtering
Data or model exfiltrationVPC Service Controls perimeters, private endpoints, IAM least privilege, CMEK, organization policies, audit logs
Over-privileged agents and toolsSeparate service accounts per agent or tool, scoped permissions, human approval for risky actions
Poisoned training data or supply chainData validation, provenance and lineage, trusted base images, Artifact Analysis vulnerability scanning
Regex for patterns, SDP for PII, Armor for prompts, filters for harm, VPC-SC for exfiltration. Pick the narrowest tool that matches the threat in the question.

Responsible AI

Explainable AI on Agent Platform

MethodModel typesNotes
Sampled ShapleyAny model, including non-differentiable (trees, ensembles), tabularApproximates Shapley values; more paths = more accurate, slower
Integrated GradientsDifferentiable models (neural networks), tabular or imagesNeeds gradients; baseline choice matters
XRAIImages (differentiable models)Highlights salient regions, easier to read than pixel maps
Example-based explanationsModels with embeddingsReturns nearest training examples; good for spotting mislabelled data and explaining by analogy

Enable explanations when uploading or deploying the model (explanation spec with method and parameters), then call explain on the endpoint, or request explanations in batch inference. Feature attributions are also what Model Monitoring uses to detect attribution drift.

Feature attributions explain what the model used, not causality. A high attribution for "ZIP code" may reveal a fairness problem rather than a business insight.

Fairness metrics in one table

MetricEqual across groupsUse when
Demographic parityPositive prediction rateOutcomes (offers, approvals) should be distributed evenly
Equal opportunityTrue positive rate (recall)Qualified people in every group should be found equally
Equalized oddsTrue positive and false positive ratesBoth kinds of error should be balanced
Predictive parityPrecisionA positive prediction should mean the same in every group
These criteria generally can't all be satisfied at once when base rates differ. Choose with domain and legal input, document the choice in the model card, and monitor it.

2. Monitoring and troubleshooting

What can go wrong after launch

ProblemMeaningDetect with
Training-serving skewProduction input distribution differs from the training data (often a preprocessing bug or a different source)Model Monitoring with the training dataset as baseline
Data (prediction) driftProduction inputs change over time compared with an earlier production windowModel Monitoring comparing recent windows
Concept driftThe relationship between inputs and label changes (fraudsters adapt); inputs may look the sameGround-truth performance tracking (needs labels): precision/recall over time
Feature attribution driftThe features the model relies on change importanceModel Monitoring with Explainable AI enabled
Operational issuesLatency, errors, saturation, costCloud Monitoring metrics and alerts, Cloud Logging, request-response logging to BigQuery

Model Monitoring on Agent Platform

Model Monitoring v1 (endpoint-centric jobs) and v2 (model-centric monitors) both appear in material; default thresholds and APIs differ by version. Learn skew vs drift vs attribution drift and what each baseline is.

Monitoring and testing gen AI

Troubleshooting order

  1. Did the system break? Errors, latency, quota, a deployment change, a missing feature.
  2. Did the inputs change? Skew (pipeline bug) vs drift (world changed).
  3. Did the relationship change? Concept drift, confirmed with fresh labels.
  4. Fix the cause: repair preprocessing for skew; retrain on recent data for drift and concept drift; add features if the world changed in a way the model can't see.
Retraining doesn't fix training-serving skew caused by a bug: the new model trains on the same correct data and is served the same broken inputs. Fix the serving pipeline.

3. Lab: Model Monitoring and drift

  1. Using an endpoint from the serving lab, enable request-response logging and create a model monitor with the training table as baseline, a short interval and low thresholds.
  2. Send normal traffic, then traffic with one feature shifted (for example multiply monthly_spend by 3).
  3. Find the skew alert; identify which feature crossed its threshold and the distance value.
  4. Decide whether this is skew or drift, and what you'd do for a pipeline bug vs a real market change.
  5. Enable explanations (Sampled Shapley) on the model and request explanations for five rows; compare the top features with ML.GLOBAL_EXPLAIN or your offline analysis.
  6. Slice evaluation by one group column and compute recall per group (equal opportunity).

Clean up: delete the monitor, undeploy models and delete the endpoint.

4. "Which control or monitor?" chooser

Pick an item to see what it means, why, and the tempting wrong choice.

Pick one above.

5. Sample outputs

What the tools return. Expand an item to see a typical result and what to read in it.

Illustrative output, not captured from a real project. IDs, numbers and some field names are invented or simplified, and formats change between releases. Learn the shape and the fields called out under each one.
Model Monitoring alert (email / Pub/Sub payload, simplified)Feature skew detected
Model monitor: churn-monitor   Objective: FEATURE_SKEW
Baseline: bq://PROJECT_ID.shop.train   Window: last 24h, sampling 50%
feature           distance   threshold   metric
monthly_spend     0.47       0.30        jensen_shannon_divergence   ALERT
plan_type         0.04       0.30        l_infinity                  ok
country           0.36       0.30        l_infinity                  ALERT

What to look at: Two features exceed their thresholds against the training baseline, so this is skew. A jump right after a release suggests a serving pipeline bug (for example spend now in cents instead of dollars); a gradual rise suggests the population changed. Check before retraining.

6. Scenarios

Exam-style situations: how to diagnose each one, the likely cause and the fix.

7. Searchable reference

ItemMeaning

8. Flashcards (click to flip)

9. Common gotchas in one list

  1. Skew baseline is training data; drift baseline is past production.
  2. Concept drift needs labels; input monitoring can't see it.
  3. Retraining doesn't fix a serving bug.
  4. Sampled Shapley for trees; Integrated Gradients for differentiable models; XRAI for image regions.
  5. Aggregate metrics hide group harms: slice evaluation.
  6. Fairness criteria conflict; choose with policy input and document.
  7. Model Armor for prompt attacks and sensitive data; regex for simple fixed patterns.
  8. VPC Service Controls, not IAM alone, stop exfiltration.
  9. Least-privilege identities per agent tool.
  10. Monitor operations too: latency, errors, cost, quota.

10. Practice quiz (18 questions)

Score: 0 / 0
← Pipelines and MLOpsBack to all guides →