🚀. Socket Launch Week Day 3:Socket Firewall Now Blocks Malicious VS Code and Open VSX Extensions.Learn more
Sign In

@promptshield/sanitizer

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@promptshield/sanitizer

PromptShield sanitizer that applies safe, deterministic fixes to text based on detected prompt-injection threats such as invisible characters, markdown smuggling, and BOM artifacts.

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

@promptshield/sanitizer

PromptShield Banner

CI codecov npm version npm downloads npm bundle size license

Deterministic sanitizer for prompt hygiene. Applies safe, idempotent text transformations to remove invisible threats and normalization artifacts.

✨ Features

  • Safe Defaults: Removes only objectively dangerous characters (BOM, ZWSP, control chars).
  • Idempotent: Running it twice produces the same result.
  • Strict Mode: Optional NFKC normalization for aggressive cleaning.
  • Zero-Dependency: Lightweight and fast.

📦 Installation

$ pnpm add @promptshield/sanitizer

🚀 Usage

View complete usage and exact removal rules
import { sanitize, sanitizeStrict } from "@promptshield/sanitizer";

const dirty = "Hello\u200BWorld"; // Contains Zero-Width Space

// Safe sanitize (removes invisible chars)
const clean = sanitize(dirty);
console.log(clean); // "HelloWorld"

// Strict sanitize (also applies NFKC normalization)
const strict = sanitizeStrict("ℍ𝕖𝕝𝕝𝕠");
console.log(strict); // "Hello"

What gets removed?

  • Invisible Characters: \u200B (ZWSP), \u200C (ZWNJ), \u200D (ZWJ), etc.
  • Byte Order Marks: \uFEFF.
  • Variation Selectors: \uFE00-\uFE0F (often used to break tokenizers).
  • Markdown Comments: <!-- hidden payload -->.
  • Empty Links: [](javascript:...).

📚 Deep Dives: For the exact execution order of the sanitization pipeline and understanding applyFixes, see the Documentation section.

License

This library is licensed under the MIT open-source license.

with 💖 by Mayank Kumar Chaudhari

Keywords

promptshield

FAQs

Package last updated on 09 Mar 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts