MCPcopy Create free account
hub / github.com/simstudioai/sim / analyzeBatch

Function analyzeBatch

apps/sim/lib/guardrails/validate_pii.ts:79–97  ·  view source on GitHub ↗

* Detect PII spans for many texts in a single analyzer pass (spaCy `nlp.pipe`), * the batched counterpart to analyze. Returns one span array per input, * in order. An empty `entityTypes` ⇒ detect all. Throws on transport/HTTP failure.

(
  texts: string[],
  entityTypes: string[],
  language: string
)

Source from the content-addressed store, hash-verified

77 * in order. An empty `entityTypes` ⇒ detect all. Throws on transport/HTTP failure.
78 */
79async function analyzeBatch(
80 texts: string[],
81 entityTypes: string[],
82 language: string
83): Promise<AnalyzerSpan[][]> {
84 const entities = entityTypes.length > 0 ? entityTypes : undefined
85
86 // boundary-raw-fetch: internal call to the Presidio analyzer service via PII_URL
87 const response = await fetch(`${PII_URL}/analyze_batch`, {
88 method: 'POST',
89 headers: { 'content-type': 'application/json' },
90 body: JSON.stringify({ texts, language, ...(entities ? { entities } : {}) }),
91 })
92 if (!response.ok) {
93 const detail = await response.text().catch(() => '')
94 throw new Error(`Presidio analyze failed (${response.status}): ${detail.slice(0, 200)}`)
95 }
96 return (await response.json()) as AnalyzerSpan[][]
97}
98
99interface AnonymizeBatchItem {
100 text: string

Callers 1

maskPIIBatchFunction · 0.85

Calls 1

textMethod · 0.80

Tested by

no test coverage detected