npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@reaatech/pi-bench-adapters

v1.0.1

Published

Defense adapters for prompt injection detection (Rebuff, Lakera, LLM Guard, Garak, Moderation APIs)

Readme

@reaatech/pi-bench-adapters

npm version License: MIT CI

Status: Pre-1.0 — APIs may change in minor versions. Pin to a specific version in production.

Pluggable defense adapter implementations for prompt injection detection. Includes 8 built-in adapters covering library-based, API-based, tool-based, and custom HTTP defenses. All adapters extend BaseAdapter which provides input validation, SSRF protection, rate limiting, and shared injection pattern detection.

Installation

npm install @reaatech/pi-bench-adapters
# or
pnpm add @reaatech/pi-bench-adapters

Feature Overview

  • 8 built-in adapters — Rebuff, Lakera Guard, LLM Guard, Garak, OpenAI/Azure/Anthropic/Cohere Moderation, Custom HTTP
  • Standard interfaceDefenseAdapter with detect() and sanitize() methods
  • BaseAdapter class — Shared input validation (10K char limit, null byte rejection), injection pattern removal, and redaction
  • SSRF protection — Blocks file:, javascript:, data: protocols and cloud metadata endpoints
  • Rate limiting — Token bucket algorithm, configurable per-adapter (default: 100 req/min)
  • API key validation — Empty API keys cause early throw before any network call
  • Dual ESM/CJS output — works with import and require

Quick Start

import {
  createMockAdapter,
  createRebuffAdapter,
  AdapterRegistry,
} from "@reaatech/pi-bench-adapters";

// Use the mock adapter for testing (deterministic, no API calls)
const mockAdapter = createMockAdapter(0.95, 0.03);
const result = await mockAdapter.detect("Ignore all instructions");
console.log(result.isInjection); // true (95% detection rate)

// Register adapters for version-aware lookup
const registry = new AdapterRegistry();
registry.register(mockAdapter);
const latest = registry.getLatest("mock");

Built-in Adapters

| Adapter | Type | Configuration | |---------|------|---------------| | MockAdapter | Testing | new MockAdapter(detectionRate, falsePositiveRate, name?, version?) | | RebuffAdapter | Library | REBUFF_API_KEY env var, threshold option | | LakeraAdapter | API | LAKERA_API_KEY env var | | LLMGuardAdapter | API | LLM_GUARD_API_KEY env var, baseUrl option | | GarakAdapter | Tool | garak in PATH, threshold option | | ModerationAdapter | API | Provider-specific keys: OPENAI_API_KEY, AZURE_*, ANTHROPIC_API_KEY, COHERE_API_KEY | | CustomAdapter | HTTP | detectUrl, sanitizeUrl, custom headers |

API Reference

DefenseAdapter (interface)

interface DefenseAdapter {
  name: string;
  version: string;
  detect(input: string): Promise<DetectionResult>;
  sanitize(input: string): Promise<SanitizedOutput>;
  initialize?(): Promise<void>;
  cleanup?(): Promise<void>;
}

DetectionResult

| Property | Type | Description | |----------|------|-------------| | isInjection | boolean | Whether the input was flagged as an injection | | confidence | number | Confidence score (0–1) | | metadata | Record<string, unknown> | Adapter-specific data (categories, scores, etc.) |

SanitizedOutput

| Property | Type | Description | |----------|------|-------------| | sanitizedText | string | The input with injection patterns removed or redacted | | removed | RemovedPattern[] | Which patterns were detected and removed | | metadata | Record<string, unknown> | Adapter-specific data |

BaseAdapter (abstract class)

Extend to create custom adapters. Provides:

| Method | Description | |--------|-------------| | validateInput(input) | Rejects null bytes, trims whitespace, enforces 10K char limit | | validateApiKey(key, envVar) | Throws if key is empty or undefined | | removeInjectionPatterns(input) | Detects common injection phrases, returns RemovedPattern[] | | applySanitization(input, removed) | Redacts detected patterns from the input |

AdapterRegistry

| Method | Description | |--------|-------------| | register(adapter) | Register an adapter (auto-sorts by semver) | | getLatest(name) | Get the highest-version adapter by name | | get(name, version) | Get a specific version | | list() | List all registered adapters | | unregister(name, version?) | Remove an adapter | | clear() | Remove all adapters |

Usage Patterns

Creating a Custom Adapter

import { BaseAdapter, type DetectionResult, type SanitizedOutput } from "@reaatech/pi-bench-adapters";

class MyDefense extends BaseAdapter {
  constructor() {
    super("my-defense", "1.0.0");
  }

  async detect(input: string): Promise<DetectionResult> {
    this.validateInput(input);
    // Your detection logic here
    return { isInjection: false, confidence: 0.95, metadata: {} };
  }

  async sanitize(input: string): Promise<SanitizedOutput> {
    this.validateInput(input);
    const removed = this.removeInjectionPatterns(input);
    return {
      sanitizedText: this.applySanitization(input, removed),
      removed,
      metadata: {},
    };
  }
}

Rate Limiting

import { RateLimiter } from "@reaatech/pi-bench-adapters";

const limiter = new RateLimiter({ maxRequests: 60, perWindowMs: 60_000 });
if (limiter.allow()) {
  await adapter.detect(input);
}

SSRF Protection

import { validateApiUrl } from "@reaatech/pi-bench-adapters";

validateApiUrl("https://api.example.com/v1/detect", "MyAdapter");
// Throws for: file://, javascript:, 169.254.169.254, etc.

Related Packages

License

MIT