Superagent LogoSuperagent
SDK

TypeScript

TypeScript SDK for content safety - guard and redact methods

TypeScript SDK

The @superagent-ai/safety-agent package provides two core methods: guard() for detecting threats and redact() for removing sensitive data.

Installation

npm install @superagent-ai/safety-agent

Quick Start

import { createClient } from "@superagent-ai/safety-agent";

const client = createClient();

// Guard: Detect threats
const guardResult = await client.guard({
  input: "user message to analyze"
});

// Redact: Remove PII
const redactResult = await client.redact({
  input: "My email is john@example.com",
  model: "openai/gpt-4o-mini"
});

Guard

The guard() method classifies input content as pass or block. It detects prompt injections, malicious instructions, and security threats.

Basic Usage

const result = await client.guard({
  input: "user message to analyze"
});

if (result.classification === "block") {
  console.log("Blocked:", result.violation_types);
}

Options

OptionTypeRequiredDefaultDescription
inputstring | Blob | URLYes-The input to analyze
modelstringNosuperagent/guard-1.7bModel in provider/model format
systemPromptstringNo-Custom system prompt
chunkSizenumberNo8000Characters per chunk (0 to disable)

Response

FieldTypeDescription
classification"pass" | "block"Whether content passed or should be blocked
violation_typesstring[]Types of violations detected
cwe_codesstring[]CWE codes associated with violations
usageTokenUsageToken usage information

Input Types

Guard supports multiple input types:

  • Plain text: Analyzed directly
  • URLs: Automatically fetched and analyzed
  • Blob/File: Analyzed based on MIME type
  • PDFs: Text extracted and analyzed per page
  • Images: Requires vision-capable model
// URL input
const result = await client.guard({
  input: "https://example.com/document.pdf"
});

// Image input (requires vision model)
const result = await client.guard({
  input: imageBlob,
  model: "openai/gpt-4o"
});

Redact

The redact() method removes sensitive content from text using placeholders or contextual rewriting.

Basic Usage

const result = await client.redact({
  input: "My email is john@example.com and SSN is 123-45-6789",
  model: "openai/gpt-4o-mini"
});

console.log(result.redacted);
// "My email is <EMAIL_REDACTED> and SSN is <SSN_REDACTED>"

Options

OptionTypeRequiredDefaultDescription
inputstringYes-The text to redact
modelstringYes-Model in provider/model format
entitiesstring[]NoDefault PIIEntity types to redact
rewritebooleanNofalseRewrite contextually instead of placeholders

Response

FieldTypeDescription
redactedstringSanitized text with redactions
findingsstring[]What was redacted
usageTokenUsageToken usage information

Rewrite Mode

Contextually rewrites text instead of using placeholders:

const result = await client.redact({
  input: "My email is john@example.com",
  model: "openai/gpt-4o-mini",
  rewrite: true
});

console.log(result.redacted);
// "My email is on file"

Custom Entities

Specify which entity types to redact:

const result = await client.redact({
  input: "Contact john@example.com or call 555-123-4567",
  model: "openai/gpt-4o-mini",
  entities: ["email addresses"] // Only redact emails
});

Default Entities

When entities is not specified:

  • SSNs, Driver's License, Passport Numbers
  • API Keys, Secrets, Passwords
  • Names, Addresses, Phone Numbers
  • Emails, Credit Card Numbers