Skip to content

Commit 67b303f

Browse files
fix(guardrails): correct sidecar port (5001) + README for combined image
The combined Presidio image (docker/pii.Dockerfile) serves /analyze + /anonymize on a single port 5001 with native VIN + multi-language recognizers. Fix the PRESIDIO_URL default (was 5002) and rewrite the README, which still described two stock containers and a TS VIN recognizer.
1 parent de32214 commit 67b303f

3 files changed

Lines changed: 18 additions & 16 deletions

File tree

apps/sim/lib/core/config/env.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ export const env = createEnv({
311311
PORT: z.number().optional(), // Main application port
312312
INTERNAL_API_BASE_URL: z.string().optional(), // Optional internal base URL for server-side self-calls; must include protocol if set (e.g., http://sim-app.namespace.svc.cluster.local:3000)
313313
ALLOWED_ORIGINS: z.string().optional(), // CORS allowed origins
314-
PRESIDIO_URL: z.string().optional(), // Presidio sidecar base URL serving /analyze + /anonymize (default http://localhost:5002)
314+
PRESIDIO_URL: z.string().optional(), // Presidio sidecar base URL serving /analyze + /anonymize (default http://localhost:5001)
315315

316316
// OAuth Integration Credentials - All optional, enables third-party integrations
317317
GOOGLE_CLIENT_ID: z.string().optional(), // Google OAuth client ID for Google services

apps/sim/lib/guardrails/README.md

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,29 @@ For **hallucination detection**, you'll need:
1919
- A knowledge base with documents
2020
- An LLM provider API key (or use hosted models)
2121

22-
### PII Detection (Presidio sidecars)
22+
### PII Detection (Presidio sidecar)
2323

24-
PII detection runs against two long-lived **Microsoft Presidio sidecar containers** reached over
25-
HTTP — the analyzer (NLP detection) and the anonymizer (masking). In deployment they run alongside the
26-
app container in the same ECS task; locally, run the official images:
24+
PII detection runs against **one** long-lived Presidio sidecar — a combined service (built from
25+
`docker/pii.Dockerfile`, source in `apps/pii/server.py`) that constructs a warm `AnalyzerEngine` +
26+
`AnonymizerEngine` once and exposes both `/analyze` and `/anonymize` (plus `/health`) on a single
27+
port. In deployment it runs alongside the app container in the same ECS task; locally, build and run
28+
it:
2729

2830
```bash
29-
docker run -d -p 5002:3000 mcr.microsoft.com/presidio-analyzer:latest
30-
docker run -d -p 5001:3000 mcr.microsoft.com/presidio-anonymizer:latest
31+
docker build -f docker/pii.Dockerfile -t sim-pii .
32+
docker run -d -p 5001:5001 sim-pii
3133
```
3234

33-
Point the app at them (defaults shown):
35+
Point the app at it (default shown):
3436

3537
```bash
36-
PRESIDIO_ANALYZER_URL=http://localhost:5002
37-
PRESIDIO_ANONYMIZER_URL=http://localhost:5001
38+
PRESIDIO_URL=http://localhost:5001
3839
```
3940

40-
VIN recognition (check-digit validated) is implemented in TypeScript (`vin.ts`) and never sent to the
41-
sidecars. No Python or local venv is required.
41+
The image bakes in the recognizers itself — a check-digit-validated **VIN** recognizer and
42+
multi-language NLP models (en/es/it/pl/fi) — so the app is a thin HTTP client (`validate_pii.ts`) with
43+
no Python or local venv. The redaction language is configured per rule (Data Retention) and defaults
44+
to English.
4245

4346
## Usage
4447

@@ -97,9 +100,8 @@ See [Presidio documentation](https://microsoft.github.io/presidio/supported_enti
97100
- `validate_json.ts` - JSON validation (TypeScript)
98101
- `validate_regex.ts` - Regex validation (TypeScript)
99102
- `validate_hallucination.ts` - Hallucination detection with RAG + LLM scoring (TypeScript)
100-
- `validate_pii.ts` - PII detection client: calls the Presidio analyzer/anonymizer sidecars (TypeScript)
101-
- `vin.ts` - Check-digit-validated VIN recognizer (TypeScript)
102-
- `pii-entities.ts` - Client-safe PII entity catalog
103+
- `validate_pii.ts` - PII detection client: calls the Presidio sidecar's /analyze + /anonymize (TypeScript)
104+
- `pii-entities.ts` - Client-safe PII entity + language catalog (shared by the block and Data Retention)
103105
- `mask-client.ts` - Internal HTTP client for batch PII masking from the log-redaction persist path
104106
- `validate.test.ts` - Test suite for JSON and regex validators
105107

apps/sim/lib/guardrails/validate_pii.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const REQUEST_TIMEOUT_MS = 45_000
1212
const MASK_CONCURRENCY = 8
1313

1414
/** Single Presidio sidecar serving both /analyze and /anonymize (VIN is native there). */
15-
const PRESIDIO_URL = env.PRESIDIO_URL || 'http://localhost:5002'
15+
const PRESIDIO_URL = env.PRESIDIO_URL || 'http://localhost:5001'
1616

1717
export interface PIIValidationInput {
1818
text: string

0 commit comments

Comments
 (0)