REPOSITORY CODING · MEDIUM
Add stable document-local aliases for sensitive values
The API can mask text, but token mode is still a placeholder. Implement document-local aliases so repeated exact values share a token and distinct values stay distinct. Keep kinds separate, preserve case and avoid storing sensitive values beyond the request.
API Contract DebuggingDocument redaction gateway
Work through a real codebase.
Choose an environment, investigate the existing implementation and use the tests to check your change. Sign in to open a workspace; execution and Ono usage follow your plan’s allowances.
Task requirements and environments
Flask · 50 minute session
- Documents contain text and annotations with start, end and kind. Offsets count Unicode code points, start is inclusive and end is exclusive. Reject invalid, boolean, negative, empty and out-of-bounds offsets before redacting.
- Supported kinds are person, email, phone and account. Each policy action is mask, token or keep; unspecified kinds default to mask. This is annotation-based redaction, not automatic entity detection.
- Merge strictly overlapping active annotations transitively; touching intervals remain separate. Ignore keep annotations when building groups. Mixed-kind groups are always masked; single-kind groups use their policy action.
- Mask replaces the whole group with [REDACTED]. Token replaces it with [KIND_N]. Assign numbers in document order, per kind. Repeated exact text shares an alias within the same document and kind. Case is significant.
- Return redacted text, ordered findings with original offsets, and distinct token counts. Never include the original sensitive value in a finding. Preserve all unannotated text, including whitespace and Unicode.
- Batch results keep input order, report invalid documents independently and reset token state for each document. The service does not persist text or aliases.