Skip to content

Commit 8602a40

Browse files
authored
Merge pull request #95 from iotexproject/feat/pii
feat: PII redactor
2 parents df3d233 + b7ef163 commit 8602a40

File tree

9 files changed

+1500
-939
lines changed

9 files changed

+1500
-939
lines changed

.env.example

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,3 +203,10 @@ LANGFUSE_ENV=development
203203
# --- OpenMeter ---
204204
OPENMETER_API_KEY=
205205
OPENMETER_SUBJECT=my-agent
206+
207+
# --- PII Redactor ---
208+
PII_REDACTION= # true | false (default false)
209+
PII_MODEL_ID= # default jammmmmm/pii
210+
PII_DEBUG= # true | false (default false)
211+
PII_CONFIDENCE_THRESHOLD= # default 0.8
212+
PII_AGGREGATION_STRATEGY= # none | first | average | max | simple (default simple)

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"name": "eliza",
33
"scripts": {
44
"preinstall": "npx only-allow pnpm",
5-
"build": "turbo run build",
6-
"build-docker": "turbo run build",
5+
"build": "turbo run build --concurrency=5",
6+
"build-docker": "turbo run build --concurrency=5",
77
"cleanstart": "if [ -f agent/data/db.sqlite ]; then rm agent/data/db.sqlite; fi && pnpm --filter \"@elizaos/agent\" start --isRoot",
88
"cleanstart:debug": "if [ -f agent/data/db.sqlite ]; then rm agent/data/db.sqlite; fi && cross-env NODE_ENV=development VERBOSE=true DEBUG=eliza:* pnpm --filter \"@elizaos/agent\" start --isRoot",
99
"start": "pnpm --filter \"@elizaos/agent\" start --isRoot",
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { describe, it, expect, beforeAll } from "vitest";
2+
import { PII } from "@elizaos/core";
3+
4+
describe.skip("PII redaction", () => {
5+
let pii: PII;
6+
7+
beforeAll(async () => {
8+
process.env.PII_MODEL_ID = process.env.PII_MODEL_ID || "jammmmmm/pii";
9+
process.env.PII_AGGREGATION_STRATEGY =
10+
process.env.PII_AGGREGATION_STRATEGY || "simple";
11+
process.env.PII_DEBUG = "true";
12+
pii = await PII.create();
13+
}, 120_000);
14+
15+
async function expectRedacted(input: string, mustNotContain: string[]) {
16+
const result = await pii.redact(input);
17+
expect(result).not.toBeNull();
18+
if (!result) return;
19+
expect(result.entities.length).toBeGreaterThan(0);
20+
for (const s of mustNotContain) {
21+
expect(result.redactedText).not.toContain(s);
22+
}
23+
}
24+
25+
it("redacts email addresses", async () => {
26+
const input = "Contact me at alice.smith@example.org for details.";
27+
await expectRedacted(input, ["alice.smith", "example.org"]);
28+
}, 120_000);
29+
30+
it("redacts names", async () => {
31+
const input = "My name is John Doe.";
32+
await expectRedacted(input, ["John", "Doe"]);
33+
}, 120_000);
34+
35+
it("redacts phone numbers", async () => {
36+
const input = "Call me at +1 (415) 555-2671 tomorrow.";
37+
await expectRedacted(input, ["415", "555-2671"]);
38+
}, 120_000);
39+
40+
it("redacts crypto wallet addresses (BTC)", async () => {
41+
const input =
42+
"Donate BTC to bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kygt080";
43+
await expectRedacted(input, [
44+
"bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kygt080",
45+
]);
46+
}, 120_000);
47+
48+
it("redacts crypto wallet addresses (ETH)", async () => {
49+
const input =
50+
"Send ETH to 0x742d35Cc6634C0532925a3b844Bc454e4438f44e please.";
51+
await expectRedacted(input, [
52+
"0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
53+
]);
54+
}, 120_000);
55+
56+
it("redacts private keys (hex)", async () => {
57+
const key =
58+
"4f3edf983ac636a65a842ce7c78d9aa706d3b113bce036f8e6f2b59e6fc9b8a7";
59+
const input = `Never share your private key: ${key}`;
60+
await expectRedacted(input, [key]);
61+
}, 120_000);
62+
63+
it("redacts home addresses", async () => {
64+
const input =
65+
"Ship it to 1600 Amphitheatre Parkway, Mountain View, CA 94043.";
66+
await expectRedacted(input, ["1600 Amphitheatre", "94043"]);
67+
}, 120_000);
68+
});

packages/core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
"@ai-sdk/deepseek": "^0.1.15",
6868
"@ai-sdk/openai": "^1.3.21",
6969
"@ai-sdk/xai": "^1.2.13",
70+
"@huggingface/transformers": "3.0.2",
7071
"@openrouter/ai-sdk-provider": "^0.4.5",
7172
"@opentelemetry/auto-instrumentations-node": "^0.62.0",
7273
"@opentelemetry/sdk-node": "^0.203.0",

0 commit comments

Comments
 (0)