Skip to main content
In this lesson we cover practical controls to protect your Amazon Bedrock applications: identify sensitive data, filter or mask it, limit what you send to models (especially in retrieval-augmented generation), and log/monitor model usage safely. These steps form a defense-in-depth approach that reduces data exposure and helps meet regulatory and governance requirements. Plan your controls in four stages:
  1. Identify: map data flows and find sensitive items (PII, financial information, proprietary data).
  2. Filter / Mask: redact or tokenize sensitive fields (names, account numbers, secrets).
  3. Limit: scope the context you send to models — chunk retrievals and avoid sending raw documents.
  4. Monitor: log and audit who calls models, prompts issued, and responses generated — while protecting any logged sensitive data.
An infographic titled "Workflow: Filtering and Logging" that maps a four-step data flow: Identify, Filter, Limit, and Monitor. Each step lists examples (e.g., identify internal/financial/PII data; drop secrets, redact names, mask account numbers; no raw dumps, minimal context, scoped RAG; log prompts/responses and track access).

Input filtering and prompt-sanitization

Logging every model invocation is useful for observability, but it creates risk if prompts or responses contain sensitive data. One important defensive control is input filtering — sanitize and validate user prompts in your application layer before calling Bedrock. Below is a simple Python example that demonstrates a string-match approach: two indicator lists (harmful_keywords, injection_phrases) and a function is_safe_input that blocks inputs containing those indicators. This basic method is intentionally minimal to illustrate the concept; treat it as one layer of defense.
This code performs a case-insensitive substring check. If any indicator is found, the input is blocked. Use this pattern to gate inputs before they reach Bedrock Runtime via your SDK client. Note that simple string matching can be evaded. Combine this with additional layers: regex checks, token-aware matching, semantic classifiers, named-entity recognition, PII detectors, and human review for high-risk flows.

Prompt-injection detection example

Prompt injection is an adversarial technique where a malicious user crafts input that tries to override system instructions, reveal hidden data, or manipulate model behavior. The following focused example flags common injection phrases:
If is_prompt_injection returns True, block or escalate the request; otherwise continue. Apply the same precaution to any retrieved RAG context: filter and redact chunks before including them in prompts.
These examples show straightforward string-matching rules. For production systems, add complementary techniques such as regex checks, tokenization-aware matching, semantic classifiers, named-entity detection, and specialized PII detectors. Combine multiple detectors and human review for high-risk flows.

What benefits to expect

Implementing these controls reduces the likelihood of disclosing sensitive information in prompts or model outputs. It also supports regulatory compliance (for example, GDPR, HIPAA, PCI DSS), strengthens governance over AI workflows, and improves customer trust.
A slide titled "Results" with four numbered panels. Each panel lists a benefit: reduced data exposure risk; improved regulatory compliance (e.g., GDPR); stronger data governance across AI workflows; and increased customer trust and confidence.

Practical checklist and controls

Use this checklist when designing Bedrock workflows:
  • Identify and classify sensitive data types across your pipeline.
  • Apply masking, redaction, tokenization, or anonymization before transmission.
  • Limit RAG context: chunk documents, and only send relevant, sanitized fragments.
  • Validate and sanitize model outputs before returning them to users.
  • Log model invocations but redact or mask PII in logs and control who can access them.
  • Combine automated detectors with human review for high-risk requests.
Table: Controls and typical benefits

Key practice: least privilege for data

Only pass the minimum data required for the model to complete the task — no more, no less. For especially sensitive fields (customer records, credit cards, secrets), apply redaction, tokenization, or anonymization prior to transmission. Effective sanitization requires knowing what sensitive data looks like and where it appears in your workflow. Sanitization should occur at every level:
  • Validate user input before sending to Bedrock.
  • Sanitize retrieved context returned by RAG systems before including in prompts.
  • Filter and validate model outputs before returning them to end users.
A presentation slide titled "Key Takeaways." It lists numbered data-privacy guidelines like "pass only the data required for the task," "avoid unnecessary privacy and security risks," and "minimize data exposure," noting relevance to Bedrock workflows.
Careful with logs: model invocation logs can contain PII or other sensitive data. Mask or redact sensitive fields before persisting logs, and control access to log storage.
That wraps up this lesson on data privacy controls for Bedrock. For additional in-model safety, consider using Bedrock Guardrails and combine platform-level, application-level, and human-review controls to create a robust defense-in-depth strategy.

Watch Video