Sign in

PII Redactor

Text and image redaction service for sensitive data protection.

pii-redactor
servicepiiredactionpresidio

Updated 2026-11-03

Verified 2026-11-03

PII Redactor is a stateless FastAPI service that removes sensitive data from text and images. It uses Microsoft Presidio for text analysis and anonymization, and Presidio image redaction for OCR-based image masking. It also provides ADK-compatible batch masking for agent conversations.

Responsibilities

  • Redact configured entity types from text payloads.
  • Redact PII from uploaded image files.
  • Mask ADK text batches with placeholder mappings that stay consistent across a conversation.
  • Enforce Cosmos authentication and authorization before redaction.
  • Expose health, readiness, metrics, and OpenAPI documentation endpoints.

Runtime

AreaDetails
Repositorycosmos-pii-redactor
FrameworkFastAPI
Core librariespresidio-analyzer, presidio-anonymizer, presidio-image-redactor
Default port8000 (2 workers by default)
StateStateless
TelemetryCloud deployments run under opentelemetry-instrument, which reports to Azure Monitor through APPLICATIONINSIGHTS_CONNECTION_STRING

API

MethodPathPurpose
POST/v1/redact-textRedact PII from text.
POST/v1/redact-imagesRedact PII from one or more images. Returns 204 when no PII is found.
POST/v1/adk/mask-textMask an ADK text batch and return masked items, the cumulative placeholder mapping, counters, and stats. Payloads over MAX_TEXT_BYTES return 413.
GET/healthzLiveness probe.
GET/readyzReadiness probe.
GET/metricsPrometheus metrics.
GET/docsOpenAPI UI.

Authentication And Authorization

Requests require:

  • Authorization: Bearer <token>
  • X-Org-Id: <org uuid>

The service validates JWTs through User Service JWKS. Service-token calls that act for an end user must include X-On-Behalf-Of-User-Id.

Authorization is checked through User Service PDP using the pii.redact action.

Configuration

Important environment variables:

VariablePurpose
AUTH_ENABLEDEnables or disables auth checks (default true).
USER_SERVICE_URLUser Service URL used for JWKS and PDP calls; required when auth is enabled.
COSMOS_SERVICE_AUDIENCEExpected service audience (default cosmos-pii-redactor).
AUTHZ_ACTIONPDP action (default pii.redact).
AUTHZ_TIMEOUT_SECONDSPDP timeout (default 5 seconds).
MAX_TEXT_BYTESMaximum accepted text payload size (default 5 MiB).
MAX_IMAGE_BYTESMaximum accepted image payload size (default 9 MiB).
DEFAULT_ENTITIESDefault Presidio entity set.
DEFAULT_SCORE_THRESHOLDPresidio score threshold (default 0.5).
SPACY_MODELspaCy model used by Presidio (default en_core_web_lg).
TESSERACT_LANGOCR language for image redaction (default eng).
OCR_DPIOCR rendering DPI (default 200).
OBSERVER_KAFKA_ENABLED, OBSERVER_KAFKA_TOPICOptional cost events for ADK masking sent to Observer (default disabled, topic observer-cost-events).
  • cosmos-mediagateway can call PII Redactor during screen-capture ingestion.
  • cosmos-adk-v3 calls /v1/adk/mask-text for conversation PII masking.
  • cosmos-user-v3 provides JWKS validation material and PDP authorization.

Changelog

See PII Redactor Changelog for verified documentation and service-surface changes.