AI Safety, Security, and Governance · Topic 5 of 7

Privacy and PII Protection

Protect PII in FM apps with Comprehend and Macie detection, guardrail masking, anonymization, Bedrock data privacy features and S3 Lifecycle retention.

  • 5 min
In a nutshell
  • Comprehend detects PII in text you send; Macie discovers PII in S3 objects.
  • Guardrail sensitive information filters block or mask (ANONYMIZE) built-in PII types and custom regex, with separate input and output actions.
  • Masked text shows type labels such as {NAME}, which keeps context for the model.

What it is

Privacy protection keeps personally identifiable information (PII) out of places it should not be: prompts sent to a model, responses shown to users, logs, training data and knowledge bases. The goal is not to block every request with a name in it. It is to remove or disguise the sensitive parts while the model still has enough context to be useful.

Four AWS pieces do most of the work: Amazon Comprehend and Amazon Macie find PII, Amazon Bedrock Guardrails blocks or masks it in live traffic, and Amazon S3 Lifecycle deletes data when its retention period ends.

Raw documentsS3scanAmazon MaciePII findingsredactComprehendPII redaction jobingestKnowledge baseclean dataUser promptmask PIIGuardrailsensitive information filterinvokeFMmask PIIResponse

How it works

Choosing the PII detection service

ServiceWhere it looksWhat it returnsBest for
Amazon ComprehendText you send to the APIPII entity types with offsets and scores; redacted copies from batch jobsInline checks in Lambda, redacting documents before ingestion
Amazon MacieObjects stored in Amazon S3Findings about buckets and objects that hold sensitive dataDiscovering PII across data lakes and training data sets
Bedrock guardrail sensitive information filterLive prompts and model responsesBlock, mask or detect, per PII type and per directionProtecting FM interactions without custom code

Comprehend has DetectPiiEntities (where the PII is and what type) and ContainsPiiEntities (which types appear) for real-time checks. Redacting a set of documents uses an asynchronous PII detection job in redaction mode.

Macie runs sensitive data discovery jobs over S3 and publishes findings to Amazon EventBridge and AWS Security Hub. An EventBridge rule can trigger a Lambda function that quarantines the object or starts redaction before the data reaches a knowledge base.

Guardrail sensitive information filters

The filter covers built-in PII types (such as NAME, EMAIL, PHONE, ADDRESS, US_SOCIAL_SECURITY_NUMBER, CREDIT_DEBIT_CARD_NUMBER and AWS_SECRET_KEY) plus custom regex patterns for IDs like account or claim numbers.

ActionEffectUse it when
BlockWhole prompt or response replaced by your blocked messageThe data must never enter or leave, such as card numbers
Mask (ANONYMIZE)Value replaced with its type, such as {NAME}The rest of the text is still useful
Detect (NONE)Nothing changed; detection returnedMeasuring before you enforce

Input and output actions are set separately. A call center summarizer might mask names in the output but allow them in the input, because the model needs them to follow the conversation.

Watch out

Masking applies to what goes to the model and what comes back. Model invocation logs still hold the original input, and the guardrail trace returns the matched value. Protect logs with CloudWatch Logs data protection policies and limit who can read traces.

Masking, anonymization and keeping utility

TechniqueWhat it doesReversible
RedactionRemoves the valueNo
Masking with type labelsReplaces the value with {NAME}, {EMAIL}No
Tokenization (pseudonymization)Replaces the value with a token; a secure map links themYes, for authorized systems
GeneralizationReplaces exact values with ranges, such as age 30 to 39No

Type labels and consistent tokens keep the meaning of the text, so the model can still reason ("the customer emailed twice") without seeing who the customer is. If an authorized downstream step needs the real value, a Lambda function swaps the token back after the model responds, using a map kept in an encrypted store.

PromptJohn at [email protected]tokenizeLambdatoken map in DynamoDBmasked promptFMresponse with tokensLambdarestore for authorized user

Amazon Bedrock data privacy features

  • Amazon Bedrock does not use your prompts and completions to train AWS models and does not share them with model providers. Model providers have no access to the deployment accounts that run their models.
  • Data is encrypted in transit with TLS and at rest; use customer managed AWS KMS keys for custom models, knowledge bases, agents and guardrails when you need key control.
  • Model invocation logging is off until you enable it. Turn it on only with a clear purpose, and protect the log destination.
  • Fine tuning and continued pretraining create a private copy of the model in your account; your training data does not change the base model.

Retention with S3 Lifecycle

Privacy rules usually include how long you may keep data. S3 Lifecycle rules enforce this automatically.

  • Expiration actions delete objects such as prompt logs or uploaded documents after a set number of days.
  • Transition actions move older logs to cheaper storage classes until they expire.
  • Scope rules with prefixes or object tags, so chat transcripts expire on one schedule and audit logs on another.
  • If a regulation requires that records cannot be deleted early, combine retention with S3 Object Lock.

Common mistakes

Blocking every request that contains PII. The app becomes useless for normal support conversations. Mask where the text is still valuable and block only data that must never flow.

Scanning live prompts with Macie. Macie analyzes data stored in S3, not API traffic. Use guardrails or Comprehend for live text.

Forgetting the logs. PII masked in the response can still sit unmasked in invocation logs. Add log data protection and retention rules.

Cleaning data after ingestion. Once PII is embedded in a vector store it is hard to remove. Detect and redact before the knowledge base sync.

What to remember for the exam

  • Comprehend detects PII in text you send; Macie discovers PII in S3 objects.
  • Guardrail sensitive information filters block or mask (ANONYMIZE) built-in PII types and custom regex, with separate input and output actions.
  • Masked text shows type labels such as {NAME}, which keeps context for the model.
  • Tokenization is reversible for authorized systems; redaction and masking are not.
  • Bedrock does not use your prompts and completions for training or share them with model providers.
  • S3 Lifecycle expiration enforces retention; Object Lock prevents early deletion.

Check yourself

  • A data lake of support transcripts must be checked for PII before it feeds a knowledge base. Which service finds the affected objects?

    Amazon Macie, which runs sensitive data discovery on objects stored in Amazon S3.

  • A summarizer must hide customer names in its output but still produce readable summaries. Which guardrail action fits?

    The sensitive information filter with the mask (ANONYMIZE) action for NAME on the output, which replaces names with a type label.

  • How do you make sure chat logs are deleted after 30 days?

    Add an S3 Lifecycle rule with an expiration action for the log prefix or tag.

Topic 5 of 7 in AI Safety, Security, and Governance

Test yourself on AI Safety, Security, and Governance

The full AWS AIP-C01 question bank has 827 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by AWS. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.