Memory & Context

Privacy & Security

Data protection and privacy controls for memory systems using regex redaction patterns

What is Memory Privacy?

Compozy's privacy system provides intelligent data protection for memory operations, automatically detecting and redacting sensitive information before storage. The system uses regex-based pattern matching with built-in security protections to prevent accidental exposure of personal data, credentials, or proprietary information while maintaining memory performance and reliability.

Core Privacy Features

Pattern-Based Redaction

Intelligent regex patterns that identify and redact sensitive data like SSNs, credit cards, and emails automatically

ReDoS Protection

Built-in validation prevents Regular Expression Denial of Service attacks with timeout and complexity checks

Message Type Filtering

Configurable filtering prevents certain message types from being stored in memory entirely

Circuit Breaker Safety

Automatic failure recovery system that prevents cascading errors from affecting memory operations

Setting Up Privacy Protection

1

Configure Privacy Policy

Add a privacy_policy section to your memory resource configuration with redaction patterns and settings.

2

Define Redaction Patterns

Specify regex patterns that match sensitive data you want to protect, such as SSNs, credit cards, and emails.

3

Set Redaction Replacement

Choose how redacted content appears in storage using the default_redaction_string property.

4

Test Pattern Safety

Validate that your patterns are safe and won't cause performance issues or ReDoS attacks.

Basic Configuration Example

resource: memory
id: secure_memory
description: Memory with privacy protection

privacy_policy:
  redact_patterns:
    # Social Security Numbers (XXX-XX-XXXX)
    - '\b\d{3}-\d{2}-\d{4}\b'
    # Credit card numbers (various formats)
    - '\b\d{4}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{3,6}\b'
    # Email addresses
    - '\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b'
    # Phone numbers (US formats)
    - '\b(?:\+?1[-.\s]?)?\(?[2-9]\d{2}\)?[-.\s]?\d{3}[-.\s]?\d{4}\b'
    # Account numbers
    - '\baccount\s*#?\s*\d{6,12}\b'

  # Replacement text for redacted content
  default_redaction_string: "[REDACTED]"

Common Redaction Patterns

Protect financial information including credit cards, SSNs, and account numbers:

privacy_policy:
  redact_patterns:
    # Credit card numbers (various formats)
    - '\b\d{4}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{3,6}\b'
    # Social Security Numbers (XXX-XX-XXXX)
    - '\b\d{3}-\d{2}-\d{4}\b'
    # Bank routing numbers
    - '\b\d{2}-\d{7}\b'
    # Account numbers
    - '\baccount\s*#?\s*\d{6,12}\b'

These patterns handle common financial data formats while avoiding false positives with other number sequences.

Message Type Filtering

Beyond pattern-based redaction, you can prevent entire categories of messages from being stored in memory. This provides an additional layer of privacy protection by filtering messages based on their type or role.

Configuration

privacy_policy:
  non_persistable_message_types:
    - system          # System messages and internal communications
    - tool_internal   # Internal tool-to-tool communications
    - debug           # Debug information and diagnostic data
    - error           # Error messages and stack traces
    - authentication  # Authentication-related messages
    - admin           # Administrative messages
    - temporary       # Temporary or transient messages

Filtering Examples:

  • Message with role "system" → Not stored in memory
  • Message with role "user" → Stored normally (with redaction applied)
  • Message with role "debug" → Not stored in memory

This filtering happens before redaction processing, providing efficient protection for sensitive message categories. Learn more about message handling in the memory operations guide.

Pattern Safety & ReDoS Protection

Compozy includes built-in validation to prevent Regular Expression Denial of Service (ReDoS) attacks. The privacy manager automatically rejects unsafe patterns that could cause performance issues, memory exhaustion, or system crashes through catastrophic backtracking.

These patterns are optimized for performance and security:

privacy_policy:
  redact_patterns:
    # Safe patterns - specific and bounded
    - '\b\d{3}-\d{2}-\d{4}\b'              # SSN with specific format
    - '\b[A-Za-z0-9+/]{40}\b'              # Fixed-length token
    - '\b(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b'  # IP address
    - '\b[A-Z]{2}-\d{6}\b'                 # Bounded business code format

Why these are safe:

  • Use specific quantifiers ({3}, {40}) instead of unbounded ones
  • Avoid nested quantifiers that cause exponential backtracking
  • Include word boundaries (\b) to limit matching scope
  • Use character classes with specific ranges

Circuit Breaker Protection

The privacy system includes an automatic failsafe mechanism that prevents cascading failures when regex patterns consistently fail. This circuit breaker monitors pattern execution and temporarily disables redaction to maintain memory system stability.

  • 1
    Automatic Activation

    Triggers after 10 consecutive pattern failures to prevent system overload

  • 2
    Self-Healing Recovery

    Automatically resets when a pattern succeeds, restoring normal operation

  • 3
    No Configuration Required

    Built-in protection that works transparently without manual setup

  • 4
    Graceful Degradation

    Memory operations continue normally while patterns are temporarily disabled

Complete Configuration Example

Here's a production-ready privacy configuration for a customer service application:

resource: memory
id: customer_service_memory
description: Customer service memory with comprehensive privacy protection

privacy_policy:
  redact_patterns:
    # Customer personal information
    - '\b\d{3}-\d{2}-\d{4}\b'                     # SSN
    - '\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b'  # Email
    - '\b(?:\+?1[-.\s]?)?\(?[2-9]\d{2}\)?[-.\s]?\d{3}[-.\s]?\d{4}\b'  # Phone

    # Financial information
    - '\b\d{4}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{3,6}\b'  # Credit cards
    - '\baccount\s*#?\s*\d{6,12}\b'               # Account numbers

    # Internal identifiers
    - '\bCS-\d{6}\b'                              # Support ticket IDs
    - '\bEMP-\d{4}\b'                             # Employee IDs

  non_persistable_message_types:
    - system
    - debug
    - error
    - authentication

  default_redaction_string: "[REDACTED]"

# Memory configuration
type: token_based
max_tokens: 4000
persistence:
  type: redis
  config:
    host: localhost
    port: 6379
    db: 0

Summary

With Compozy's privacy system, you can confidently handle sensitive data while maintaining optimal memory performance. Start with the basic patterns that match your data types, enable message filtering for sensitive categories, and monitor system performance as you scale.

Ready to implement privacy controls? Begin with the memory configuration guide to set up your secure memory resources, then explore integration patterns for advanced privacy-aware architectures.

Next Steps