Data privacy and model risk for GenAI in a bank
Trace where prompts and completions go on Amazon Bedrock, apply UK GDPR thinking to GenAI, and build a model inventory with risk tiers, validation, logging and monitoring that a bank's model-risk function can accept.
Assumes: .NET 10 LTS · AWS SDK for .NET v4 · AWS CLI v2 · CDK v2 (Amazon.CDK.Lib 2.277.0) · Terraform AWS provider v6 · Amazon Bedrock · UK GDPR as amended by the Data (Use and Access) Act 2025 · Region us-east-1. Verified against official sources on 2026-11-18.
Read this first
This lesson explains data-protection and model-risk concepts so engineers can design sensibly and ask the right questions. It is not legal advice and it does not make any system compliant. Lawful basis, DPIAs, international transfers, retention periods, regulatory classification (for example under the EU AI Act) and model-risk sign-off belong to Harbourline's DPO, legal, compliance and model-risk teams. Items marked ⚠ VERIFY must be confirmed against the primary source before you rely on them.
Learning objectives
By the end of this lesson you can:
- Trace a prompt from your .NET code to the model and back, and say what AWS documents about storage, access, retention, encryption and Regional routing on Amazon Bedrock.
- Explain the Bedrock data retention modes and why some models need
aws_review. - Choose between a single Region, a geographic cross-Region inference profile and a global profile, and enforce the choice with an SCP.
- Apply UK GDPR principles to GenAI: lawful basis, minimisation, accuracy, transparency, automated decisions, DPIAs and erasure in logs, memory and vector stores.
- Build a model inventory with risk tiers and automated rule checks in C#, and write metadata-only audit records.
- Describe model validation and ongoing monitoring for foundation-model use cases, and name the AWS tools that remain available after the 2026-07-30 closures.
Prerequisites
- Module 16 overview, Bedrock basics and Calling Bedrock from C#.
- Knowledge Bases and RAG, because knowledge-base documents and vector indexes are personal-data stores too.
- UK GDPR and data residency: the controller and processor split, residency versus sovereignty, restricted transfers and crypto-shredding. This lesson assumes it and applies it to GenAI.
- KMS envelope encryption and CloudTrail for banks.
- Agents on AWS, for the idea that agent memory is a personal-data store.
- Tools: .NET 10 SDK, Docker, AWS CLI v2 with
learn-sandbox(only for the optional logging exercise).
Why this matters in banking
Three questions arrive in the first model-risk review of any GenAI project, usually in this order:
- "Where does our data go?" A prompt that contains an account number or a complaint narrative is personal data. Who processes it, where, for how long, and can the vendor read it?
- "How do we know it works, and keep working?" The model is a third-party component that its provider updates or retires on its own schedule. A prompt that behaved well in March may behave differently after a model version change.
- "Who is accountable and where is the evidence?" If the assistant mis-states a fee to a customer, you must reconstruct which model, which prompt template, which source documents and which reviewer were involved.
Projects that cannot answer these in a page each stall at the risk committee. This lesson gives you the answers and the artefacts.
The idea in plain language
Data privacy asks: what personal or confidential data enters the system, where it travels and rests, who can see it, and how long it lives. Model risk asks: what harm can come from the model being wrong, biased, unavailable or changed, and what controls keep that harm within the bank's appetite.
GenAI adds three twists to older model-risk practice:
- The model is not yours. You consume a foundation model from a provider through Bedrock. You cannot inspect its weights or training data, so your assurance comes from testing the behaviour on your own use case, monitoring in production, and contract and vendor due diligence.
- Outputs are open-ended text. A credit-scoring model returns a number you can back-test. A chatbot returns sentences that can be fluent and wrong (hallucination).
- Your prompt is the model. Changing the system prompt, the retrieval sources or the guardrail changes the system's behaviour, so each is a controlled change, not a casual edit.
Analogy: treat a foundation model like an outsourced analyst. You do not audit their brain; you check their references, test their work on your cases, supervise them, log what they did, and have a plan for when they leave or change.
What problem the AWS service solves
What AWS documents about Bedrock and your data
Facts below were checked against the Bedrock user guide on 2026-11-18. Re-check before you quote them in a risk paper, because they change.
| Topic | What AWS states | What you still own |
|---|---|---|
| Model provider access | Each Region has a Model Deployment Account per provider, owned and operated by the Bedrock service team. Providers have no access to those accounts, to Bedrock logs, or to customer prompts and completions | Your DPO still needs the contractual terms and the sub-processor list |
| Content sharing | Bedrock does not share your content with model providers under any current retention mode | Confirm in the current AWS Service Terms |
| Retention | Controlled by a data retention mode per Region (see below) | Choose and enforce the mode |
| Encryption | Data encrypted in transit (TLS 1.2 required, 1.3 recommended); encryption at rest options per feature, including customer managed KMS keys for several resources | Choose keys; manage key policies |
| Network | VPC endpoints through AWS PrivateLink for Bedrock APIs | Create endpoints and endpoint policies |
| Logging | Model invocation logging is disabled by default. When enabled it writes full request and response bodies to S3 and/or CloudWatch Logs in the same account and Region | Your logs may now contain personal data: classify, encrypt, restrict and expire them |
| Abuse detection | Data may be processed for abuse detection; see the Bedrock abuse-detection page | Read it for each model you use |
| Cross-Region inference | Requests can be routed to other Regions via inference profiles; CloudTrail logs them in the source Region with additionalEventData.inferenceRegion showing where processing occurred | Pick geographic or global; allow the destination Regions in your SCPs |
Data retention modes
Bedrock lets you set, per Region and at account level, how prompts and outputs are retained:
| Mode | Meaning |
|---|---|
none | Zero data retention: nothing written to durable storage by AWS and nothing shared with the model provider |
default | The model's own policy applies (no change from before). AWS may retain data for safety and abuse prevention; the provider does not receive it |
aws_review | Inputs and outputs may be retained and reviewed by AWS (never shared with the provider), required for models whose provider demands human review as a condition of access |
provider_data_share | Legacy. Does not cause sharing today; behaves like aws_review |
inherit | No opinion at this scope; defer to a broader scope (the default for new accounts) |
Key points to remember:
- Each model declares which modes it allows. Some models (as documented on 2026-11-18, the Claude Fable 5, 5.1 and 5.2 models) require
aws_review: prompts and completions are kept within the AWS boundary for up to 30 days and may be reviewed by AWS. If your effective mode isnoneordefault, those models appear unavailable and calls fail with aValidationException. - Most other models do not require review, and setting
aws_reviewdoes not make them retain data. - If cross-Region inference is on, retained data is stored in the destination Regions.
- Zero data retention for models that require retention is a per-account, per-model eligibility decision made with AWS and the model provider ⚠ VERIFY current eligibility conditions with your AWS account team.
- Control is enforceable with IAM and SCPs through the condition keys
bedrock:DataRetentionMode(control plane) andbedrock-mantle:DataRetentionMode(the OpenAI-compatible endpoint). There was no console toggle at launch; use the API or SDK ⚠ VERIFY current console support.
Banking reading: pick the model after you know your data class and retention rules, not before. A model that needs aws_review is a different conversation with the DPO from a model that allows none.
Where the model runs: Region, geographic and global profiles
| Option | Processing location | SCP implication | Fit for bank data |
|---|---|---|---|
| Single Region (in-Region model ID) | The Region you call | Allow that Region | Strongest residency story; may limit throughput and model choice |
| Geographic inference profile (for example US or EU prefix) | Regions within one geography | Allow every destination Region listed in the profile | Reasonable when the DPO accepts the geography |
| Global inference profile | Any supported commercial Region worldwide; roughly 10% cheaper according to the AWS comparison table | SCPs must allow aws:RequestedRegion of unspecified | Generally not suitable for personal data of UK or EU customers without explicit approval |
For a UK bank the usual sequence is: confirm whether the model is available in eu-west-2 (London) or via an EU or UK-appropriate geographic profile ⚠ VERIFY current availability for each model, then decide with the DPO. Module 5's UK GDPR and data residency lesson explains restricted transfers and the UK data bridge; do not repeat its conclusions here without re-checking them.
UK GDPR applied to GenAI
| Principle or right | What it means for a GenAI system |
|---|---|
| Lawful basis and purpose limitation | Each use case has a recorded lawful basis. "We have the data and the model can use it" is not a purpose |
| Data minimisation | Send the model only the fields it needs. Redact or tokenise account numbers, names and addresses before prompting where the task allows (Bedrock Guardrails can mask PII; do it in your own code too) |
| Accuracy | Hallucinated statements about a person are inaccurate personal data. Ground answers in retrieved sources and require citations; keep humans in the loop for anything about a customer |
| Transparency | Tell people when they interact with AI and how decisions are made. A chatbot must not pretend to be a person |
| Automated decision-making (UK GDPR Article 22, as amended by the Data (Use and Access) Act 2025) | Significant decisions about people made solely by automated means are restricted, with safeguards such as human involvement and the right to contest. ⚠ VERIFY the current wording and commencement with legal counsel; treat "meaningful human review" as the default design |
| Storage limitation and erasure | Prompts, completions, invocation logs, agent memory, vector indexes and knowledge-base documents all hold personal data if the content does. Each needs retention and deletion |
| Security | Encryption, least privilege, logging, tested backups (Module 5) |
| Accountability and DPIA | A Data Protection Impact Assessment is expected for high-risk processing; new technology on customer data usually qualifies. The DPO decides |
| Rights requests | You must be able to find a person's data across all those stores. Design lookup keys (a hashed user ID in logs, for example) before launch |
Model risk: the regulators' frame
Banks already have model-risk management. For a UK bank the main reference is the PRA's supervisory statement SS1/23, Model risk management principles for banks, effective 17 May 2024. As described in secondary sources it applies formally to firms with internal-model permissions for regulatory capital and is widely used as the benchmark for others; the Bank of England has said AI and machine-learning models fall within model risk. ⚠ VERIFY the scope paragraph and the current version on the Bank of England site. In the US the equivalent heritage is the Federal Reserve and OCC guidance SR 11-7.
The five habits that every framework shares, translated to GenAI:
| Habit | GenAI meaning |
|---|---|
| Inventory | Every GenAI use case, model ID, prompt template, data source and owner is recorded |
| Tiering | Risk-based: an internal drafting aid gets lighter treatment than a customer-facing answer |
| Independent validation | Someone not on the build team tests behaviour on representative and adversarial cases before launch |
| Ongoing monitoring | Quality, safety and drift checks in production, with thresholds and escalation |
| Change management | Model version, prompt, guardrail and source-document changes go through controlled release |
EU AI Act pointer (for the EU subsidiary). Annex III lists AI used to assess the creditworthiness of natural persons as high-risk. The Digital Omnibus agreement on the AI Act postponed the stand-alone high-risk obligations to 2 December 2027 (political agreement reported May 2026; publication in the Official Journal reported July 2026). ⚠ VERIFY the final text and dates with legal counsel. The point for engineers: a GenAI feature that influences credit decisions leaves the "productivity tool" category entirely.
Tools that remain, and those that closed
Several AWS tools that appear in AIF-C01 and AIP-C01 study material are closed to new customers since 2026-07-30: SageMaker AI Clarify and Model Monitor (and Ground Truth and A2I). Learn their names for exams, but do not build on them. Alternatives verified 2026-11-18:
| Need | Use instead |
|---|---|
| Bias and explainability metrics for classic ML | SHAP with pandas and scikit-learn bias metrics; SageMaker AI MLflow |
| Evaluating foundation-model outputs | Amazon Bedrock Evaluations and the open-source fmeval library |
| Runtime content safety | Bedrock Guardrails |
| Monitoring drift and quality in production | CloudWatch metrics and alarms on invocation logs; open-source monitoring solutions (for example MLflow with Evidently AI) from AWS samples |
| Human review queue | Build your own (see lesson 10) |
Microsoft / Azure comparison
| You know (Microsoft/Azure) | AWS equivalent | What's different |
|---|---|---|
| Azure OpenAI abuse monitoring and data-storage opt-outs | Bedrock data retention modes and abuse detection | Mode is set per Region and enforceable with IAM and SCP condition keys |
| Azure OpenAI diagnostic logging to Log Analytics | Bedrock model invocation logging to S3 or CloudWatch Logs | Disabled by default; same account and Region only; bodies larger than 100 KB go to S3 |
| Azure data zones and global deployments | Geographic versus global inference profiles | Global profiles route worldwide; SCPs must allow unspecified |
| Microsoft Purview and DSPM | Macie, your own data inventory, CloudWatch Logs data protection | No single managed DSAR product |
| Azure AI Foundry evaluations | Bedrock Evaluations and fmeval | Different metrics and job model |
| Azure Policy for allowed models and locations | SCPs with bedrock:InvokeModel resource ARNs and aws:RequestedRegion | Enforced at API call time |
| Model cards and registries | Your own model inventory (this lesson); SageMaker Model Registry for self-built models | For foundation models the inventory is mostly use-case records |
Architecture
Security-boundary view. Personal data crosses four boundaries: from the user into your app (authentication), from your app to Bedrock (minimisation, IAM, VPC endpoint, retention mode, Region), from Bedrock to your log stores (encryption, access, expiry), and from your stores to people who investigate (least privilege, audit of access). Governance controls (inventory, validation, SCPs) sit around the flow and are checked before and after release.
Step-by-step implementation
Step one: draw the data flow and classify it
List every field that can reach a prompt, every store the system writes (logs, memory, vector index, cache), and the data class of each. This single diagram answers most of the DPO's first questions.
Step two: choose Region, profile and model against your data class
Use the table above. Record the decision, the retention mode and the reasons in the inventory entry.
Step three: minimise before you prompt
Remove fields the task does not need, tokenise identifiers (for example replace an account number with a short-lived token), and keep a mapping on your side if you must re-insert values after the model responds.
Step four: decide whether to log bodies, and protect the logs
Invocation logging gives you evidence and a new store of personal data. Decide with the DPO: log bodies in a short-retention, KMS-encrypted bucket for validated pilots; log metadata only for production use cases with sensitive content (lesson 9 shows what to detect in them).
Step five: register the use case and run the rule checks
Create the inventory entry, run the rules in CI, attach the DPIA and validation references, and schedule the next review.
Step six: monitor and review
Track token use, guardrail interventions, refusal and error rates, human-reviewer overrides and complaint volumes. Re-validate when the model ID, prompt, retrieval sources or guardrail change.
AWS Console instructions
Console labels change, so ⚠ VERIFY them:
- Console → Amazon Bedrock → Settings → Model invocation logging. Choose the data types (text, image, embedding, video), the destination (S3, CloudWatch Logs or both) and the bucket or log group. Only destinations in the same account and Region work.
- Console → Amazon Bedrock → Model catalog to see which models are available in
us-east-1or your chosen Region, and any availability or retention notes. - Console → CloudTrail → Event history, filter by event source
bedrock.amazonaws.com, and open an event to readadditionalEventData.inferenceRegionfor cross-Region calls. - Console → AWS Organizations → Policies → Service control policies to attach Region, model or retention-mode guard rails.
AWS CLI
# Read the current model invocation logging configuration (read-only)
aws bedrock get-model-invocation-logging-configuration \
--region us-east-1 --profile learn-sandbox
# Enable invocation logging to the S3 bucket created by the CDK stack below.
# Replace BUCKET with the stack output LogBucketName.
aws bedrock put-model-invocation-logging-configuration \
--region us-east-1 --profile learn-sandbox \
--logging-config '{
"s3Config": { "bucketName": "BUCKET", "keyPrefix": "bedrock" },
"textDataDeliveryEnabled": true,
"imageDataDeliveryEnabled": false,
"embeddingDataDeliveryEnabled": false,
"videoDataDeliveryEnabled": false
}'
# Turn logging off again (the logs already written stay in S3 until they expire)
aws bedrock delete-model-invocation-logging-configuration \
--region us-east-1 --profile learn-sandbox
# Read the account data retention mode for this Region (control plane).
# ⚠ VERIFY: the CLI subcommand name; the documented REST call is GET /data-retention on the bedrock endpoint.
aws bedrock get-account-data-retention --region us-east-1 --profile learn-sandboxInfrastructure as Code
CloudFormation has no resource for the logging configuration itself (checked 2026-11-18), so the pattern is: CDK builds the encrypted bucket and key with the correct service-principal policies, and the configuration is switched on with the CLI or with Terraform's aws_bedrock_model_invocation_logging_configuration.
using Amazon.CDK;
using Amazon.CDK.AWS.IAM;
using Amazon.CDK.AWS.KMS;
using Amazon.CDK.AWS.S3;
using Constructs;
public class BedrockLoggingStack : Stack
{
public BedrockLoggingStack(Construct scope, string id, IStackProps props) : base(scope, id, props)
{
var bedrock = new ServicePrincipal("bedrock.amazonaws.com");
var sourceConditions = new Dictionary<string, object>
{
["StringEquals"] = new Dictionary<string, object> { ["aws:SourceAccount"] = this.Account },
["ArnLike"] = new Dictionary<string, object> { ["aws:SourceArn"] = $"arn:aws:bedrock:{this.Region}:{this.Account}:*" }
};
var key = new Key(this, "LogKey", new KeyProps
{
Alias = "alias/hl-m16-bedrock-invocation-logs",
EnableKeyRotation = true,
RemovalPolicy = RemovalPolicy.DESTROY // lab only
});
key.AddToResourcePolicy(new PolicyStatement(new PolicyStatementProps
{
Sid = "AllowBedrockToEncryptLogs",
Principals = [bedrock],
Actions = ["kms:GenerateDataKey"],
Resources = ["*"],
Conditions = sourceConditions
}));
var bucket = new Bucket(this, "LogBucket", new BucketProps
{
Encryption = BucketEncryption.KMS,
EncryptionKey = key,
BlockPublicAccess = BlockPublicAccess.BLOCK_ALL,
EnforceSSL = true,
ObjectOwnership = ObjectOwnership.BUCKET_OWNER_ENFORCED, // ACLs disabled, as Bedrock requires
Versioned = true,
LifecycleRules =
[
new LifecycleRule { Id = "expire-after-90-days", Expiration = Duration.Days(90) }
],
RemovalPolicy = RemovalPolicy.DESTROY, // lab only
AutoDeleteObjects = true // lab only
});
bucket.AddToResourcePolicy(new PolicyStatement(new PolicyStatementProps
{
Sid = "AmazonBedrockLogsWrite",
Principals = [bedrock],
Actions = ["s3:PutObject"],
Resources = [bucket.ArnForObjects($"bedrock/AWSLogs/{this.Account}/BedrockModelInvocationLogs/*")],
Conditions = sourceConditions
}));
// Mandatory tags. Inside a Stack write Amazon.CDK.Tags, not Tags.
Amazon.CDK.Tags.Of(this).Add("Project", "cea-lab");
Amazon.CDK.Tags.Of(this).Add("Lab", "m16-privacy");
Amazon.CDK.Tags.Of(this).Add("Environment", "learn");
new CfnOutput(this, "LogBucketName", new CfnOutputProps { Value = bucket.BucketName });
}
}This stack compiled against Amazon.CDK.Lib 2.277.0 on 2026-11-18.
⚠ Learning shortcut — not for production
RemovalPolicy.DESTROY and AutoDeleteObjects make teardown easy, and they are exactly wrong for audit logs. In production the log bucket lives in a dedicated logging account, uses Object Lock and RETAIN, is readable only by a small audit role, and the 90-day expiry is whatever your retention schedule and DPO decide, not a number copied from a tutorial. Also confirm whether logging full bodies is justified at all for the data class.
Complete code
The inventory rules below compiled and ran in Docker with the .NET 10 SDK on 2026-11-18. They need no NuGet packages.
using System.Security.Cryptography;
using System.Text;
namespace Harbourline.ModelRisk;
public enum DataClass { Public = 0, Internal = 1, Confidential = 2, Restricted = 3 }
public enum OutputUse { InternalDraft, StaffDecisionSupport, CustomerFacing, AutomatedDecision }
public enum RiskTier { Low = 0, Medium = 1, High = 2 }
/// <summary>One row of the GenAI model inventory. Facts about a use case, not about the model alone.</summary>
public sealed record ModelInventoryEntry(
string UseCaseId,
string Name,
string Owner,
string ModelId, // pinned ID or inference-profile ID, never "latest"
string Region,
bool GlobalInferenceProfile, // true = requests may be processed in any supported Region
DataClass HighestDataClass,
OutputUse OutputUse,
bool HumanReview,
RiskTier DeclaredTier,
bool InvocationLoggingEnabled,
string? DpiaReference,
string? ValidationReference,
DateOnly? LastValidated,
DateOnly NextReview);
public sealed record Finding(string Rule, string Message);
public static class InventoryRules
{
/// <summary>The lowest tier the facts allow. A declared tier below this is a finding.</summary>
public static RiskTier MinimumTier(ModelInventoryEntry e)
{
if (e.OutputUse is OutputUse.CustomerFacing or OutputUse.AutomatedDecision) return RiskTier.High;
if (e.HighestDataClass >= DataClass.Confidential) return RiskTier.High;
if (e.OutputUse == OutputUse.StaffDecisionSupport || e.HighestDataClass == DataClass.Internal)
return RiskTier.Medium;
return RiskTier.Low;
}
public static IReadOnlyList<Finding> Validate(ModelInventoryEntry e, DateOnly today)
{
var f = new List<Finding>();
var min = MinimumTier(e);
if (string.IsNullOrWhiteSpace(e.ModelId) || e.ModelId.Contains("latest", StringComparison.OrdinalIgnoreCase))
f.Add(new("R1", "Model ID must be pinned. Floating aliases change behaviour without a validation."));
if (e.DeclaredTier < min)
f.Add(new("R2", $"Declared tier {e.DeclaredTier} is below the minimum {min} for these facts."));
if (e.HighestDataClass >= DataClass.Confidential && string.IsNullOrWhiteSpace(e.DpiaReference))
f.Add(new("R3", "Confidential or restricted data requires a DPIA reference."));
if (e.HighestDataClass == DataClass.Restricted)
f.Add(new("R4", "Restricted data (for example customer personal data) must not be sent to a model without explicit risk and DPO approval."));
if (min == RiskTier.High && string.IsNullOrWhiteSpace(e.ValidationReference))
f.Add(new("R5", "High-tier use requires an independent validation reference."));
if (e.OutputUse == OutputUse.AutomatedDecision && !e.HumanReview)
f.Add(new("R6", "Automated decisions about people need meaningful human involvement. Escalate to legal and the DPO."));
if (e.GlobalInferenceProfile && e.HighestDataClass >= DataClass.Internal)
f.Add(new("R7", "A global inference profile may process requests in any supported Region. Use a geographic profile or a single Region."));
if (min >= RiskTier.Medium && !e.InvocationLoggingEnabled)
f.Add(new("R8", "Medium and high tiers need invocation logging (or equivalent) so decisions can be reconstructed."));
if (min >= RiskTier.Medium)
{
var maxAge = min == RiskTier.High ? 365 : 730;
if (e.LastValidated is null || today.DayNumber - e.LastValidated.Value.DayNumber > maxAge)
f.Add(new("R9", $"Validation is missing or older than {maxAge} days."));
}
if (e.NextReview < today)
f.Add(new("R10", "Scheduled review date has passed."));
return f;
}
}
/// <summary>Metadata-only audit record: enough to reconstruct what happened, without storing the prompt text.</summary>
public sealed record InferenceAuditRecord(
string RequestId,
DateTimeOffset At,
string UserIdHash,
string UseCaseId,
string ModelId,
int InputTokens,
int OutputTokens,
string PromptHmac,
string? GuardrailAction)
{
public static InferenceAuditRecord Create(
byte[] hmacKey, string requestId, string userId, string useCaseId, string modelId,
string prompt, int inputTokens, int outputTokens, string? guardrailAction, DateTimeOffset? at = null)
{
using var hmac = new HMACSHA256(hmacKey);
string H(string s) => Convert.ToHexString(hmac.ComputeHash(Encoding.UTF8.GetBytes(s)));
return new InferenceAuditRecord(requestId, at ?? DateTimeOffset.UtcNow, H("user:" + userId),
useCaseId, modelId, inputTokens, outputTokens, H("prompt:" + prompt), guardrailAction);
}
}A driver with one acceptable and one deliberately bad entry:
using Harbourline.ModelRisk;
var today = new DateOnly(2026, 11, 18);
var good = new ModelInventoryEntry(
"UC-001", "Policy Q&A (internal)", "ops-knowledge", "anthropic.claude-sonnet-5-5", "us-east-1",
GlobalInferenceProfile: false, DataClass.Internal, OutputUse.StaffDecisionSupport, HumanReview: true,
RiskTier.Medium, InvocationLoggingEnabled: true, DpiaReference: null, ValidationReference: "VAL-2026-014",
LastValidated: new DateOnly(2026, 9, 1), NextReview: new DateOnly(2027, 3, 1));
var bad = good with
{
UseCaseId = "UC-002", Name = "Complaint auto-reply",
ModelId = "anthropic.claude-sonnet-latest", GlobalInferenceProfile = true,
HighestDataClass = DataClass.Restricted, OutputUse = OutputUse.CustomerFacing,
DeclaredTier = RiskTier.Low, InvocationLoggingEnabled = false, ValidationReference = null,
LastValidated = null, NextReview = new DateOnly(2026, 6, 1)
};
foreach (var e in new[] { good, bad })
{
var findings = InventoryRules.Validate(e, today);
Console.WriteLine($"{e.UseCaseId} {e.Name}: minimum tier {InventoryRules.MinimumTier(e)}, {findings.Count} finding(s)");
foreach (var f in findings) Console.WriteLine($" {f.Rule}: {f.Message}");
}
var key = new byte[32]; // lab only: load the HMAC key from Secrets Manager or KMS in real code
var rec = InferenceAuditRecord.Create(key, "req-1", "alice", "UC-001", good.ModelId,
"What is the overdraft fee policy?", 25, 120, null, new DateTimeOffset(2026, 11, 18, 9, 0, 0, TimeSpan.Zero));
Console.WriteLine($"audit: {rec.RequestId} user={rec.UserIdHash[..8]}... prompt={rec.PromptHmac[..8]}... tokens={rec.InputTokens}/{rec.OutputTokens}");Verified output:
UC-001 Policy Q&A (internal): minimum tier Medium, 0 finding(s)
UC-002 Complaint auto-reply: minimum tier High, 9 finding(s)
R1: Model ID must be pinned. Floating aliases change behaviour without a validation.
R2: Declared tier Low is below the minimum High for these facts.
R3: Confidential or restricted data requires a DPIA reference.
R4: Restricted data (for example customer personal data) must not be sent to a model without explicit risk and DPO approval.
R5: High-tier use requires an independent validation reference.
R7: A global inference profile may process requests in any supported Region. Use a geographic profile or a single Region.
R8: Medium and high tiers need invocation logging (or equivalent) so decisions can be reconstructed.
R9: Validation is missing or older than 365 days.
R10: Scheduled review date has passed.
audit: req-1 user=17A625E9... prompt=D4F29E01... tokens=25/120To attach the audit record to a real Bedrock call, put non-sensitive tags in the Converse request's RequestMetadata (for example the use-case ID), which Bedrock copies into invocation-log entries for later filtering ⚠ VERIFY the exact ConverseRequest.RequestMetadata property in your SDK version. Never put personal data in metadata, tags or names.
Code explained line by line
- The three enums encode vocabulary the risk team already uses.
DataClassis ordered so comparisons such as>= Confidentialwork. ModelInventoryEntryis a record of facts about a use case. The model ID is a string so it can be an inference-profile ID.GlobalInferenceProfilecaptures the Regional-routing decision explicitly.MinimumTiercomputes the lowest acceptable tier from the facts. Customer-facing or automated output, or confidential data, forces High. A declared tier below it is finding R2, which stops teams from "self-certifying" Low.Validatereturns findings instead of throwing, so CI can print all problems at once and the risk team can read them.- R1 rejects blank or
latestIDs. Floating aliases change behaviour without a validation event. - R4 is deliberately blunt: restricted data in a prompt is a finding every time until a human approves it with a DPO sign-off, so the exception is visible.
- R7 flags global inference profiles for anything above public data, reflecting the routing rules above.
- R9 uses a validation age limit (365 days for High, 730 for Medium). The numbers are illustrative; your policy sets them.
InferenceAuditRecord.Createstores HMAC-SHA256 of the user ID and the prompt, not the text. The HMAC proves later that a given prompt was the one sent (recompute and compare) without keeping the prompt in the audit store. Use a secret key from a managed store, and note that hashing is pseudonymisation, not anonymisation: it is still personal data.- The audit record keeps counts, the model ID and the guardrail action: enough to reconstruct the event and charge costs.
Security considerations
- Logs are a data store. When invocation logging is on, full prompts and completions land in S3 or CloudWatch. Encrypt with a customer managed key, block public access, restrict read access to an audit role, set retention, and include the bucket in your erasure and DSAR procedures.
- Least privilege for invocation. Allow
bedrock:InvokeModelon specific model or inference-profile ARNs only; deny the rest by SCP. Remember geographic profiles need all destination-Region foundation-model ARNs in the policy ⚠ VERIFY the exact resource ARNs for the profile you use. - VPC endpoints. Use the Bedrock runtime interface endpoint with an endpoint policy for workloads in private subnets so traffic does not need a NAT or the public internet.
- Do not put personal data in free-text names or tags (the Bedrock data-protection page says tags and name fields may be used in billing and diagnostic logs).
- Memory, vector stores and caches hold derived personal data. Give each a retention rule and a deletion path keyed to the data subject.
- Model lifecycle. Providers retire model versions. Pin IDs, subscribe to deprecation notices ⚠ VERIFY where Bedrock publishes them, and treat a model change like any other material change: re-validate before switching.
- Never claim compliance. Say "the design supports the bank's DPIA and model-risk process", not "this is GDPR compliant".
⚠ Learning shortcut — not for production
The HMAC key in the sample is 32 zero bytes, the inventory is an in-memory record, and the rules are checked on a console run. In production the key comes from AWS Secrets Manager or KMS and is rotated, the inventory lives in a governed system of record (for example a database with change history, owned by model risk), the rules run in CI for every change to a prompt template or model ID, and findings block the release rather than printing a line.
Banking use case
Harbourline internal policy Q&A (inventory UC-001). Staff ask questions about fee policies. Data class Internal, no customer data in prompts, output is staff decision support with citations. Minimum tier Medium. Region us-east-1 for the lab; production would use the Region and profile the DPO approves. Invocation logging on with 90-day expiry for the pilot. Validation: a set of 200 fictional questions with known answers plus 50 adversarial prompts, scored by two reviewers who did not build it. Monitoring: weekly sample of 25 answers, guardrail intervention rate, thumbs-down rate, and a trigger to re-validate if the model ID, prompt or document set changes. The recommendation to the risk committee is go for a staff pilot, with a no-go for any customer-facing version until it has its own tier-High assessment.
Common mistakes
- Treating "Bedrock does not train on my data" as the whole answer. Retention, logging, Region routing, memory and vector stores are separate questions.
- Enabling invocation logging and forgetting it is now a personal-data store.
- Choosing a global inference profile for cost without checking residency and the SCP consequences.
- Letting model IDs float. A silent model change is an unvalidated change.
- Self-assigning the lowest tier to avoid review. Compute the minimum tier from the facts.
- Hashing as anonymisation. A hashed user ID can still be linked back; it is pseudonymised.
- Validating once. Prompts, sources, models and guardrails drift. Schedule re-validation and trigger it on change.
- Building on SageMaker Clarify or Model Monitor after the 2026-07-30 closure.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
ValidationException when invoking a model | The model requires a retention mode (for example aws_review) that the account's effective mode does not satisfy | Check the model's allowed modes and the account setting with your AWS team and DPO; choose another model if review is not acceptable |
| Model shows as unavailable in the catalog | Region availability or retention-mode mismatch | Check the Region and the data-retention setting |
| Logging configuration fails with access denied | Bucket policy missing the Bedrock service principal, ACLs enabled, or KMS key policy lacks kms:GenerateDataKey for Bedrock | Use the policies shown above; set object ownership to bucket owner enforced |
| No log objects appear | Logging disabled, wrong Region, or calls made through a different endpoint | Logging is per Region and covers bedrock-runtime calls; confirm with get-model-invocation-logging-configuration |
| SCP blocks a cross-Region profile | Destination Region not allowed | Allow all Regions in the profile (or unspecified for global) or pick a single-Region model |
| Large prompts missing from logs | Bodies over 100 KB are stored as separate S3 objects | Provide an S3 location for large data delivery and look under the data prefix |
| Inventory check passes locally, fails in CI | Different today date or stale fixture | Inject the date and keep fixtures in source control |
Cost and cleanup
Costs. The inventory code is free. The optional logging exercise costs a few cents for an S3 bucket, a KMS key (USD 1 per month if left for a month) and a handful of Bedrock calls ⚠ VERIFY current prices. Deploy-and-destroy within the hour.
Teardown.
# 1. Turn off invocation logging first, so nothing writes while you delete
aws bedrock delete-model-invocation-logging-configuration \
--region us-east-1 --profile learn-sandbox
# 2. Destroy the infrastructure (CDK path)
cdk destroy hl-m16-bedrock-logging --profile learn-sandbox
# or (Terraform path)
terraform destroy
# 3. Confirm nothing tagged for the lab remains
aws resourcegroupstaggingapi get-resources \
--tag-filters Key=Project,Values=cea-lab \
--region us-east-1 --profile learn-sandbox \
--query "ResourceTagMappingList[].ResourceARN"A KMS key is scheduled for deletion with a waiting period (7 to 30 days), so it may still appear briefly and bill until deletion completes.
Exercises
- 🟢 Guided: run the sample, then add a third inventory entry that passes with zero findings at tier High (customer-facing assistant with human review). List every field you had to fill in.
- 🟡 Challenge: add rule R11: a use case whose
HighestDataClassisInternalor above must haveRegionequal to an approved Region from a configurable list. Add rule R12: anAutomatedDecisionuse case must always produce a finding that says "legal review required" even if everything else passes. - 🔴 Live problem: a vendor offers a GenAI "customer sentiment" service for complaint emails, hosted outside the UK, which stores the emails for 30 days "to improve the service". Write the model-risk and privacy questions you would send back, and say what evidence would let you approve a pilot.
Assignment
Write a one-page GenAI data-flow and retention note for the policy Q&A assistant: a data-flow diagram, a table of every store with its data class, retention period and deletion method, the Region and inference-profile decision, the retention-mode setting, and the inventory entry with rule results. Attach the verified output of the rules.
Solutions
A passing tier-High entry needs: pinned model ID, Region set, GlobalInferenceProfile = false, OutputUse.CustomerFacing, HumanReview = true, DeclaredTier = High, InvocationLoggingEnabled = true, a DPIA reference if data class is Confidential or above, a validation reference, a LastValidated date within 365 days and a future NextReview. Data class must be below Restricted or the entry still raises R4, which is deliberate: restricted data requires an explicit human decision outside the rule engine. The exercise shows how many artefacts a customer-facing use case needs compared with an internal one.
Add a HashSet<string> approvedRegions parameter to Validate (or a small options record) and test e.HighestDataClass >= DataClass.Internal && !approvedRegions.Contains(e.Region) for R11. For R12, add if (e.OutputUse == OutputUse.AutomatedDecision) f.Add(new("R12", "Legal review required: automated decisions about people.")) outside any conditional. R12 is a permanent finding on purpose: the engine cannot decide legality, it can only force the conversation. Mention in the code comment who clears it (the DPO or legal) and where the clearance is recorded.
Questions: What personal data is in the emails and what is the lawful basis for disclosing it to a vendor? Is the vendor a processor, and does the contract include UK GDPR processor terms and audit rights? Where is data stored and processed, who are the sub-processors, and what transfer mechanism applies? Why 30 days, is it used to train or improve models (and can this be switched off), how are deletion requests honoured? What security certifications and breach notice times apply? How accurate is the sentiment output, on what test, and with what bias analysis? Evidence for a pilot: signed DPA, DPIA approved by the DPO, a transfer risk assessment if outside the UK or without a data bridge, redaction of names and account numbers before sending, a time-limited pilot on a sample, and an exit plan. If the vendor refuses to disable training on bank data, the answer is no.
Knowledge check
Answer: none is zero data retention. A model that requires human review (allowed modes start at aws_review) is unavailable when the effective mode is none or default, and calls to it fail with a ValidationException.
Answer: No. It is disabled by default and, when enabled, logs full request and response data to S3 and/or CloudWatch Logs in the same account and Region. That makes the log destination a personal-data store the bank must protect.
Answer: The request may be processed in any supported commercial Region, so the SCP must allow aws:RequestedRegion of unspecified. Most banks with residency requirements prefer a single Region or a geographic profile.
Answer: Inventory, risk tiering, independent validation, ongoing monitoring and change management. For GenAI, prompts, sources and guardrails are inside the controlled change scope.
Answer: SageMaker AI Clarify and Model Monitor (closed to new customers since 2026-07-30). Use Bedrock Evaluations and fmeval for foundation models, SHAP and scikit-learn metrics for classic ML bias, CloudWatch for monitoring, and Bedrock Guardrails at runtime.
Interview questions
- Where does a prompt go when you call Bedrock, and who can see it? From your app over TLS to the Bedrock runtime endpoint in a chosen Region (or the destination Region of an inference profile), processed in an AWS-operated model deployment account the model provider cannot access. Retention depends on the mode and model; AWS may retain for abuse detection and, for some models, review. Your own logging adds another copy you control.
- How would you explain model risk for a foundation model you cannot inspect? Assurance shifts from inspecting the model to testing behaviour on your use case, monitoring in production, controlling changes and vendor due diligence.
- How do you handle a right-to-erasure request when prompts are logged? Identify all stores (logs, memory, vector index, caches), use data-subject-keyed identifiers so records can be found, delete or crypto-shred, and note any legal retention exceptions with the DPO. Prefer logging metadata over bodies to make this tractable.
- Why pin the model ID? A model change alters behaviour; pinning makes the change visible and gives you a validation checkpoint.
- What makes a GenAI use case high risk in a bank? Customer-facing output, influence on credit or eligibility decisions, restricted data in prompts, or autonomy over actions.
Certification practice
A bank wants an audit trail of every prompt and response sent to Amazon Bedrock for a pilot. Which approach provides it, and what must the bank also do?
A. It is on by default; no action is needed. B. Enable model invocation logging to an encrypted S3 bucket or CloudWatch Logs group, and treat the destination as a store of potentially personal data with access control and retention. C. Enable AWS Config; it records prompts. D. Ask the model provider to send the logs.
Answer: B. Invocation logging is off by default and writes bodies to your destination. Config records resource configuration, not prompts. Providers have no access to customer prompts on Bedrock.
A UK bank must ensure Bedrock inference for personal data stays within a defined geography. Which design is most appropriate?
A. A global cross-Region inference profile for the lowest cost.
B. An in-Region model ID, or a geographic inference profile whose destination Regions are all approved, with an SCP restricting aws:RequestedRegion accordingly.
C. A public internet endpoint and a firewall rule.
D. Disabling CloudTrail so no Regional data is recorded.
Answer: B. Global profiles can route to any supported commercial Region. CloudTrail should stay on and records the processing Region.
Bedrock invocation logs written to S3 contain customer complaints. Which combination best protects them?
A. SSE-S3 and a public-read ACL for the audit team. B. SSE-KMS with a customer managed key, S3 Block Public Access, a bucket policy limiting reads to an audit role, and a lifecycle expiry aligned with retention policy. C. Store them unencrypted for faster search. D. Email the logs to the DPO weekly.
Answer: B. It applies encryption, least privilege and storage limitation. A and C expose data; D creates uncontrolled copies.
Completion checklist
- I can explain Bedrock's retention modes and when a model requires
aws_review - I can choose between single-Region, geographic and global inference and defend the choice
- I ran the inventory rules and understand each finding
- I can list every store that may hold personal data in a GenAI system
- I ran the cleanup steps and confirmed nothing tagged
Project=cea-labis still billing
Key takeaways
- Bedrock model providers cannot access your prompts, but retention, logging, Region routing, memory and vector stores are your responsibility to design and justify.
- Retention is a mode per Region and a per-model requirement; some models need
aws_review. Enforce choices with IAM and SCP condition keys. - Global inference profiles trade residency for cost; geographic or single-Region is the default for bank personal data.
- Model risk for GenAI means inventory, tiering, independent validation, monitoring and change control, with prompts and sources inside the change scope.
- Compute the minimum risk tier from the facts, log metadata not bodies where possible, and never claim compliance.
Further reading
- Data protection in Amazon Bedrock — model deployment accounts, encryption, VPC and retention links
- Data retention in Amazon Bedrock — modes, per-model requirements and IAM condition keys
- Monitor model invocation — S3 and CloudWatch destinations and the log format
- Cross-Region inference — geographic and global profiles
- Terraform resource: aws_bedrock_model_invocation_logging_configuration — logging configuration in Terraform
Independent learning resource — not affiliated with, endorsed or sponsored by Amazon Web Services. AWS and related marks are trademarks of Amazon.com, Inc. or its affiliates. All banking data in examples is fictional. Sample architectures are for learning and are not automatically compliant with GDPR, PCI DSS or any banking regulation.
AI coding assistants: Amazon Q Developer to Kiro, and safe use on bank code
Understand the move from Amazon Q Developer to Kiro, compare AI coding assistants, and write a policy, a steering file and CI checks so developers can use them on proprietary bank code without leaking data or shipping unreviewed code.
Prompt injection and data leakage: defence in depth and red-teaming
Recognise direct and indirect prompt injection, system-prompt and data leakage, and unsafe output handling; build layered C# defences (untrusted-content wrapping, canary tokens, output scanning, Bedrock Guardrails) and red-team your own prototype with a repeatable test harness.