Skip to content

Build production ready apps for GPT using Node.js & TypeScript

License

Notifications You must be signed in to change notification settings

GPTSafe/PromptGuard

Repository files navigation

PromptGuard



What is PromptGuard?

PromptGuard helps you build production ready GPT apps for Node.js and TypeScript applications.

Project Goals

The goal of the PromptGuard project is to provide the features necessary to deploy GPT-based applications to production. This includes:

  • Detecting and mitigating prompt attacks
  • Caching to improve performance and reduce the cost of GPT queries
  • Content filtering
  • Language filtering
  • Token limiting
  • GPT ready encoded outputs
  • Prompt Obfuscation

PromptGuard is still a fairly young project and would love your contributions. If you wish to contribute, please read the contribution guide and code of conduct first.

Feature requests and bug reports are welcome!

Configuration Options

Option Default Value Description
maxTokens 4096 The maximum amount of tokens the prompt can contain. Restricting the maximum amount of tokens can reduce the cost of the GPT query and the opportunity for prompt attacks. You can read more information about tokens here.

If the prompt exceeds the maximum tokens, PromptGuard will reject the prompt with the following output:
{ pass: false, output: EXCEEDS_MAX_TOKEN_THRESHOLD }
denyList [""] An array of string literals that should not appear in the prompt text. If PromptGuard finds a deny list match, it will reject with the following output:
{ pass: false, output: CONTAINS_DENY_LIST_ITEM }
disableAttackMitigation false A list of known prompt attacks and injections that are checked against the prompt. In the future, this will become more sophisticated.

If PromptGuard finds a default deny list match, it will reject the prompt with the following output:
{ pass: false, output: CONTAINS_KNOWN_ATTACK }
encodeOutput false Encodes the output as GPT-3 tokens. You can read more information about tokens here.

Usage

Install

npm install @gtpsafe/promptguard

Configure

import { PromptGuard } from "@gtpsafe/promptguard"

const promptGuard = new PromptGuard({
  maxTokens: 200,
  denyList:['baz'],
});

Process a Prompt

const output = await promptGuard.process("This is my awesome prompt. There are many like it, but this one is mine.")

Output

{
  pass: true,
  output: "This is my awesome prompt. There are many like it, but this one is mine."
}