Lesson 2 of 3 Data Security and Privacy for GenAI

Detecting and Protecting Personal Data in Generative AI Systems

This lesson covers the AWS services that detect personal data where it enters generative AI systems, prompts, documents, knowledge bases, fine-tuning data and logs, and where it leaves through responses.

Learning outcomes

After completing this lesson, you will be able to:

  • Detect PII in pipelines with Amazon Comprehend.
  • Find PII in S3 data with Amazon Macie.
  • Mask PII at inference time with guardrails.

Amazon Comprehend for text in pipelines

Personal information can enter a generative AI system in prompts, in documents used for retrieval or fine-tuning, and in model responses. Amazon Comprehend detects personally identifiable information (PII) in text. Its DetectPiiEntities operation returns each PII entity found, with its type, such as name, address or bank account number, and its position in the text, so that the application can mask or remove it. ContainsPiiEntities returns only the types present, which is enough to decide whether a text needs special handling.

Comprehend suits real-time checks of prompts and responses in a Lambda function, and pre-processing of documents before they are embedded into a knowledge base or used for fine-tuning; batch jobs can redact PII in large collections of documents stored in Amazon S3. For audio, Amazon Transcribe redacts PII in transcripts as it creates them.

The following diagram shows the three layers of protection.

Three layers of PII protection for a knowledge base. Amazon Macie discovers which buckets and objects contain personal data, Amazon Comprehend redacts it before ingestion, and a guardrail sensitive information filter masks anything that remains in responses.
The guardrail is the final safeguard, not the only one.

Amazon Macie for data at rest in S3

Data used for retrieval and fine-tuning usually sits in Amazon S3, often collected from many sources, and it may contain personal data that nobody expected. Amazon Macie discovers sensitive data in S3 using managed data identifiers, which recognise names, addresses, financial and health identifiers and credentials, and custom data identifiers that an organisation defines for its own formats, such as employee IDs. Automated sensitive data discovery samples objects across all buckets continuously, while targeted discovery jobs examine chosen buckets in full.

Macie also evaluates bucket security, such as public access and encryption settings. Its findings are sent to Amazon EventBridge, where rules can quarantine affected objects or alert their owners. Macie is therefore the right tool to confirm that buckets feeding a knowledge base or a fine-tuning job do not contain unexpected personal data before that data reaches a model.

Sort into groups

Comprehend, Macie or a guardrail?

Exam skills 3.2.2

Choose the service that protects personal data at each point.

Log in to try this activity Interactive activities are free with an account.

Guardrails and native Bedrock privacy

Bedrock Guardrails sensitive information filters block or mask PII types and custom patterns in prompts and responses at inference time, which protects users even when upstream checks miss something. Amazon Bedrock's native data privacy features include: prompts and responses are not used to train the base models and are not shared with model providers; model providers have no access to the accounts where models run; data is encrypted in transit and at rest; and customisation data and custom models stay in the customer's account. Bedrock does not store prompts and responses unless the customer enables invocation logging.

The following table maps data locations to services.

Where PII appearsService
Objects stored in S3 bucketsAmazon Macie
Text flowing through pipelines and LambdaAmazon Comprehend
Audio transcriptsAmazon Transcribe PII redaction
Prompts and responses at inferenceBedrock Guardrails sensitive information filters
Invocation logsRedaction before logging; restricted, encrypted log storage
True or false

Bedrock's native privacy

Exam skills 3.2.2

Check three claims about Amazon Bedrock's built-in data privacy.

Log in to try this activity Interactive activities are free with an account.
Worked example

Preparing a knowledge base

A company plans to ingest 2 million support documents into a knowledge base for a customer-facing assistant and must ensure customers' personal data is not exposed.

Macie discovery identifies which buckets and objects contain PII; a pre-processing step with Comprehend redacts PII in those documents before ingestion; and a guardrail sensitive information filter masks any remaining PII in responses as a final safeguard.

Check yourself

Does Amazon Bedrock use prompts to train base models?

Show answer

No. Bedrock does not use prompts or responses to train base models and does not share them with model providers.

Exam Tips

Remember for the exam

  • PII in S3 buckets: Macie. PII in text pipelines: Comprehend.
  • Mask or block PII in prompts and responses: Guardrails.
  • Bedrock does not use prompts to train base models or share them with providers.
  • Redact before documents are embedded or used for fine-tuning.