Skip to content

feat: add prompt input sanitization layer#27

Merged
realityinspector merged 3 commits intomainfrom
agent/el-42buw-prompt-sanitization
Mar 25, 2026
Merged

feat: add prompt input sanitization layer#27
realityinspector merged 3 commits intomainfrom
agent/el-42buw-prompt-sanitization

Conversation

@realityinspector
Copy link
Collaborator

Strips control characters, truncates oversized inputs, rejects null bytes across character_bio, dialog, and scene prompt builders. Unit tests included.

timepointai added 3 commits March 25, 2026 06:58
…alls

Add app/prompts/sanitize.py with sanitize_prompt_input() that:
- Escapes { and } to prevent format-string injection via user input
- Strips adversarial prompt-injection patterns (ignore instructions, role hijacks, etc.)
- Removes null bytes and ASCII control characters
- Enforces a 4000-character length cap
- Normalises Unicode to NFC

Apply sanitize_prompt_input() to all user-controlled fields before
.format() calls in character_bio.py, dialog.py, and scene.py, including
sequential dialog prompt helpers.

Add 24-test suite in tests/unit/test_prompt_sanitize.py covering both
the sanitizer function and end-to-end template rendering.
- Add POSTHOG_API_KEY and POSTHOG_HOST to config
- New app/feature_flags.py: init_posthog(), is_feature_enabled() async
  wrapper, shutdown_posthog() — safe no-op when key not set
- main.py: call init_posthog() on startup, shutdown_posthog() on shutdown
- Add posthog>=3.0.0 to observability extras in pyproject.toml
@realityinspector realityinspector merged commit 6f2d51e into main Mar 25, 2026
2 of 3 checks passed
@realityinspector realityinspector deleted the agent/el-42buw-prompt-sanitization branch March 25, 2026 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant