Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,5 @@ __pycache__/
*.pyc
.pytest_cache/

# internal
# internal examples
internal_examples/
27 changes: 27 additions & 0 deletions src/__tests__/unit/checks/pii.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,31 @@ describe('pii guardrail', () => {

await expect(pii({}, '', config)).rejects.toThrow('Text cannot be empty or null');
});

it('detects Korean Resident Registration Number (KR_RRN)', async () => {
const config = PIIConfig.parse({
entities: [PIIEntity.KR_RRN],
block: false,
});
const text = 'Korean RRN: 123456-1234567';

const result = await pii({}, text, config);

expect(result.tripwireTriggered).toBe(false);
expect((result.info?.detected_entities as Record<string, string[]>)?.KR_RRN).toEqual(['123456-1234567']);
expect(result.info?.checked_text).toBe('Korean RRN: <KR_RRN>');
});

it('triggers tripwire for KR_RRN when block=true', async () => {
const config = PIIConfig.parse({
entities: [PIIEntity.KR_RRN],
block: true,
});
const text = 'Korean RRN: 123456-1234567';

const result = await pii({}, text, config);

expect(result.tripwireTriggered).toBe(true);
expect((result.info?.detected_entities as Record<string, string[]>)?.KR_RRN).toEqual(['123456-1234567']);
});
});
6 changes: 6 additions & 0 deletions src/checks/pii.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ export enum PIIEntity {

// Finland
FI_PERSONAL_IDENTITY_CODE = 'FI_PERSONAL_IDENTITY_CODE',

// Korea
KR_RRN = 'KR_RRN',
}

/**
Expand Down Expand Up @@ -236,6 +239,9 @@ const DEFAULT_PII_PATTERNS: Record<PIIEntity, RegExp> = {

// Finland
[PIIEntity.FI_PERSONAL_IDENTITY_CODE]: /\b\d{6}[+-A]\d{3}[A-Z0-9]\b/g,

// Korea
[PIIEntity.KR_RRN]: /\b\d{6}-\d{7}\b/g,
};

/**
Expand Down