Automated PII removal in PDFs with Nutrient API
Table of contents
Use Nutrient’s AI redaction API for contextual detection and review the results before applying redactions.
Choose a detection method — Use AI redaction for contextual criteria, or text, preset, and regex rules for known patterns.
Review before removal — Staged annotations only mark content. The underlying content remains in the PDF until you apply the redactions.
Prepare and verify — Run optical character recognition (OCR) first for scans, check the final PDF, and review your plan’s retention terms before uploading sensitive documents.
Automated PII removal from a PDF involves detecting personally identifiable information (PII), reviewing the proposed redactions, and permanently removing the marked page content from the output. Nutrient’s hosted API provides AI-based detection and rule-based redaction. This tutorial covers the cURL and Python requests, plus the checks needed before you distribute the result.
How to automate PII removal from a PDF
- Start with a copy of the PDF. List the names, email addresses, or account numbers the recipient shouldn’t see.
- Prepare a searchable PDF. For scans, run the PDF OCR API first and inspect the recognized text before detection.
- Choose AI criteria or deterministic text, preset, or regex rules. The Python AI example stages matches. For review before removal, omit
applyRedactionsfrom the text-search example. - Review the marked PDF and apply the approved redactions.
- Open the applied PDF and verify that it’s the file your workflow will share.
AI detection and pattern matching need representative tests. A regex for hyphenated Social Security numbers can miss a spaced version, and an AI request can miss a repeated mention. Neither method replaces output verification.
What is PII redaction?
PII redaction removes marked personal information from a document’s page content. A PII redaction API can identify candidate regions and either stage annotations for review or apply them to remove the covered content. Your application should record review decisions and processing outcomes when an audit trail is required.
Drawing a black rectangle over text can leave that text selectable or extractable. Applied redactions remove the covered page content from the processed PDF. They don’t erase the original file, other stored copies, or every possible source of identifying information.
Which detection method should you use?
Start with the recipient’s needs and your document policy. List names, contact details, government identifiers, financial account numbers, and contextual references that must be removed. Check repeated mentions, headers, tables, and combinations of details that could identify someone.
| Approach | Use it for | What to check |
|---|---|---|
| AI criteria | Identifiers described by context, including personal details in freeform text | Missed occurrences, ambiguous names, and information marked unnecessarily |
| Text search | A known name, phrase, or identifier repeated in a document | Spelling variants, capitalization, and partial matches |
| Preset or regex patterns | Structured identifiers with recognizable formats | Formatting variations and unrelated values that match the pattern |
| Human review | Ambiguous cases and approval before sharing | Every page and the final applied output |
This post explains implementation. For vendor selection, see the AI redaction API comparison. If users need redaction controls inside your application, see the SDK redaction workflow.
Prerequisites
Before implementing automated PII redaction, you’ll need:
- A valid Nutrient API account (sign up here(opens in a new tab))
- Basic understanding of REST APIs
- A supported Python version with the
requestspackage installed, or cURL for the shell example - PDF documents for testing redaction (you can use this example document containing various PII types)
How Nutrient handles AI and pattern-based redaction

Nutrient provides two redaction methods to meet different requirements.
AI-powered redaction API
The AI redaction API accepts criteria describing the sensitive information to locate. Use context-based criteria when a fixed pattern won’t describe the target, and test ambiguous cases such as a person’s name appearing in an address.
Send a searchable PDF. For scans, run OCR first and send its output in a separate AI redaction request. Start with staged annotations so you can review detections before applying them. The API reference documents an optional options.confidence.threshold from 1 to 10. Raising it filters out more candidate matches. Check for missed identifiers and false positives on your own documents before choosing a threshold.
Text and pattern-based redaction API
The redaction API supports text search, preset patterns, and custom regex rules. The Python example below uses text search for a known term; the redaction guide covers the other strategies.
Create annotations first when review is required. Apply them to the reviewed PDF to permanently remove the covered content from the output.
Review the Processor privacy guide before uploading sensitive files. On retention-disabled plans, uploaded and generated files are deleted within 24 hours; that bound doesn’t cover all logs or backups. Retention-enabled plans retain inputs and outputs for service improvement, including model training and evaluation. API requests use HTTPS.
API setup
To get your API credentials:
- Create a Nutrient API account(opens in a new tab).
- Navigate to the API keys section in your dashboard.
- Check your plan’s usage allowance and retention terms before uploading documents.

Code path A: AI-powered PII detection and redaction
Here’s how to implement AI-powered PII detection and redaction.
Basic redaction with cURL
This example sends a document with a criteria string, staging every detected PII match for review:
# Simple PII redaction.curl -X POST https://api.nutrient.io/ai/redact \ -H "Authorization: Bearer {NUTRIENT_API_KEY}" \ -o result.pdf \ --fail \ -F file1=@redaction.pdf \ -F data='{ "documents": [ { "file": "file1" } ], "criteria": "All personally identifiable information", "redaction_state": "stage" }'Stage vs. apply
Set how redactions are finalized via redaction_state:
"stage"— Creates reviewable annotations; the underlying content remains in the PDF."apply"— Applies the detected redactions to remove the covered content from the output.
Here’s the minimal payload change needed:
{ "documents": [{"file": "file1"}], "criteria": "All personally identifiable information", "redaction_state": "stage"}{ "documents": [{"file": "file1"}], "criteria": "All personally identifiable information", "redaction_state": "apply"}Use "stage" to evaluate detection before applying redactions. A new AI request runs detection again; to preserve human-reviewed annotations, apply those annotations to the reviewed PDF with the Build API’s applyRedactions action.
PII redaction in Python
The same request looks like this using Python’s requests library:
import requestsimport json
response = requests.request( 'POST', 'https://api.nutrient.io/ai/redact', headers = { 'Authorization': 'Bearer {NUTRIENT_API_KEY}' # Replace with your actual API key. }, files = { 'file1': open('redaction.pdf', 'rb') }, data = { 'data': json.dumps({ 'documents': [ { 'file': 'file1' } ], 'criteria': 'All personally identifiable information', "redaction_state": "stage" # or "apply" for permanent redaction. }) }, stream = True)
if response.ok: with open('result.pdf', 'wb') as fd: for chunk in response.iter_content(chunk_size=8096): fd.write(chunk)else: print(response.text) exit()Code path B: Text and pattern-based redaction
Use text search for a known value, a preset for a supported format, or a regex for a custom pattern. These use the Build API’s createRedactions action with the corresponding strategy.
Basic redaction with Python
This example searches for the text acme with strategy: "text" and applies the matching redactions in the same request. It demonstrates text search, rather than a regex or a preset. For human review, omit the applyRedactions action when creating annotations:
import requestsimport json
response = requests.request( 'POST', 'https://api.nutrient.io/build', headers = { 'Authorization': 'Bearer {NUTRIENT_API_KEY}' # Replace with your actual API key. }, files = { 'document': open('redaction.pdf', 'rb') }, data = { 'instructions': json.dumps({ 'parts': [ { 'file': 'document' } ], 'actions': [ { 'type': 'createRedactions', 'strategy': 'text', 'strategyOptions': { 'text': 'acme', 'includeAnnotations': True, 'caseSensitive': False } }, { 'type': 'applyRedactions' # createRedactions only for review. } ] }) }, stream = True)
if response.ok: with open('result.pdf', 'wb') as fd: for chunk in response.iter_content(chunk_size=8096): fd.write(chunk)else: print(response.text) exit()Stage vs. apply in the Build API
Text, regex, and preset redaction use a two-step pipeline:
createRedactionsmarks regions for review.applyRedactionsremoves the covered content from the processed PDF.
If you omit the applyRedactions step, the result contains staged annotations and the underlying content is still present. After review, submit that annotated PDF with applyRedactions to remove the covered content.
For a browser review interface or a workflow in your own infrastructure, compare the options in the redaction workflow guide.
Verify PII removal before sharing
Verification has three steps: review the detected PII, apply the approved redactions, and check the PDF you’ll share.
Review the detected PII
Open the staged PDF in a viewer that shows redaction annotations. Compare the marks with your list of identifiers. Check every page — including scanned images, tables, headers, and footers — for repeated or missed occurrences. In an editor that supports redaction annotations, add marks for missed PII and remove incorrect marks. Save the annotated copy as reviewed.pdf.
Apply the approved redactions
Use the Advanced API example in the apply redactions guide. Submit reviewed.pdf to the Build API with the applyRedactions action and write the response to a separate file, such as redacted.pdf. This applies the annotations you reviewed. Sending the file through AI detection again would run a new detection pass.
Check the PDF you’ll share
Open redacted.pdf from disk and check it against your list of identifiers:
- Search the PDF for the original identifiers and their variants. Try selecting and copying text from the redacted regions, and check that extracted text no longer contains the identifiers.
- Inspect every page visually. Check scans and other images for details that text search can miss.
- Inspect metadata, comments, and attachments separately. If any still contain information the recipient shouldn’t see, hold the file until you’ve removed it and checked the PDF again.
- Confirm that the attachment or download in your sharing workflow is the verified
redacted.pdf. The source and review copy still contain PII.
Keep the source and output versions, reviewer, and processing result in your application’s audit record. For a broader inspection process, see the PDF redaction verification article.
GDPR and HIPAA compliance contexts
Automated redaction must comply with data protection regulations that govern how PII is processed, stored, and deleted. Here’s how to align your implementation with the General Data Protection Regulation (GDPR) and the Health Insurance Portability and Accountability Act (HIPAA).
GDPR requirements for automated processing
Under GDPR Article 6(opens in a new tab), automated PII processing requires a lawful basis (e.g. legitimate interests, contractual necessity, or legal obligation). Core principles in Article 5(opens in a new tab) apply:
- Data minimization — Only process data necessary for redaction
- Purpose limitation — Define the purpose and avoid incompatible further processing
- Storage limitation — Retain personal data only as long as necessary for the stated purpose
- Accuracy — Keep personal data accurate and address inaccuracies
- Accountability — Demonstrate compliance through technical and organizational measures
HIPAA safeguards and de-identification
HIPAA obligations depend on your organization’s role and use of protected health information (PHI). Access controls, audit controls, integrity, authentication, and transmission safeguards belong to the broader security process; an API key or redaction operation alone doesn’t establish compliance.
For de-identification, the U.S. Department of Health and Human Services (HHS) describes Safe Harbor and Expert Determination(opens in a new tab). Removing some visible identifiers isn’t sufficient by itself. Neither HIPAA nor GDPR universally requires AI confidence scores. Plan appropriate review, recordkeeping, and contractual safeguards for your use case.
This guide provides technical implementation details and isn’t legal advice. Consult your legal counsel for specific compliance requirements in your jurisdiction and use case.
Redacting bank documents before sharing
Before a lender shares a loan file with an investor, servicer, or outside reviewer, define which details the recipient needs and which must be removed. A banking application can use Nutrient’s AI redaction API to stage potential matches for review, including account numbers and government identifiers covered by the lender’s sharing policy.
Follow the review, apply, and output checks above for this sharing copy. Identity checks and the onboarding decision remain part of the bank’s separate processes.
Troubleshooting
Common API errors:
401 Unauthorized— Check your API key in theAuthorizationheader413 Payload Too Large— Reduce or split the input as appropriate, and check the error response for details429 Too Many Requests— For an asynchronous Build API request, follow theRetry-Afterheader when present.422 Unprocessable Entity— For AI redaction, the output PDF exceeds the size limit. For the Build API, check the response details for an oversized output or a rejected action.
FAQ
A PII redaction API detects or marks personal information in a document and can apply redactions to remove the covered page content. Nutrient offers AI criteria through /ai/redact and text, preset, and regex rules through /build. A staged response is a review copy: The underlying content remains until the redactions are applied.
Create a Nutrient API account(opens in a new tab) to test the examples with the free plan’s $5 of monthly usage. Free-plan output carries an evaluation watermark. Check the current pricing and account terms before estimating how many documents you can process. OCR, conversion, and redaction can incur separate charges.
For AI redaction, budget for both the per-page AI charge and the standard redaction fee per operation. Pattern-based redaction uses the standard per-operation rate. See the current per-tool pricing for rates and account billing details, and include any OCR or conversion steps in your estimate.
Use AI redaction when the criteria depend on context. Use text search, presets, or regex when you can describe the target values as deterministic rules. For scans, prepare and check the OCR text first. Both approaches need evaluation for missed matches and incorrect detections, plus review and verification before sharing the final PDF.
Run OCR first to add a searchable text layer, inspect the OCR result, and send that PDF to the AI redaction endpoint. OCR and AI redaction are separate requests. Incorrect recognition can cause missed detections, so check the visible scan as well as the extracted text in the final output.
AI redaction uses large language models (LLMs) to identify sensitive content from context. Depending on redaction_state, the response contains staged annotations or applied redactions. Detection can miss content, so validate the results. Document retention follows the Processor privacy guide.
Context can help distinguish a phone number from a product code or a person from a street name, but ambiguous cases still need evaluation.
PDF is fully supported. Office files (Word, Excel, PowerPoint) can be converted to PDF first using Nutrient’s conversion APIs; conversion is charged per operation too.
For complete format support and pricing details, see our API documentation.
Start with a reviewed test document
Download the sample PDF and test redaction on a copy. Use the staged Python example to see what the API detects. Then review, apply, and verify the result. Check the final file before using the workflow on other documents.