---
title: "Redact PII from extracted text"
method: POST
path: "/security/text/redact"
tags: ["Security"]
---

# Redact PII from extracted text

`POST /security/text/redact`

## Request

- Base URL: `https://api.filegraph.ai` (the document declares no server; this is the origin it was published from)
- URL: `https://api.filegraph.ai/security/text/redact`
- Auth: API key in header `X-API-Key`

Extract text from any document and redact PII with category tags.

## How It Works

1. **Extract text** from any supported format (PDF, DOCX, XLSX, PPTX, images, HTML, etc.)
2. **Detect PII** using pattern matching and intelligent entity recognition
3. **Redact** by replacing PII with category tags like `[SSN]`, `[EMAIL]`, `[NAME]`
4. **Return** redacted text with audit metadata

## PII Types Detected

| Type | Example Output | Confidence |
|------|----------------|------------|
| `ssn` | [SSN] | 0.90 |
| `credit_card` | [CREDIT_CARD] | 0.95 |
| `email` | [EMAIL] | 0.98 |
| `phone` | [PHONE] | 0.85 |
| `ip_address` | [IP_ADDRESS] | 0.95 |
| `date_of_birth` | [DATE_OF_BIRTH] | 0.70 |
| `name` | [NAME] | 0.85 |
| `address` | [ADDRESS] | 0.85 |
| `organization` | [ORGANIZATION] | 0.85 |

## Parameters

- `pii_types`: Comma-separated list of types to detect, or "all" (default)
- `use_ner`: Enable intelligent name/address/organization detection (default: true)
- `minimum_confidence`: Threshold 0.0-1.0 (default: 0.8)
- `ocr_language`: OCR language if needed (default: "eng")
- `ocr_fallback`: Use OCR if text extraction fails (default: true)

## Audit Metadata

The response includes masked values for compliance logging:
- SSN: `***-**-6789`
- Email: `j***@example.com`
- Phone: `***-***-7890`
- Credit Card: `************1234`

## Example

```python
import httpx

response = httpx.post(
    "https://api.filegraph.ai/security/text/redact",
    headers={"X-API-Key": "your-api-key"},
    files={"file": open("document.pdf", "rb")},
    data={
        "pii_types": "ssn,email,phone,name",
        "use_ner": "true",
        "minimum_confidence": "0.8"
    }
)

result = response.json()
print(f"Found {result['pii_found']} PII instances")
print(result['redacted_text'])

# Audit log
for match in result['matches']:
    print(f"{match['pii_type']}: {match['masked_value']}")
```

## Response `200`

Successful Response

- TextRedactResponse: Response for text PII redaction operation.
  - `redacted_text` string, required: Text with PII replaced by category tags
  - `format_detected` string, required: Detected input format (pdf, docx, image, etc.)
  - `word_count` integer, required: Number of words in extracted text
  - `char_count` integer, required: Number of characters in extracted text
  - `used_ocr` boolean, required: Whether OCR was used for text extraction
  - `pii_found` integer, required: Total number of PII instances detected and redacted
  - `pii_by_type` object, required: Count of PII by type: {'ssn': 3, 'email': 5}
  - `matches` PIIMatch[], required: Detailed info about each redacted PII instance
    - `pii_type` 'ssn' | 'credit_card' | 'phone' | 'email' | 'ip_address' | 'date_of_birth' | 'name' | 'address' | 'organization', required: Types of PII that can be detected.
    - `masked_value` string, required: Partially masked value for audit: ***-**-6789, j***@example.com
    - `redacted_tag` string, required: Tag used in redacted text: [SSN], [EMAIL]
    - `start_position` integer, required: Start position in original text
    - `end_position` integer, required: End position in original text
    - `confidence` number, required: Detection confidence score
  - `processing_time_ms` integer, required: Total processing time in milliseconds
  - `ner_enabled` boolean, required: Whether intelligent entity detection was used for names/addresses

## Other responses

- `422`: Validation Error

---

[API](https://skmtc.dev/filegraph/apis/docconvert-api.md) · [All operations](https://skmtc.dev/filegraph/apis/docconvert-api/llms.txt) · [OpenAPI document](https://skmtc.dev/filegraph/apis/docconvert-api/revisions/436255c85bd4?raw)
