Skip to content

Skill 1.2.8: Mask, redact, and anonymize data


Question 1 - PII Detection and Masking Pipeline

A healthcare analytics company is building a machine learning pipeline in Amazon SageMaker to train a patient readmission prediction model. The training dataset contains clinical notes stored in Amazon S3, and compliance with HIPAA requires that all protected health information (PHI) such as patient names, medical record numbers, and dates of birth must be masked before model training. The data engineering team needs to implement a managed, serverless service that can automatically detect PHI entities in unstructured clinical text and replace them with synthetic placeholder values while preserving the overall text structure for downstream NLP processing.

The company requires minimal operational overhead and automatic entity detection without building custom regex patterns or maintaining rule lists.

Which solution meets these requirements?

A) Use Amazon Comprehend to detect PHI entities in the clinical notes and write a custom AWS Lambda function to replace detected entities with synthetic masked values before storing the processed text in S3.

B) Use Amazon SageMaker Data Wrangler with a custom PySpark script to apply regex-based masking patterns for names, dates, and medical record numbers to the clinical notes column.

C) Use Amazon Macie to automatically discover and mask PHI entities within the clinical notes stored in S3 by applying automated data transformation rules.

D) Use AWS Glue DataBrew to create a visual recipe with pattern-matching transformations that identify and replace PHI values with hashed tokens.


Click to reveal Answer & Explanation

Correct Answer: A

Correct Answer Analysis

  • A is Correct: Amazon Comprehend provides a managed DetectPII API that automatically identifies PHI entities (such as names, dates, medical record numbers) in unstructured text without requiring custom regex rules. Pairing it with AWS Lambda for the masking transformation maintains a fully serverless architecture with minimal operational overhead, satisfying both the HIPAA compliance requirement and the managed service constraint.

Distractor Analysis

  • B is Incorrect: SageMaker Data Wrangler is designed for interactive tabular data preparation, and writing custom PySpark regex patterns introduces significant operational overhead. It requires manual rule maintenance and does not use managed entity detection.
  • C is Incorrect: Amazon Macie is an automated data discovery and classification service for S3 that identifies where sensitive data exists. It does not perform entity-level masking or redaction of data within files.
  • D is Incorrect: AWS Glue DataBrew's pattern-matching transformations rely on user-defined regex or pattern rules. It does not provide managed PHI entity detection and would require manual rule creation and ongoing maintenance.

Key Takeaway: Amazon Comprehend's DetectPII API is the managed AWS service for automatic PHI detection in text, and it pairs naturally with serverless compute like Lambda for masking operations.


Question 2 - Anonymization vs Redaction Decision

A financial services company is preparing transaction data for an external vendor to perform fraud detection model training. The data includes customer names, account numbers, transaction amounts, and timestamps. The company's data governance team has determined that the vendor requires the transaction amounts and timestamps for analysis but does not need customer-identifiable information. The vendor agreement explicitly requires that no customer can be identified from the data, either directly or indirectly, after processing.

Which approach correctly implements the governance requirement?

A) Mask customer names by replacing characters with asterisks and truncate account numbers to the last four digits before sending the data.

B) Redact customer names and account numbers by removing those columns entirely, and apply k-anonymity to the remaining attributes so no individual can be re-identified.

C) Anonymize the data by replacing customer names with randomly generated but realistic-looking names and account numbers with sequential integers, while keeping transaction amounts and timestamps unchanged.

D) Encrypt the customer names and account numbers using AWS KMS customer-managed keys and provide the vendor with the decryption key so they can decrypt only when needed.


Click to reveal Answer & Explanation

Correct Answer: B

Correct Answer Analysis

  • B is Correct: The requirement states that no customer can be identified either directly or indirectly from the data. Redaction removes the identifying columns entirely, and applying k-anonymity ensures that the remaining quasi-identifiers (like transaction amounts and timestamps) cannot be used to re-identify individuals by grouping records into equivalence classes of at least k members.

Distractor Analysis

  • A is Incorrect: Masking preserves the original data structure but does not guarantee anonymization. Partial masking (e.g., retaining last 4 digits of account numbers) can still allow re-identification when combined with other attributes, and the format preservation means the data is not truly anonymized.
  • C is Incorrect: Replacing names with realistic-looking names and sequential account numbers is pseudonymization, not anonymization. Sequential integers preserve uniqueness and allow record linking, making re-identification possible.
  • D is Incorrect: Encryption is a security control, not a privacy transformation. Providing the decryption key to the vendor defeats the purpose of anonymization and does not remove personal information from the data.

Key Takeaway: Anonymization requires that no individual can be identified either directly or indirectly, often requiring statistical techniques like k-anonymity applied to quasi-identifiers, whereas masking only hides values while preserving the data's shape.


Question 3 - S3 Sensitive Data Discovery Workflow

A large e-commerce company stores customer interaction logs from multiple applications in various Amazon S3 buckets across many AWS accounts. Before migrating this data into a centralized Amazon SageMaker Feature Store for a recommendation model, the security team must first inventory all S3 buckets to identify which objects contain sensitive data such as credit card numbers, passport identifiers, and personal email addresses so that targeted masking jobs can be applied.

The security team wants automated discovery across the entire S3 estate with minimal manual effort and needs a service that generates detailed findings reports with severity ratings for prioritization.

Which AWS service should the team use first?

A) Amazon Comprehend to run entity detection on each S3 object by invoking the BatchDetectEntities API through a scheduled AWS Glue job.

B) Amazon Macie with a discovery job configured across all S3 buckets to automatically detect and classify sensitive data types, generating findings with severity scores.

C) AWS Glue DataBrew profile job to scan all S3 data and automatically detect personally identifiable information columns through its built-in data profiling rules.

D) Amazon SageMaker Clarify to analyze the S3 datasets for sensitive data bias and generate explainability reports before feature engineering begins.


Click to reveal Answer & Explanation

Correct Answer: B

Correct Answer Analysis

  • B is Correct: Amazon Macie is the AWS service purpose-built for automated sensitive data discovery and classification across S3 buckets. It uses managed data identifiers (including credit card numbers, passport numbers, and email addresses) and generates findings with severity ratings, allowing targeted remediation like masking or redaction.

Distractor Analysis

  • A is Incorrect: Amazon Comprehend detects PII in text but requires you to build the orchestration (scheduled Glue jobs, API calls, result aggregation). It does not natively scan across the entire S3 estate with automated classification and severity-based prioritization.
  • C is Incorrect: AWS Glue DataBrew profile jobs analyze column-level statistics for data quality and completeness but do not provide managed PII/sensitive data detection with severity ratings like Macie.
  • D is Incorrect: Amazon SageMaker Clarify is focused on model bias detection and explainability, not sensitive data discovery in raw datasets.

Key Takeaway: Amazon Macie is the AWS-native solution for automated sensitive data discovery and classification across S3 before applying targeted masking transformations.


Question 4 - SageMaker Training Data Masking

A company is using Amazon SageMaker Pipelines to orchestrate a training workflow. The preprocessing step reads raw Parquet files from S3, applies feature engineering, and outputs the result to S3 as a CSV before training. The raw data contains email addresses and phone numbers in free-text fields. The compliance team requires these values to be irreversibly anonymized (cannot be reconstructed to their original form) while maintaining realistic text formats for NLP feature extraction.

Which transformation should be incorporated into the SageMaker processing step?

A) Apply AES-256 encryption to the email and phone number fields using a SageMaker Feature Store offline store transformation.

B) Replace email addresses and phone numbers with hash values generated using a deterministic hash function (e.g., SHA-256) without a salt.

C) Replace email addresses and phone numbers with synthetic values generated from the same character distribution (e.g., a random string matching the email format), ensuring no original values are recoverable.

D) Mask email addresses by replacing the domain with a placeholder (e.g., user@example.com) while keeping the phone numbers unchanged since they are not considered sensitive.


Click to reveal Answer & Explanation

Correct Answer: C

Correct Answer Analysis

  • C is Correct: Generating synthetic values from the same character distribution produces realistic-looking, format-preserving replacements that cannot be reversed to recover the original data. This satisfies the irreversible anonymization requirement while maintaining text structure for NLP features.

Distractor Analysis

  • A is Incorrect: Encryption is reversible (given the key) and thus does not constitute anonymization. Additionally, SageMaker Feature Store offline store does not perform field-level encryption transformations.
  • B is Incorrect: Deterministic hashing without a salt is vulnerable to dictionary or brute-force attacks (rainbow table attacks), especially for email addresses that have limited entropy. This makes it reversible in practice and not compliant with the irreversibility requirement.
  • D is Incorrect: Masking only the domain of the email address still reveals the local part (username) and is a reversible masking operation. Phone numbers are also PII and leaving them unchanged fails the privacy requirement.

Key Takeaway: True anonymization requires transformations that cannot be reversed, whereas hashing without salts and simple masking are either vulnerable to attacks or easily reversed.


Question 5 - Streaming PII Redaction with Lambda

A real-time recommendation service ingests user activity data through Amazon Kinesis Data Streams. Each record contains a JSON payload with user_id, email, search_query, and clicked_item. The privacy team requires that before records are written to Amazon S3 for model training, the email field must be completely redacted (removed from the payload), and the user_id must remain unchanged for behavioral analysis. The team wants this transformation to happen in the stream with minimal latency and no additional infrastructure to manage.

Which solution should be implemented?

A) Configure an AWS Lambda function as a Kinesis Data Streams consumer that transforms each record by removing the email field and writes the modified record to S3 via PutObject.

B) Use Amazon Kinesis Data Firehose with a built-in data transformation Lambda function that removes the email field before delivering the data to S3.

C) Use Amazon EMR with Apache Flink to create a streaming job that consumes from Kinesis, redacts the email field, and writes to S3.

D) Use AWS Glue streaming ETL job with a Python script that removes the email field and writes the output to a Kinesis Data Firehose delivery stream.


Click to reveal Answer & Explanation

Correct Answer: B

Correct Answer Analysis

  • B is Correct: Amazon Kinesis Data Firehose provides native serverless data transformation capability using Lambda. The Firehose delivery stream automatically invokes the Lambda function for each record, removes the email field, and delivers the transformed data to S3 with buffering. This minimizes latency and requires no additional infrastructure management.

Distractor Analysis

  • A is Incorrect: While Lambda can consume from Kinesis, writing directly to S3 via PutObject requires custom code for stream checkpointing, scaling, and managing delivery semantics. This introduces more operational complexity than using Firehose's built-in transformation and delivery path.
  • C is Incorrect: Amazon EMR with Apache Flink requires provisioning and managing an EMR cluster (or Kinesis Data Analytics with Flink), which is heavy infrastructure for a simple record-level transformation. It violates the minimal operational overhead constraint.
  • D is Incorrect: AWS Glue streaming ETL runs on a Spark cluster that is auto-managed but still introduces more startup latency and overhead than a Firehose Lambda transform for a simple per-record redaction.

Key Takeaway: For simple record-level redaction in streaming pipelines, Kinesis Data Firehose with a Lambda transform is the serverless solution with minimal operational overhead and low latency.


Question 6 - Comprehend PII vs Contain vs Detect

A multilingual customer support platform processes chat conversations in English and Spanish. The data science team needs to redact customer email addresses, phone numbers, and full names from the conversation text before using it for Amazon Bedrock fine-tuning. The team wants to use Amazon Comprehend to detect the PII entities and needs to know which API operation to use for real-time synchronous detection of PII in a single document.

Which Amazon Comprehend API operation should be used?

A) StartPiiEntitiesDetectionJob with an S3 input and output location

B) DetectPiiEntities with the text passed as a parameter

C) BatchDetectEntities with the text passed as a list

D) DetectEntities with the text passed as a parameter and a filter for PII entity types


Click to reveal Answer & Explanation

Correct Answer: B

Correct Answer Analysis

  • B is Correct: Amazon Comprehend's DetectPiiEntities API operation performs real-time, synchronous PII detection for a single text document, returning the detected PII entity types (e.g., EMAIL, PHONE, NAME) with confidence scores and character offsets for targeted redaction or masking.

Distractor Analysis

  • A is Incorrect: StartPiiEntitiesDetectionJob is the asynchronous batch API for detecting PII across multiple large documents stored in S3. While powerful for batch workloads, it is not the correct operation for real-time synchronous processing of a single document.
  • C is Incorrect: BatchDetectEntities performs entity detection for general entities (e.g., organizations, persons, locations), not PII-specific entities. PII detection requires the dedicated PII API.
  • D is Incorrect: DetectEntities detects named entities but does not have a PII-specific filter mode. It identifies general entities like ORG, PERSON, and LOCATION, which may miss sensitive data types like emails and phone numbers.

Key Takeaway: Amazon Comprehend distinguishes between general entity detection (DetectEntities) and PII-specific detection (DetectPiiEntities), with the latter being the correct choice for redaction workflows targeting personal data.


Question 7 - Bedrock Fine-tuning Data Preparation

A software company is preparing a dataset for Amazon Bedrock model fine-tuning to improve the model's ability to generate technical documentation. The raw training data contains code snippets, API keys, customer names, and internal project identifiers distributed across thousands of JSONL files stored in Amazon S3. The compliance team requires that all sensitive information be redacted from the fine-tuning data before it is uploaded to Amazon Bedrock.

The team is deciding between two approaches:

  • Approach X: Use Amazon Macie to discover sensitive data, then use AWS Glue jobs with Amazon Comprehend to detect and redact PII from the training data.
  • Approach Y: Use Amazon Bedrock Guardrails to automatically filter PII from the training data during the fine-tuning process.

Which approach is correct, and why?

A) Approach Y is correct because Bedrock Guardrails automatically redacts PII from fine-tuning data, eliminating the need for pre-processing.

B) Approach X is correct because PII must be redacted before the data is used for fine-tuning; Bedrock Guardrails filter inference output but do not pre-process training data.

C) Both approaches are equally valid because Bedrock Guardrails can be applied to both training and inference phases.

D) Neither approach is correct because Amazon Comprehend cannot detect PII in JSONL files.


Click to reveal Answer & Explanation

Correct Answer: B

Correct Answer Analysis

  • B is Correct: Amazon Bedrock Guardrails are designed to filter PII and harmful content during inference time from model inputs and outputs, not to pre-process training data. Sensitive data must be redacted before fine-tuning begins, using tools like Amazon Comprehend paired with AWS Glue to scan and redact the raw training files.

Distractor Analysis

  • A is Incorrect: Bedrock Guardrails do not operate on fine-tuning training data. They are inference-time controls, so this approach would leave sensitive data exposed in the training set.
  • C is Incorrect: Guardrails cannot be applied to the training phase of Bedrock model customization. The statement presents a false equivalence.
  • D is Incorrect: Amazon Comprehend supports PII detection in plain text documents, including JSONL files when the text is properly extracted and passed to the API. This option incorrectly dismisses a valid approach.

Key Takeaway: Always redact sensitive data from training datasets before fine-tuning; Bedrock Guardrails are inference-time controls, not training data pre-processors.


Question 8 - Glue DataBrew Recipe for Masking

A marketing analytics team uses AWS Glue DataBrew for visual data preparation. They need to create a recipe that masks email addresses in a customer dataset by preserving the first character and the domain while obfuscating the intermediate characters (e.g., j***e@example.com instead of johndoe@example.com). The team has no coding experience and must use DataBrew's built-in transformations.

Which DataBrew recipe step should the team add?

A) A custom Pyspark step with regex replacement logic

B) A REDACT pattern-matching step to remove the middle characters of the email address

C) A MASK pattern-matching step with a mask pattern that preserves the first character, masks intermediate characters, and retains the domain

D) A SHUFFLE transformation on the column to randomize character positions


Click to reveal Answer & Explanation

Correct Answer: C

Correct Answer Analysis

  • C is Correct: AWS Glue DataBrew provides built-in MASK transformations that allow users to define patterns for masking specific portions of a string column. The team can configure the mask to preserve the first character and the domain while replacing the middle characters with asterisks or other placeholder characters, all within a visual recipe environment.

Distractor Analysis

  • A is Incorrect: Custom PySpark steps require coding knowledge and defeat the purpose of using a no-code visual tool. While technically possible, it violates the constraint of using DataBrew's built-in transformations.
  • B is Incorrect: A REDACT step removes values entirely rather than masking them with placeholders. This would not preserve the format required (e.g., keeping the first character and domain).
  • D is Incorrect: SHUFFLE randomizes character positions within a field, which irreversibly destroys the email format and does not produce the required masked output.

Key Takeaway: AWS Glue DataBrew's built-in MASK transformation supports format-preserving masking with user-defined patterns, making it suitable for no-code data preparation workflows.


Question 9 - Inference-Time Output Filtering

A customer support chatbot built on Amazon Bedrock generates responses that may inadvertently include PII found in the retrieved context from customer conversation history stored in an Amazon OpenSearch Serverless vector store. The compliance team requires that any PII in the model's output be automatically blocked before being displayed to the end user. The team also wants to block any suggestions of harmful or offensive content.

Which solution provides the most comprehensive protection with the least operational overhead?

A) Configure Amazon Bedrock Guardrails with PII redaction and content filtering policies applied to the model invocation to block or mask PII and harmful content in real time.

B) Run all model outputs through a custom AWS Lambda function that uses Amazon Comprehend to detect and redact PII before returning the response to the user.

C) Use Amazon Macie to continuously scan the OpenSearch Serverless collection for PII and automatically apply redaction policies.

D) Filter the embedding vectors in the vector store to exclude any chunks containing PII, ensuring the model never retrieves sensitive data.


Click to reveal Answer & Explanation

Correct Answer: A

Correct Answer Analysis

  • A is Correct: Amazon Bedrock Guardrails provide managed, real-time filtering of PII and harmful content during model inference. They can be applied to model invocations to redact or block PII in outputs and enforce content policies, all with minimal operational overhead and no custom code required.

Distractor Analysis

  • B is Incorrect: A custom Lambda function with Amazon Comprehend introduces significant operational overhead (code to maintain, error handling, latency) and does not provide the built-in content filtering for harmful content that Bedrock Guardrails offers.
  • C is Incorrect: Amazon Macie is designed for S3 data discovery and classification, not for real-time filtering of model outputs from OpenSearch Serverless. It cannot apply redaction policies to inference outputs.
  • D is Incorrect: Filtering the vector store only addresses the retrieval phase but does not protect against PII that may be generated by the model itself or present in the prompt. It also does not address harmful content filtering in outputs.

Key Takeaway: Amazon Bedrock Guardrails provide the managed, integrated solution for PII blocking and content filtering at inference time, eliminating the need for custom detection pipelines.


Question 10 - Distillation Dataset Anonymization

A startup is preparing data for model distillation in Amazon Bedrock. They have assembled a large set of prompts covering their domain to send to the teacher model. However, some prompts contain internal customer project names, API endpoints, and employee email addresses. The company's security policy requires that the prompt set be fully anonymized before transmission to the Bedrock service, meaning no identifiable information can remain in the data.

The team needs to choose a transformation strategy that ensures no reversible linkage to the original entities while maintaining the semantic meaning of the prompts for effective distillation.

Which option best meets these requirements?

A) Mask the sensitive values by replacing them with *** characters throughout the prompt text, preserving the surrounding context for semantic analysis.

B) Replace sensitive entities with synthetic equivalents that match the same semantic category (e.g., replace real emails with user@domain.com, API endpoints with api.example.com) so the prompt's meaning is retained without exposure of real identifiers.

C) Redact the sensitive values by removing them entirely from the prompts, accepting that some prompts may become syntactically incomplete.

D) Use AWS KMS to encrypt the prompt set and transmit the ciphertext to Bedrock for distillation, ensuring no identifiable data is exposed in plaintext.


Click to reveal Answer & Explanation

Correct Answer: B

Correct Answer Analysis

  • B is Correct: Anonymization by replacing sensitive entities with semantically equivalent synthetic placeholders (e.g., generic emails, example domains, placeholder API endpoints) breaks the linkage to the original identifiable entities while preserving the prompt's syntactic and semantic structure. This ensures the teacher model receives meaningful prompts for distillation without exposing real sensitive data.

Distractor Analysis

  • A is Incorrect: Masking with *** characters destroys the semantic meaning of the sensitive entities and may produce prompts that are confusing or misleading for the teacher model, reducing the quality of distillation responses.
  • C is Incorrect: Redaction removes sensitive values but breaks syntactic completeness, potentially producing prompts that are nonsensical to the teacher model, resulting in low-quality responses for distillation.
  • D is Incorrect: Encryption protects data in transit but does not anonymize it. The Bedrock distillation pipeline would receive ciphertext that cannot be processed as a meaningful prompt. Additionally, providing decryption keys would defeat the purpose of anonymization.

Key Takeaway: For model distillation data preparation, anonymization should preserve semantic and syntactic structure through synthetic replacements rather than masking or redaction, which can degrade prompt quality.