AWS Builder Center

Redact PII from Documents and Audio at Scale with a Serverless Pipeline on AWS

Learn how to deploy a serverless pipeline on AWS that automatically detects and redacts PII from documents and audio uploaded to Amazon S3. It uses Amazon Bedrock for contextual detection, along with Amazon Textract, Amazon Transcribe, and Amazon Polly, and replaces PII with realistic synthetic data or a blackout while keeping a full audit trail.

Problem

Teams in financial services, healthcare, and insurance run into the same wall before they can do anything useful with their data: the documents are full of personally identifiable information (PII) such as names, social security numbers, addresses, medical details, account numbers. Before that data can go into analytics, model training, or a third party's hands, the PII has to come out. And the usual ways of getting it out are painful. Manual review takes weeks and is inconsistent. Legal clearances add another month or two. Promising projects stall out simply because the data prep turns out to be harder than the problem everyone actually wanted to solve.
The reason it stays hard is that traditional PII tooling leans on pattern matching and named entity recognition. That works until you hit a scanned form, a handwritten note, or a date of birth buried in a paragraph of clinical notes. Context matters, and rule based systems do not have much of it. This system supplies that context, and it is now open source.

What it is

The PII Anonymization and Redaction System is a serverless pipeline on AWS that detects and redacts PII from documents and audio dropped into an Amazon S3 bucket. The core idea is to combine the contextual understanding of a large language model with the precision of OCR and word-level audio timestamps. The LLM figures out what is actually PII given the surrounding context. Amazon Textract and Amazon Transcribe give us the exact coordinates and timestamps so the redaction lands in the right place, whether that is a pixel region on a scanned page or a slice of a phone call.
It has been tested across different use cases such as dispute document understanding, medical summary generation, claim validation, loan document processing, and multilingual documents.

How it works

Amazon S3 is the front door. You drop files in, and the rest runs itself. AWS Step Functions orchestrates six AWS Lambda functions through three stages: detect, generate synthetic replacements, redact. Amazon SQS gives backpressure control and Amazon DynamoDB handles concurrency and keeps an audit trail. Amazon Bedrock does the AI-driven detection using both text and vision models.
There are three processing paths depending on what you feed it:
Documents that are scanned or image-heavy go through Textract for OCR with word-level coordinates. A vision model on Bedrock reads the page image alongside the OCR text, so it catches PII with full context. Textract then refines the bounding boxes through exact, spatial, and fuzzy matching for pixel-accurate redaction. The output PDF is flattened to images, so there is no hidden text layer for PII to leak through.
Digitally generated files (PDF, Word, Excel, CSV, plain text) get their text extracted directly, and a language model detects PII with threaded parallel processing for large documents. Entities are clustered by identity, so "John Smith" on page 1 and "J. Smith" on page 5 get the same replacement and the document stays internally consistent.
Audio (MP3, WAV) is transcribed by Amazon Transcribe with word-level timestamps and speaker diarization. Bedrock detects PII in the transcript, each phrase is mapped back to its exact time range, and Amazon Polly synthesizes a natural-sounding replacement that ffmpeg splices back into the recording. Everything except the sensitive segments stays untouched.

Two ways to redact

  • Synthetic replacement (the default) swaps real PII for realistic fake data. "Jane Doe, 123 Main St" becomes "Robert Chen, 789 Oak Ave." The document stays readable and structurally valid, which matters a lot for downstream analytics.
  • Blackout mode drops solid black rectangles over PII in images and PDFs, or  [REDACTED]  markers in text, for when you want maximum certainty that nothing survives.
One design choice we care about is output-limit safety. Detection work is chunked to fit each model's output token limit, spreadsheets are sub-split, and if a detection response comes back truncated the pipeline fails loudly instead of silently dropping PII. In this domain a quiet failure is the worst possible outcome, so the system is built to never pretend it finished when it did not.
You can also swap models freely through  src/config.yaml  (any supported Amazon Bedrock model, such as Anthropic Claude, Amazon Nova, or OpenAI GPT-5.x), toggle bounding box overlays for visual verification, and customize the detection prompts for your own regulatory categories.

Prerequisites

Before deploying, make sure you have the following:
  •  Git  and  make  (pre-installed on macOS and Linux; on Windows use Git Bash)
  •  AWS CLI v2 , configured with credentials ( aws configure )
  •  Docker Desktop , required on Windows and recommended on macOS and Linux (used to build the Lambda layer)
  • An AWS account with access to Lambda, Amazon S3, Amazon DynamoDB, Amazon Bedrock, Amazon Textract, Amazon Transcribe, Amazon Polly, AWS Step Functions, Amazon SQS, Amazon EventBridge, Amazon CloudWatch, and AWS IAM
  • Amazon Bedrock model access enabled in your Region (for example Amazon Nova Pro or Anthropic Claude)
  •  ffmpeg  for audio processing. It ships as a Lambda layer for the deployed pipeline; for local testing install it with  brew install ffmpeg  (macOS) or your package manager
  • Three Amazon S3 buckets that already exist, since the stack does not create them: an input bucket for documents, an output bucket for redacted results, and an artifact bucket for SAM packaging (CloudFormation only, not needed for Terraform)

Deploy it

Start by cloning the repository and creating your S3 buckets:
git clone https://github.com/awslabs/pii-anonymizer.git
cd pii-anonymizer

# Create your S3 buckets (if they don't already exist) in your preferred Region. For example:
aws s3 mb s3://my-pii-input --region us-east-2
aws s3 mb s3://my-pii-output --region us-east-2
aws s3 mb s3://my-pii-artifacts --region us-east-2 # CloudFormation only
Then set your model, processing approach, and redaction mode in  src/config.yaml  and deploy with whichever tool you prefer.
Option A: CloudFormation (SAM). No local Python environment needed, the Lambda layer builds its own dependencies.
cp infra/cfn/parameters.example.json infra/cfn/parameters.json # fill in your parameters
make cfn-deploy
Option B: Terraform.
cp infra/terraform/terraform.tfvars.example infra/terraform/terraform.tfvars # fill in your values
make tf-init && make tf-deploy
The stack builds its own Lambda layer (fonts for PDF redaction included) and provisions everything in about 10 to 15 minutes. Once it is up, you can drop a file into the input bucket for single-file processing, or upload a folder of related files to have them treated as one job with consistent replacements across every document. Redacted output lands in the output bucket with the same folder structure, and the DynamoDB tracking table keeps a full audit trail of detected entities and their replacements.
There is also an optional Streamlit frontend for uploads, live job monitoring, and reviewing original and redacted content. Sample documents are included in the repo so you can see it work before pointing it at anything real.

Clean up

To avoid ongoing charges, tear the stack down when you are done:
# CloudFormation
make cfn-delete

# Terraform
make tf-destroy
This removes all infrastructure resources. Back up anything you need from S3 and DynamoDB first, then empty and delete the input, output, and artifact buckets if you no longer need them.

Conclusion

PII redaction does not have to be the step that stalls a project for weeks or months. This pipeline handles documents and audio in one serverless workflow, uses contextual detection on Amazon Bedrock to catch PII that pattern matching misses, and keeps output readable through synthetic replacement. Deploy it in your own account with CloudFormation or Terraform, point it at the included sample documents, and see how it does on your own formats. Feedback and contributions are welcome, especially on edge cases it does not handle well yet.
Disclaimer: This is a technical sample intended to accelerate data preparation, not a compliance guarantee. Run it in your own AWS environment, keep a human in the loop, and validate the anonymized output yourself before trusting or sharing it. Confirming that a dataset is free of PII or PHI remains the responsibility of the users who are using the tool, and any production use should follow your organization's security and legal review process.

About the authors

Akhil Nooney is a Deep Learning Architect at the AWS Generative AI Innovation Center, where he works with customers to design scalable, production-ready generative AI solutions. He helps organizations tackle complex challenges and take generative AI use cases from discovery through to production.
Sirajus Salekin is an Applied Scientist at the AWS Generative AI Innovation Center, where he develops machine learning and generative AI solutions for enterprise customers. He works across a range of industries to take applied research from prototype to production.
Mofijul Islam is a Senior Applied Scientist at the AWS Generative AI Innovation Center, where he builds generative AI solutions for enterprise customers. His work focuses on multi-agent reasoning, multimodal LLMs, synthetic data generation, and code generation.
Tanay Chowdhury is a Data Scientist at the AWS Generative AI Innovation Center, where he builds generative AI solutions for enterprise customers. He works across industries to apply large language models and retrieval techniques to real-world problems.
Yanxiang Yu is an Applied Scientist at the AWS Generative AI Innovation Center, where he builds AI and machine learning solutions for enterprise customers. He has years of experience and specializes in generative AI, computer vision, and time series modeling.
Monica Raj is a Deep Learning Architect at the AWS Generative AI Innovation Center, where she architects and deploys production-ready AI solutions across industries. She specializes in agentic AI systems, natural language processing, contact center automation, and intelligent document processing.
Dipanshu Jain is a Senior Generative AI Strategist at the AWS Generative AI Innovation Center, where he helps customers identify high-impact generative AI use cases. He shapes execution roadmaps and guides cross-functional teams through proofs of concept, from discovery to production.
Yingwei Yu is an Applied Science Manager at the AWS Generative AI Innovation Center, where he leads teams building generative AI solutions for enterprise customers. He guides applied science work from research through production delivery.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article