Summary

Adds PiiRedactor class to the JS SDK (@arakoodev/edgechains.js/ai) that integrates with AWS Comprehend to detect and redact personally identifiable information (PII) from text — useful for sanitizing prompts before sending them to LLMs.

/claim #290

What’s included

PiiRedactor class (src/ai/src/lib/aws-comprehend/pii-redactor.ts)

  • detectPiiEntities() — detect PII entities with optional type filtering
  • containsPii() — quick boolean check for PII presence
  • redact() — redact PII with configurable mask modes:
    • fixed (default): Replace with [REDACTED] or custom value
    • char: Replace each character with a mask character
    • label: Replace with entity type label (e.g., [SSN], [NAME])
  • pipe()/chain() — fluent chaining API for composing with Endpoint classes

Chainable with existing Endpoint classes (as observables)

import { PiiRedactor } from "@arakoodev/edgechains.js/ai";
import { OpenAI } from "@arakoodev/edgechains.js/ai";

const redactor = new PiiRedactor({ region: "us-east-1" });
const openai = new OpenAI({ apiKey: "..." });

// Chain: redact PII → send to LLM
const response = await redactor
  .pipe("My SSN is 123-45-6789, help me with taxes")
  .chain((result) => openai.chat({ prompt: result.redactedText }));

// LLM receives: "My [REDACTED], help me with taxes"

Test cases

Full test suite in src/ai/src/tests/piiRedactor.test.ts:

  • 20 tests covering all methods
  • Tests for constructor options (region, credentials)
  • Tests for all mask modes
  • Tests for pipe/chain chaining behavior
  • Tests for OpenAI integration pattern

Example

Working example in examples/pii-redaction/:

  • Demonstrates all redaction modes
  • Shows chaining pattern with endpoints
  • Includes README with setup instructions

Test Results

PASS src/ai/src/tests/piiRedactor.test.ts
  PiiRedactor
    detectPiiEntities
      ✓ should detect PII entities in text
      ✓ should return empty entities when no PII found
      ✓ should filter entities by type when piiEntityTypes is specified
      ✓ should default to English language code
      ✓ should use custom language code when provided
    containsPii
      ✓ should return true when PII is present
      ✓ should return false when no PII is present
    redact
      ✓ should redact PII using fixed mask (default)
      ✓ should redact PII using char mask
      ✓ should redact PII using label mask
      ✓ should use custom fixed mask value
      ✓ should build entity map for replacements
      ✓ should handle entities with undefined offsets gracefully
    redactPrompt
      ✓ should return only the redacted text string
    pipe and chain (observable chaining)
      ✓ should pipe text and await redacted result
      ✓ should chain redaction result into another async function
      ✓ should chain into OpenAI-like endpoint call
    constructor
      ✓ should use provided region
      ✓ should default to us-east-1 when no region specified
      ✓ should use AWS_REGION env var when set

Test Suites: 1 passed, 1 total
Tests:       20 passed, 20 total

Dependencies

  • @aws-sdk/client-comprehend — AWS SDK for Comprehend API

Loom Video

Will add loom.com demo video after initial review.

Claim

Total prize pool $75
Total paid $0
Status Pending
Submitted April 10, 2026
Last updated April 10, 2026

Contributors

AL

Alex Smith

@alexanderxfgl-bit

100%

Sponsors

AR

Arakoo.ai

@arakoodev

$25
GI

gittare

@gittare

$50