Cms Ai Pii Redaction Service — independently scanned and version-tracked by SaferSkills.
SaferSkills independently audited Cms Ai Pii Redaction Service (Agent Skill) and scored it 100/100 (green). The audit ran 55 deterministic rules across Security, Supply Chain, Maintenance, Transparency, and Community; it found 0 high-severity and 0 lower-severity findings. The full rule-by-rule trace and per-finding evidence are below. Free, methodology-open.
Findings & checks · 0 flagged
Every scanned point with the score it earned and what moved between them.
First recorded scan — no prior version to compare against.
The primary manifest — the file an agent reads to learn what this artifact does.
A self-contained service for extracting text from documents, detecting and redacting PII across multiple languages, summarizing the clean output, and exposing all capabilities to AI agents via MCP. All activity is traced to Azure Log Analytics Workspace.
├── src/
│ ├── api.py # FastAPI app initialisation + router registration
│ ├── models.py # All Pydantic request/response DTOs
│ ├── constants.py # Env var keys + hardcoded constants
│ ├── errors/
│ │ ├── exceptions.py # Domain exceptions
│ │ └── exception_handlers.py # Global HTTP error handlers
│ ├── routers/
│ │ ├── health.py # GET /health, /entities, /languages
│ │ ├── redaction.py # POST /redact, /process
│ │ ├── summarization.py # POST /summarize (quota enforced)
│ │ └── patterns.py # GET|POST /patterns, DELETE /patterns/{id}, POST /patterns/test
│ ├── redaction/
│ │ ├── extractor.py # File → plain text
│ │ ├── redactor.py # Presidio PII detection + redaction
│ │ └── custom_patterns.py # Per-business-unit pattern CRUD + persistence
│ ├── summarization/
│ │ └── summarizer.py # Claude-powered summarization
│ └── util/
│ ├── auth.py # API key dependency
│ ├── logging_config.py # Structured logging + Azure Log Analytics handler
│ ├── rate_limit.py # slowapi limiter + per-key identification
│ └── quota.py # Daily LLM quota tracker (in-memory / Redis)
│
├── mcp_server/ # MCP server — AI agent access layer
│ ├── app.py # Shared FastMCP instance
│ ├── server.py # ASGI app factory (SSE + auth middleware + /health)
│ ├── middleware.py # MCP_API_KEY auth middleware
│ └── tools/
│ ├── redact.py # redact_text, list_entities, list_languages
│ ├── summarize.py # summarize_text
│ └── patterns.py # list/add/delete/test custom patterns
│
├── tests/
│ ├── conftest.py
│ ├── unit/ # Mocked, no external services needed
│ ├── integration/ # Full app via TestClient
│ └── utils/ # Shared fixtures + mock data
│
├── data/
│ └── custom_patterns.json # Persisted user-defined patterns (auto-created)
│
├── quota_config.json # Per-team rate limits and LLM quotas
├── index.html # Single-page UI (no build step)
├── main.py # REST entry point shim → src.api:api
├── mcp_main.py # MCP SSE entry point → mcp_server.server:app (port 8001)
├── mcp_stdio.py # MCP stdio entry point → for Claude Desktop
├── Dockerfile # Single image, two startup commands
├── docker-compose.yml # REST + MCP as separate scalable services
├── requirements.txt
└── .env.examplepython -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
python -m spacy download en_core_web_lgcp .env.example .env
# Edit .env — set ANTHROPIC_API_KEY and optionally Azure + auth credentialsuvicorn src.api:api --host 0.0.0.0 --port 8000 --reloaduvicorn mcp_main:app --host 0.0.0.0 --port 8001 --reloadopen index.html
# or: python -m http.server 3000 then visit http://localhost:3000The UI expects the backend at http://localhost:8000.docker compose up # start REST + MCP
docker compose up --scale mcp-server=3 # scale MCP independentlyBrowser (index.html) AI Agents / Claude Desktop
│ │
│ REST (port 8000) │ MCP stdio / SSE (port 8001)
▼ ▼
FastAPI src/api.py MCP Server mcp_server/server.py
│ │
├── src/routers/ ├── mcp_server/tools/redact.py
├── src/redaction/ ├── mcp_server/tools/summarize.py
├── src/summarization/ └── mcp_server/tools/patterns.py
└── src/util/ │
├── rate_limit.py │
├── quota.py │
└── logging_config.py │
│ │
└──────── shared ───────────────┘
src/redaction/
src/summarization/
src/redaction/custom_patterns.py
│
Azure Log Analytics| Transport | Entry point | Port | Used by |
|---|---|---|---|
| REST (HTTP) | main.py → src.api:api | 8000 | Browser UI, direct REST clients |
| MCP SSE | mcp_main.py → mcp_server.server:app | 8001 | Remote AI agents, Trimble-wide access |
| MCP stdio | mcp_stdio.py | — | Claude Desktop (local subprocess) |
Both MCP transports expose the same 9 tools backed by the same src/ services.
Router / Tool → Service → (external call if needed)
│ └→ logger.info(..., extra={trace fields})
│ └→ AzureLogAnalyticsHandler → Log Analytics
│
├── Rate limit check (slowapi — burst guard per API key)
└── Quota check (quota.py — daily LLM calls per team)| Variable | Required | Description |
|---|---|---|
ANTHROPIC_API_KEY | No | Claude API key — omit to use extractive summarization fallback |
API_KEY | No | REST API key — all requests must include it in X-API-Key header. Unset = auth disabled |
API_KEY_HEADER | No | Header name for REST API key (default: X-API-Key) |
MCP_API_KEY | No | MCP server key — agents must send Authorization: Bearer <key> or X-MCP-Key: <key>. Unset = auth disabled |
REDIS_URL | No | Redis connection URL for distributed rate limiting across pods (e.g. redis://localhost:6379/0). Unset = in-memory |
AZURE_LOG_WORKSPACE_ID | No | Log Analytics workspace ID — omit to log to stdout only |
AZURE_LOG_WORKSPACE_KEY | No | Log Analytics primary/secondary shared key (base64) |
AZURE_LOG_TYPE | No | Custom table name in Log Analytics (default: PIIRedactionTrace) |
The service enforces two independent limits to prevent abuse and control LLM costs.
Applied per API key (falls back to IP when auth is disabled). Each key gets its own counter bucket — teams don't share limits.
| Endpoint | Default limit |
|---|---|
POST /redact | 60 requests / minute |
POST /process | 30 requests / hour |
POST /summarize | 10 requests / hour |
When exceeded, the response is HTTP 429 with standard X-RateLimit-* headers.
Tracks Claude API calls per team per UTC day. Resets automatically at midnight — no cron job needed. Uses in-memory storage by default; set REDIS_URL for multi-pod deployments.
| Team | Summarize calls / day |
|---|---|
| Default (unlisted key) | 50 |
| Construction / Agriculture / Geospatial | 200 |
| HR / Legal | 100 |
| Admin | 1000 |
Every /summarize response includes:
X-RateLimit-Limit: 10
X-RateLimit-Remaining: 7
X-Quota-Summarize-Limit: 50
X-Quota-Summarize-Used: 12
X-Quota-Summarize-Remaining: 38
X-Quota-Reset: 2026-04-06quota_config.json)Edit quota_config.json at the project root. Changes take effect on server restart.
{
"default": {
"requests_per_minute": 60,
"process_per_hour": 30,
"summarize_per_day": 50
},
"teams": {
"their-api-key": {
"name": "New Team",
"requests_per_minute": 120,
"process_per_hour": 60,
"summarize_per_day": 200
}
}
}# .env
REDIS_URL=redis://your-redis-host:6379/0Rate limit counters are then shared across all pods — no per-pod drift.
# Single call — inspect quota headers
curl -i -X POST http://localhost:8000/summarize \
-H "Content-Type: application/json" \
-d '{"redacted_text": "A person works at a company.", "length": "short"}' \
| grep -E "X-Quota|X-RateLimit|HTTP"
# Python test — 6 calls against a quota of 3 (set summarize_per_day: 3 in quota_config.json)
python3 - << 'EOF'
import httpx, time
for i in range(6):
r = httpx.post("http://localhost:8000/summarize",
json={"redacted_text": "Test text.", "length": "short"}, timeout=15)
used = r.headers.get("X-Quota-Summarize-Used", "?")
rem = r.headers.get("X-Quota-Summarize-Remaining", "?")
lim = r.headers.get("X-Quota-Summarize-Limit", "?")
print(f"Call {i+1}: HTTP {r.status_code} | quota {used}/{lim} | remaining {rem}")
time.sleep(0.2)
EOFExpected output:
Call 1: HTTP 200 | quota 1/3 | remaining 2
Call 2: HTTP 200 | quota 2/3 | remaining 1
Call 3: HTTP 200 | quota 3/3 | remaining 0
Call 4: HTTP 429 | quota 3/3 | remaining 0 ← blocked
Call 5: HTTP 429 | quota 3/3 | remaining 0
Call 6: HTTP 429 | quota 3/3 | remaining 0The MCP server runs as a separate process on port 8001 and exposes PII redaction capabilities to AI agents via the Model Context Protocol. It shares all business logic with the REST API — only the transport layer differs.
| Tool | Description |
|---|---|
redact_text | Detect and redact PII from plain text (all operators, all languages) |
list_entities | List all supported PII entity types including active custom patterns |
list_languages | List supported languages and spaCy model install status |
summarize_text | Summarize PII-free text via Claude (or extractive fallback) |
list_business_units | List the four supported business units |
list_patterns | List patterns filtered by business unit |
add_custom_pattern | Create and persist a new custom PII pattern |
delete_custom_pattern | Delete a user-defined pattern by ID |
test_regex_pattern | Test regex(es) against sample text without persisting |
# SSE transport (remote agents)
Authorization: Bearer <MCP_API_KEY>
# or
X-MCP-Key: <MCP_API_KEY>The /health endpoint on port 8001 is always public (no auth required).
~/Library/Application Support/Claude/claude_desktop_config.json{
"mcpServers": {
"pii-redaction": {
"command": "/path/to/project/.venv/bin/python3",
"args": ["/path/to/project/mcp_stdio.py"]
}
}
}pii-redaction.{
"mcpServers": {
"pii-redaction": {
"url": "http://mcp-server:8001/sse",
"headers": {
"Authorization": "Bearer your-mcp-secret-key"
}
}
}
}Using pii-redaction, redact then summarize:
"John Smith (EMP-10029) submitted bid BID-2024-008821 from [email protected].
Contract CNT-2024-REF00812, SSN 123-45-6789."Using pii-redaction, add a custom pattern for construction:
entity CONSTR_PROJECT_CODE, regex \bPROJ-[A-Z]{2}-\d{4}-\d{4}\b,
context "project code, proj id". Then redact: "Project PROJ-TX-2024-0091 assigned."Per-business-unit regex patterns extend the built-in Presidio recognizers. Patterns persist to data/custom_patterns.json and activate on the next redact call.
| Unit | ID | Built-in entities |
|---|---|---|
| Construction | construction | CONSTR_BID_NUMBER, CONSTR_PERMIT_NUMBER, CONSTR_SUBCONTRACTOR_ID, CONSTR_SITE_CODE |
| Agriculture | agriculture | AGRI_FARM_ID, AGRI_PARCEL_ID, AGRI_YIELD_RECORD |
| Geospatial | geospatial | GEO_SURVEY_LICENSE, GEO_CONTROL_POINT_ID |
| HR / Legal | hr_legal | HR_EMPLOYEE_ID, HR_COST_CODE, HR_CONTRACT_REF |
Click Custom Patterns (gear icon) in the top-right header of the UI:
# List all patterns for a unit
curl http://localhost:8000/patterns?unit=construction
# Add a custom pattern
curl -X POST http://localhost:8000/patterns \
-H "Content-Type: application/json" \
-d '{
"entity_type": "CONSTR_PROJECT_CODE",
"label": "Project Code",
"unit": "construction",
"patterns": ["\\bPROJ-[A-Z]{2}-\\d{4}-\\d{4}\\b"],
"context": ["project code", "proj id"],
"score": 0.85
}'
# Test a regex
curl -X POST http://localhost:8000/patterns/test \
-H "Content-Type: application/json" \
-d '{"patterns": ["\\bPROJ-[A-Z]{2}-\\d{4}\\b"], "sample_text": "Project PROJ-TX-2024 approved"}'
# Delete a pattern
curl -X DELETE http://localhost:8000/patterns/{id}Every API action emits a structured trace record via Python's standard logging module.
AZURE_LOG_WORKSPACE_ID and AZURE_LOG_WORKSPACE_KEY are set. Records land in PIIRedactionTrace_CL.| Field | Type | Description | ||
|---|---|---|---|---|
timestamp | ISO 8601 | UTC time of the event | ||
level | string | Log level (INFO, WARNING, ERROR) | ||
event_type | string | process \ | redact \ | summarize |
client_ip | string | Caller IP (respects X-Forwarded-For) | ||
session_id | string | UUID grouping related events for one document | ||
filename | string | Uploaded filename (process events only) | ||
file_type | string | File extension (pdf, txt, etc.) | ||
detected_language | string | ISO 639-1 code auto-detected by langdetect | ||
entity_counts | object | {"PERSON": 2, "EMAIL_ADDRESS": 1, ...} | ||
pii_count | int | Total PII spans found | ||
operator | string | Redaction style used (replace, mask, etc.) | ||
text_length | int | Character count of input text | ||
summarization_run | bool | Whether Claude was called | ||
llm_model | string | Model ID used for summarization |
// All PII processing events in the last 24 hours
PIIRedactionTrace_CL
| where TimeGenerated > ago(24h)
| where event_type_s == "process"
| project TimeGenerated, client_ip_s, filename_s, detected_language_s, pii_count_d
// Top PII types detected this week
PIIRedactionTrace_CL
| where TimeGenerated > ago(7d)
| mv-expand entity_counts_s
| summarize total = sum(todouble(entity_counts_s)) by tostring(entity_counts_s)
| order by total desc
// Summarize quota usage per team key
PIIRedactionTrace_CL
| where TimeGenerated > ago(1d)
| where event_type_s == "summarize"
| summarize calls = count() by client_ip_s
| order by calls descGET /health{ "status": "ok" }GET /entitiesReturns all supported PII entity types including active custom patterns.
GET /languagesReturns supported languages and whether their spaCy NLP model is installed.
POST /processUpload a file, extract text, auto-detect language, and redact PII.
Request — multipart/form-data
| Field | Type | Description |
|---|---|---|
file | file | .txt, .pdf, .docx, .doc, .csv, .md |
language | string | ISO 639-1 code or "auto" (default) |
session_id | string | Optional — groups trace events |
curl -X POST http://localhost:8000/process \
-F "[email protected]" -F "language=auto"Response
{
"original_text": "My name is John Smith...",
"redacted_text": "My name is <PERSON>...",
"entities_found": [{"type": "PERSON", "start": 11, "end": 21, "score": 0.85, "original": "John Smith"}],
"entity_counts": {"PERSON": 1},
"detected_language": "en",
"filename": "document.pdf",
"file_type": "pdf",
"session_id": "a1b2c3d4-..."
}POST /redactRedact PII from raw text.
| Field | Type | Default | Description | |||
|---|---|---|---|---|---|---|
text | string | required | Plain text to redact | |||
language | string | "auto" | ISO 639-1 code or "auto" | |||
entities | list | all | Entity IDs to detect | |||
operator | string | "replace" | replace \ | redact \ | mask \ | hash |
session_id | string | — | Groups trace events |
curl -X POST http://localhost:8000/redact \
-H "Content-Type: application/json" \
-d '{"text": "Contact Sarah at [email protected]", "operator": "mask"}'POST /summarizeSummarize PII-free text via Claude. Subject to hourly burst limit and daily LLM quota.
| Field | Type | Default | Description | ||
|---|---|---|---|---|---|
redacted_text | string | required | PII-free text | ||
length | string | "short" | short \ | medium \ | detailed |
session_id | string | — | Groups trace events |
Returns HTTP 429 when daily quota is exceeded. Quota headers are included on every response.
GET /patternsList custom PII patterns. Filter with ?unit=construction.
GET /patterns/unitsList the four business units.
POST /patternsCreate a custom pattern.
| Field | Type | Description | |||
|---|---|---|---|---|---|
entity_type | string | Uppercase ID e.g. CONSTR_PROJECT_CODE | |||
label | string | Human-readable label | |||
unit | string | construction \ | agriculture \ | geospatial \ | hr_legal |
patterns | list | Regex pattern strings | |||
context | list | Context keywords (optional) | |||
score | float | Confidence 0.0–1.0 (default 0.80) |
DELETE /patterns/{id}Delete a user-defined pattern. Returns 403 for built-in patterns.
POST /patterns/testTest regex patterns against sample text without persisting.
Language is auto-detected via langdetect. The detected language drives spaCy NLP (names, locations, orgs). Country-specific IDs use regex and work regardless of which NLP model is installed.
| Region | Languages | NLP model |
|---|---|---|
| Default | English | en_core_web_lg ✓ |
| Europe | German, French, Spanish, Dutch, Italian, Swedish | *_core_news_lg |
| Americas | Portuguese (Brazil), Spanish (LATAM) | pt/es_core_news_lg |
| APAC | Japanese, Chinese, Korean | ja/zh/xx models |
python -m spacy download de_core_news_lg # German
python -m spacy download fr_core_news_lg # French
python -m spacy download pt_core_news_lg # PortugueseBoth services share the same Docker image. Scale them independently:
# Scale MCP server for more concurrent agent connections
docker compose up --scale mcp-server=3
# Scale REST API for higher HTTP throughput
docker compose up --scale rest-api=2For Azure Container Apps:
az containerapp update --name mcp-server \
--min-replicas 2 --max-replicas 20Add REDIS_URL when running multiple REST API pods so rate limit counters are shared across replicas.# Run unit tests
pytest tests/unit/ -v
# Run integration tests
pytest tests/integration/ -v
# Run with coverage
pytest tests/unit/ --cov=src --cov-report=html
# Lint and format
ruff check --fix src tests mcp_server
black src tests mcp_server
isort src tests mcp_server~30 seconds. Free. No account. Every finding cites a rule and a line of evidence.