Skip to content

Commit 47ca743

Browse files
fix(pii): include ORGANIZATION in app-side NER set (align with server)
1 parent f8b45e6 commit 47ca743

2 files changed

Lines changed: 16 additions & 9 deletions

File tree

apps/sim/lib/guardrails/pii-entities.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ import {
1010
} from '@/lib/guardrails/pii-entities'
1111

1212
describe('NER_PII_ENTITIES', () => {
13-
it('is exactly the 4 spaCy-NER entities', () => {
14-
expect(new Set(NER_PII_ENTITIES)).toEqual(new Set(['PERSON', 'LOCATION', 'NRP', 'DATE_TIME']))
13+
it('covers the spaCy-NER entities including ORGANIZATION', () => {
14+
expect(new Set(NER_PII_ENTITIES)).toEqual(
15+
new Set(['PERSON', 'LOCATION', 'NRP', 'DATE_TIME', 'ORGANIZATION'])
16+
)
1517
})
1618
})
1719

@@ -23,6 +25,7 @@ describe('stripNerEntities', () => {
2325
'EMAIL_ADDRESS',
2426
'DATE_TIME',
2527
'US_SSN',
28+
'ORGANIZATION',
2629
'LOCATION',
2730
'PHONE_NUMBER',
2831
])

apps/sim/lib/guardrails/pii-entities.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,22 +230,26 @@ export function isEntitySupportedForLanguage(
230230
}
231231

232232
/**
233-
* The spaCy-NER entity types — the only ones detected by the NLP model, vs the
234-
* regex/checksum pattern recognizers. The block-output redaction stage is
235-
* restricted to the non-NER (regex) entities so it runs on the Presidio
236-
* spaCy-free fast path without the per-leaf NER cost. Mirrors `NER_ENTITIES` in
237-
* `apps/pii/server.py`.
233+
* Entity types produced by the spaCy NER model (vs the regex/checksum pattern
234+
* recognizers). The block-output redaction stage is restricted to the non-NER
235+
* (regex) entities so it runs on the Presidio spaCy-free fast path without the
236+
* per-leaf NER cost. Includes ORGANIZATION — which Presidio's spaCy recognizer
237+
* emits but the user-facing catalog above does not list — so it too is stripped
238+
* from block-output selections, keeping this in sync with the derived
239+
* `NER_ENTITIES` in `apps/pii/server.py`. Typed as strings because ORGANIZATION
240+
* isn't a catalog `PIIEntityType`.
238241
*/
239-
export const NER_PII_ENTITIES: ReadonlySet<PIIEntityType> = new Set<PIIEntityType>([
242+
export const NER_PII_ENTITIES: ReadonlySet<string> = new Set<string>([
240243
'PERSON',
241244
'LOCATION',
242245
'NRP',
243246
'DATE_TIME',
247+
'ORGANIZATION',
244248
])
245249

246250
/** Drop the spaCy-NER entities ({@link NER_PII_ENTITIES}) from a selection. */
247251
export function stripNerEntities(entities: readonly string[]): string[] {
248-
return entities.filter((e) => !NER_PII_ENTITIES.has(e as PIIEntityType))
252+
return entities.filter((e) => !NER_PII_ENTITIES.has(e))
249253
}
250254

251255
/**

0 commit comments

Comments
 (0)