Sonam

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

The app has two workflows:

  • submit an existing transcript
  • upload an audio file, transcribe it, then redact the transcript

What it redacts

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

  • names -> [NAME]
  • credit cards -> [CREDIT_CARD]
  • SSNs / national IDs -> [SSN]
  • phone numbers -> [PHONE]
  • emails -> [EMAIL]
  • street addresses -> [ADDRESS]
  • dates of birth -> [DOB]
  • account numbers -> [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"]
}

Enter fullscreen mode Exit fullscreen mode

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

Run it

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

Enter fullscreen mode Exit fullscreen mode

Configure .env:

TELNYX_API_KEY=your_telnyx_api_key
AI_MODEL=meta-llama/Llama-3.3-70B-Instruct
HOST=127.0.0.1

Enter fullscreen mode Exit fullscreen mode

Redact a transcript

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."
  }'

Enter fullscreen mode Exit fullscreen mode

This calls Telnyx AI Inference through:

POST /v2/ai/chat/completions

Enter fullscreen mode Exit fullscreen mode

Redact an audio file

curl -X POST http://localhost:5000/redact/audio \
  -F "[email protected]"

Enter fullscreen mode Exit fullscreen mode

For audio, the app first calls:

POST /v2/ai/audio/transcriptions

Enter fullscreen mode Exit fullscreen mode

using:

distil-whisper/distil-large-v2

Enter fullscreen mode Exit fullscreen mode

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

Routes included

  • POST /redact
  • POST /redact/audio
  • GET /redactions
  • GET /redactions/<id>
  • GET /health

Production ideas

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

For production, I would add:

  • auth
  • persistent storage
  • async processing for long recordings
  • call recording webhook ingestion
  • schema validation for model output
  • audit logs
  • custom PII categories
  • role-based access to original transcripts
  • audio masking if the original recording must be sanitized too

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

Resources: