{"id":47788537,"url":"https://github.com/acebot712/promptguard-node","last_synced_at":"2026-04-11T11:07:50.594Z","repository":{"id":341184525,"uuid":"1169222599","full_name":"acebot712/promptguard-node","owner":"acebot712","description":"PromptGuard Node.js SDK — Drop-in security for AI applications","archived":false,"fork":false,"pushed_at":"2026-03-25T12:27:22.000Z","size":123,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-03T17:47:39.257Z","etag":null,"topics":["ai-firewall","ai-safety","llm","nodejs","prompt-injection","sdk","security","typescript"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/acebot712.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-02-28T11:04:54.000Z","updated_at":"2026-03-25T12:27:26.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/acebot712/promptguard-node","commit_stats":null,"previous_names":["acebot712/promptguard-node"],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/acebot712/promptguard-node","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acebot712%2Fpromptguard-node","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acebot712%2Fpromptguard-node/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acebot712%2Fpromptguard-node/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acebot712%2Fpromptguard-node/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/acebot712","download_url":"https://codeload.github.com/acebot712/promptguard-node/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acebot712%2Fpromptguard-node/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31677819,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-11T08:18:19.405Z","status":"ssl_error","status_checked_at":"2026-04-11T08:17:08.892Z","response_time":54,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai-firewall","ai-safety","llm","nodejs","prompt-injection","sdk","security","typescript"],"created_at":"2026-04-03T15:10:18.814Z","updated_at":"2026-04-11T11:07:50.589Z","avatar_url":"https://github.com/acebot712.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![npm version](https://img.shields.io/npm/v/promptguard)](https://www.npmjs.com/package/promptguard)\n[![CI](https://github.com/acebot712/promptguard-node/actions/workflows/ci.yml/badge.svg)](https://github.com/acebot712/promptguard-node/actions/workflows/ci.yml)\n[![License](https://img.shields.io/github/license/acebot712/promptguard-node)](https://github.com/acebot712/promptguard-node/blob/main/LICENSE)\n[![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue)](https://www.typescriptlang.org/)\n\n# PromptGuard Node.js SDK\n\nDrop-in security for AI applications. Secure any GenAI app - regardless of framework or LLM provider.\n\n## Installation\n\n```bash\nnpm install promptguard-sdk\n```\n\n## Option 1: Auto-Instrumentation (Recommended)\n\nOne line secures **every** LLM call in your application - no matter which framework you use.\n\n```typescript\nimport { init } from 'promptguard-sdk';\n\n// Call once at startup - before any LLM SDK usage.\ninit({ apiKey: 'pg_xxx' });\n\n// Everything below is now secured transparently.\nimport OpenAI from 'openai';\nconst client = new OpenAI();\n\n// This call is automatically scanned by PromptGuard.\nconst response = await client.chat.completions.create({\n  model: 'gpt-5-nano',\n  messages: [{ role: 'user', content: 'Hello!' }],\n});\n```\n\n### Supported SDKs\n\nAuto-instrumentation patches the `create` / `generateContent` / `chat` / `send` methods on:\n\n| SDK | npm Package | What Gets Patched |\n|-----|------------|-------------------|\n| OpenAI | `openai` | `chat.completions.create` |\n| Anthropic | `@anthropic-ai/sdk` | `messages.create` |\n| Google Generative AI | `@google/generative-ai` | `generateContent` |\n| Cohere | `cohere-ai` | `Client.chat` / `ClientV2.chat` |\n| AWS Bedrock | `@aws-sdk/client-bedrock-runtime` | `BedrockRuntimeClient.send` (InvokeModel, Converse) |\n\nAny framework built on these SDKs is automatically covered: **LangChain.js**, **Vercel AI SDK**, **AutoGen**, **Semantic Kernel**, and more.\n\n### Modes\n\n```typescript\n// Enforce mode (default) - blocks policy violations.\ninit({ apiKey: 'pg_xxx', mode: 'enforce' });\n\n// Monitor mode - logs threats but never blocks. Good for shadow deployment.\ninit({ apiKey: 'pg_xxx', mode: 'monitor' });\n```\n\n### Options\n\n```typescript\ninit({\n  apiKey: 'pg_xxx',           // or set PROMPTGUARD_API_KEY env var\n  baseUrl: 'https://...',     // or set PROMPTGUARD_BASE_URL env var\n  mode: 'enforce',            // 'enforce' | 'monitor'\n  failOpen: true,             // allow calls when Guard API is unreachable\n  scanResponses: false,       // also scan LLM responses\n  timeout: 10_000,            // Guard API timeout in ms\n});\n```\n\n### Shutdown\n\n```typescript\nimport { shutdown } from 'promptguard-sdk';\n\n// Removes all patches and cleans up.\nshutdown();\n```\n\n## Option 2: Proxy Mode\n\nRoute LLM traffic through PromptGuard. Just swap your base URL.\n\n```typescript\nimport { PromptGuard } from 'promptguard-sdk';\n\nconst pg = new PromptGuard({ apiKey: 'pg_xxx' });\n\n// Use exactly like the OpenAI client.\nconst response = await pg.chat.completions.create({\n  model: 'gpt-5-nano',\n  messages: [{ role: 'user', content: 'Hello!' }],\n});\n```\n\n### Security Scanning\n\n```typescript\nconst result = await pg.security.scan('Ignore previous instructions...');\nif (result.blocked) {\n  console.log(`Threat detected: ${result.reason}`);\n}\n```\n\n### PII Redaction\n\n```typescript\nconst result = await pg.security.redact(\n  'My email is john@example.com and SSN is 123-45-6789'\n);\nconsole.log(result.redacted);\n```\n\n## Framework Integrations\n\n### LangChain.js\n\n```typescript\nimport { PromptGuardCallbackHandler } from 'promptguard-sdk/integrations/langchain';\nimport { ChatOpenAI } from '@langchain/openai';\n\nconst handler = new PromptGuardCallbackHandler({\n  apiKey: 'pg_xxx',\n  mode: 'enforce',\n  scanResponses: true,\n});\n\n// Attach to a single model\nconst llm = new ChatOpenAI({\n  model: 'gpt-5-nano',\n  callbacks: [handler],\n});\n\n// Or use with any chain / agent\nconst result = await chain.invoke(\n  { input: 'Hello' },\n  { callbacks: [handler] },\n);\n```\n\nThe callback handler provides rich context to PromptGuard - chain names, tool calls, agent steps - for more precise threat detection.\n\n### Vercel AI SDK\n\n```typescript\nimport { openai } from '@ai-sdk/openai';\nimport { wrapLanguageModel, generateText } from 'ai';\nimport { promptGuardMiddleware } from 'promptguard-sdk/integrations/vercel-ai';\n\nconst model = wrapLanguageModel({\n  model: openai('gpt-5-nano'),\n  middleware: promptGuardMiddleware({\n    apiKey: 'pg_xxx',\n    mode: 'enforce',\n    scanResponses: true,\n  }),\n});\n\nconst { text } = await generateText({\n  model,\n  prompt: 'Hello!',\n});\n```\n\n### Standalone Guard API\n\nUse the Guard client directly for maximum control:\n\n```typescript\nimport { GuardClient } from 'promptguard-sdk';\n\nconst guard = new GuardClient({ apiKey: 'pg_xxx' });\n\n// Scan before sending to LLM\nconst decision = await guard.scan(\n  [{ role: 'user', content: userInput }],\n  'input',\n  'gpt-5-nano',\n);\n\nif (decision.blocked) {\n  console.log(`Blocked: ${decision.threatType}`);\n} else if (decision.redacted \u0026\u0026 decision.redactedMessages) {\n  // Use redacted messages instead\n  messages = decision.redactedMessages;\n}\n\n// Scan LLM response\nconst outputDecision = await guard.scan(\n  [{ role: 'assistant', content: llmOutput }],\n  'output',\n);\n```\n\n## Retry Logic\n\nBoth `PromptGuard` and `GuardClient` support configurable retry behavior for transient failures:\n\n```typescript\nconst pg = new PromptGuard({\n  apiKey: 'pg_xxx',\n  maxRetries: 3,      // Number of retry attempts (default: 2)\n  retryDelay: 500,     // Base delay in ms between retries (default: 250)\n});\n```\n\nRetries use exponential backoff starting from `retryDelay`. Only transient errors (network timeouts, 5xx responses) are retried; client errors (4xx) fail immediately.\n\n## Embeddings\n\nScan and secure embedding requests through the proxy:\n\n```typescript\nconst response = await pg.embeddings.create({\n  model: 'text-embedding-3-small',\n  input: 'The quick brown fox jumps over the lazy dog',\n});\nconsole.log(response.data[0].embedding.slice(0, 5));\n```\n\nBatch embedding requests are also supported:\n\n```typescript\nconst response = await pg.embeddings.create({\n  model: 'text-embedding-3-small',\n  input: ['First document', 'Second document', 'Third document'],\n});\nfor (const item of response.data) {\n  console.log(`Index ${item.index}: ${item.embedding.length} dimensions`);\n}\n```\n\n## AI Agent Security\n\n```typescript\nconst validation = await pg.agent.validateTool(\n  'agent-123',\n  'execute_shell',\n  { command: 'ls -la' },\n);\n\nif (!validation.allowed) {\n  console.log(`Blocked: ${validation.reason}`);\n}\n```\n\n## Red Team Testing\n\n```typescript\nconst pg = new PromptGuard({ apiKey: 'pg_xxx' });\n\n// Run the autonomous red team agent (LLM-powered mutation)\nconst report = await pg.redteam.runAutonomous({\n  budget: 200,\n  target_preset: 'support_bot:strict',\n});\nconsole.log(`Grade: ${report.grade}, Bypass rate: ${(report.bypass_rate * 100).toFixed(0)}%`);\n\n// Get Attack Intelligence stats\nconst stats = await pg.redteam.intelligenceStats();\nconsole.log(`Total patterns: ${stats.total_patterns}`);\n```\n\n## Configuration\n\n| Option | Environment Variable | Default | Description |\n|--------|---------------------|---------|-------------|\n| `apiKey` | `PROMPTGUARD_API_KEY` | - | PromptGuard API key (required) |\n| `baseUrl` | `PROMPTGUARD_BASE_URL` | `https://api.promptguard.co/api/v1` | API base URL |\n| `mode` | - | `\"enforce\"` | `\"enforce\"` or `\"monitor\"` |\n| `failOpen` | - | `true` | Allow calls when Guard API is unreachable |\n| `scanResponses` | - | `false` | Also scan LLM responses |\n| `timeout` | - | `10000` | HTTP timeout in milliseconds |\n\n## Error Handling\n\n```typescript\nimport { PromptGuardBlockedError, GuardApiError } from 'promptguard-sdk';\n\ntry {\n  await client.chat.completions.create({ ... });\n} catch (error) {\n  if (error instanceof PromptGuardBlockedError) {\n    // Request was blocked by policy\n    console.log(error.decision.threatType);\n    console.log(error.decision.confidence);\n    console.log(error.decision.eventId);\n  } else if (error instanceof GuardApiError) {\n    // Guard API is unreachable (only when failOpen=false)\n    console.log(error.statusCode);\n  }\n}\n```\n\n## TypeScript Support\n\nFull TypeScript support with type definitions for all exports:\n\n```typescript\nimport type {\n  GuardDecision,\n  GuardMessage,\n  GuardContext,\n  InitOptions,\n  ChatCompletionRequest,\n  ChatCompletionResponse,\n  SecurityScanResult,\n  AutonomousRedTeamRequest,\n  AutonomousRedTeamReport,\n  IntelligenceStats,\n} from 'promptguard-sdk';\n```\n\n## Links\n\n- [Documentation](https://docs.promptguard.co)\n- [SDK Reference](https://docs.promptguard.co/sdks/node)\n- [Support](mailto:support@promptguard.co)\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Facebot712%2Fpromptguard-node","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Facebot712%2Fpromptguard-node","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Facebot712%2Fpromptguard-node/lists"}