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

promptdefend

v1.0.0

Published

Node.js SDK for the Prompt Defend AI Security API - 16-Layer Guardrail Protection

Readme

Prompt Defend Node.js SDK

npm version Node.js

The official Node.js SDK for the Prompt Defend AI Security API. Protect your AI applications with our 16-layer guardrail system.

Installation

npm install promptdefend

Or with yarn:

yarn add promptdefend

Quick Start

const { PromptDefend } = require('promptdefend');

// Initialize the client with your API key
const client = new PromptDefend({ apiKey: 'your-api-key' });

// Scan a prompt for security issues
const result = await client.scan('What is the weather today?');

if (result.safe) {
    console.log('✅ Prompt is safe to process');
} else {
    console.log(`⚠️ Warning: ${result.reason}`);
}

Features

  • 🛡️ 16-Layer Protection - Comprehensive guardrail system
  • 🔒 Prompt Injection Detection - Block jailbreak and injection attempts
  • Sub-millisecond Latency - Average response time ~0.7ms
  • 📦 TypeScript Support - Full type definitions included
  • 🔧 Error Handling - Comprehensive error classes
  • 🌐 ESM & CommonJS - Works with both module systems

Usage

ESM (ES Modules)

import { PromptDefend } from 'promptdefend';

const client = new PromptDefend({ apiKey: 'your-api-key' });
const result = await client.scan('Hello, how are you?');

CommonJS

const { PromptDefend } = require('promptdefend');

const client = new PromptDefend({ apiKey: 'your-api-key' });
const result = await client.scan('Hello, how are you?');

TypeScript

import { PromptDefend, ScanResult, PromptDefendOptions } from 'promptdefend';

const options: PromptDefendOptions = {
    apiKey: 'your-api-key',
    baseUrl: 'https://api.promptdefend.dev'
};

const client = new PromptDefend(options);
const result: ScanResult = await client.scan('Test prompt');

console.log(result.safe);    // boolean
console.log(result.reason);  // string
console.log(result.details); // object

Custom Configuration

const { PromptDefend } = require('promptdefend');

const client = new PromptDefend({
    apiKey: 'your-api-key',
    baseUrl: 'https://api.promptdefend.dev',  // Optional custom endpoint
    timeout: 60000  // Custom timeout in milliseconds
});

Error Handling

The SDK provides specific error classes for different error types:

const { 
    PromptDefend, 
    PromptDefendError,
    AuthenticationError,
    NetworkError,
    APIError 
} = require('promptdefend');

const client = new PromptDefend({ apiKey: 'your-api-key' });

try {
    const result = await client.scan('Test prompt');
} catch (error) {
    if (error instanceof AuthenticationError) {
        console.error(`Invalid API key: ${error.message}`);
    } else if (error instanceof NetworkError) {
        console.error(`Network issue: ${error.message}`);
    } else if (error instanceof APIError) {
        console.error(`API error (status ${error.statusCode}): ${error.message}`);
    } else if (error instanceof PromptDefendError) {
        console.error(`General error: ${error.message}`);
    }
}

Response Object

The scan() method returns a ScanResult object with the following properties:

| Property | Type | Description | |----------|------|-------------| | safe | boolean | Whether the prompt is safe to process | | reason | string | Explanation of the safety assessment | | details | object | Full detection details from all 16 layers | | fastPath | boolean | Whether allowlist short-circuit was used |

API Reference

PromptDefend Class

Constructor Options

interface PromptDefendOptions {
    apiKey: string;      // Required: Your API key
    baseUrl?: string;    // Optional: Custom API base URL
    timeout?: number;    // Optional: Request timeout in milliseconds (default: 30000)
}

Methods

| Method | Description | |--------|-------------| | scan(promptText: string): Promise<ScanResult> | Scan a prompt and return results |

Requirements

  • Node.js 18.0.0 or higher

License

This SDK is proprietary software. See LICENSE for details.

Support


© 2026 Prompt Defend. All Rights Reserved.