Guard System

Input validation and protection for your context storage.

What It Protects

The write guard validates all inputs before saving context. Enable or disable it in your config:

.opencontext.jsonc
{
  "guard": {
    "enabled": true,
    "maxFileSizeKb": 50,
    "strictPatternCheck": true
  }
}

Validations

Empty Content

Prevents saving blank or whitespace-only files

Payload Too Large

Configurable max file size (default 50KB)

Invalid Topics

Enforces snake_case or kebab-case naming

Path Traversal

Blocks "..", absolute paths, and directory escapes

Reserved Topics

Prevents overwriting system files like index.md

Prompt Injection

Detects and blocks common injection patterns

Error Codes

CodeDescription
EMPTY_CONTENTContent is empty or whitespace only
PAYLOAD_TOO_LARGEContent exceeds maxFileSizeKb
INVALID_TOPICTopic name doesn't match required pattern
PATH_TRAVERSALTopic contains path traversal attempts
RESERVED_TOPICTopic is reserved by the system
FORBIDDEN_PATTERNContent contains prompt injection patterns

Forbidden Patterns

When strictPatternCheck is enabled, the guard detects these prompt injection patterns:

ignore (all) (previous|prior) instructions
system: override
bypass (safety|guardrails?|system prompt)