# Redact PII from Call Recordings with Python and Telnyx AI

> Source: <https://dev.to/sonam_50a41a4ced7e6b4f3fa/redact-pii-from-call-recordings-with-python-and-telnyx-ai-28pl>
> Published: 2026-07-29 19:24:41+00:00

I put together a small Flask example that redacts PII from call transcripts and call recordings using Telnyx AI.

Code:

[https://github.com/team-telnyx/telnyx-code-examples/tree/main/call-recording-redactor-python](https://github.com/team-telnyx/telnyx-code-examples/tree/main/call-recording-redactor-python)

The app has two workflows:

The prompt asks the model to replace common PII with placeholders:

`[NAME]`

`[CREDIT_CARD]`

`[SSN]`

`[PHONE]`

`[EMAIL]`

`[ADDRESS]`

`[DOB]`

`[ACCOUNT_NUMBER]`

The useful part is that the response is structured JSON, not just rewritten text.

```
{
  "redacted_transcript": "Hi, this is [NAME] calling. My card number is [CREDIT_CARD].",
  "redactions": [
    {
      "type": "name",
      "original": "John Smith",
      "redacted": "[NAME]",
      "count": 1
    }
  ],
  "items_redacted": 2,
  "pii_types_found": ["name", "credit_card"]
}
```

That means your app can show the sanitized transcript while still keeping an audit-friendly redaction map.

```
git clone https://github.com/team-telnyx/telnyx-code-examples.git
cd telnyx-code-examples/call-recording-redactor-python
cp .env.example .env
pip install -r requirements.txt
python app.py
```

Configure `.env`

:

```
TELNYX_API_KEY=your_telnyx_api_key
AI_MODEL=meta-llama/Llama-3.3-70B-Instruct
HOST=127.0.0.1
curl -X POST http://localhost:5000/redact \
  -H "Content-Type: application/json" \
  -d '{
    "transcript": "Hi, this is John Smith calling. My card number is 4532-1234-5678-9012 and my SSN is 123-45-6789."
  }'
```

This calls Telnyx AI Inference through:

```
POST /v2/ai/chat/completions
curl -X POST http://localhost:5000/redact/audio \
  -F "file=@recording.wav"
```

For audio, the app first calls:

```
POST /v2/ai/audio/transcriptions
```

using:

```
distil-whisper/distil-large-v2
```

Then it sends the transcript through the same PII redaction flow.

`POST /redact`

`POST /redact/audio`

`GET /redactions`

`GET /redactions/<id>`

`GET /health`

This is a starter app, so it stores redaction jobs in memory.

For production, I would add:

The main pattern is reusable: turn communications data into structured, safer application data before it moves deeper into your systems.

Resources:
