🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

safeprompt

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

safeprompt

API-first prompt injection protection for AI applications

latest
Source
npmnpm
Version
1.2.1
Version published
Maintainers
1
Created
Source

SafePrompt JavaScript/TypeScript SDK

Official JavaScript/TypeScript SDK for SafePrompt API.

Installation

npm install safeprompt

Quick Start

import SafePrompt from 'safeprompt';

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

const result = await client.check('User input goes here');

if (result.safe) {
  // Safe to proceed with LLM
} else {
  // Handle malicious input
  console.log('Threats detected:', result.threats);
}

API Reference

new SafePrompt(config)

Create a new SafePrompt client.

Parameters:

  • config.apiKey (string, required): Your SafePrompt API key
  • config.baseURL (string, optional): Custom API base URL

client.check(prompt)

Validate a single prompt.

Parameters:

  • prompt (string, required): The user input to validate

Returns:

{
  safe: boolean;
  threats: string[];
  confidence: number;
  processingTime: number;
}

client.checkBatch(prompts)

Validate multiple prompts in one request.

Parameters:

  • prompts (string[], required): Array of prompts to validate

Returns:

Array<ValidationResult>

client.getUsage()

Get API usage statistics.

Returns:

{
  requestsThisMonth: number;
  requestsRemaining: number;
  plan: string;
}

Error Handling

try {
  const result = await client.check(userInput);
} catch (error) {
  if (error instanceof SafePromptError) {
    console.error('API Error:', error.message, error.statusCode);
  } else {
    console.error('Unexpected error:', error);
  }
}

TypeScript Support

Full TypeScript support included with type definitions.

License

MIT

Keywords

prompt-injection

FAQs

Package last updated on 03 Jul 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