TypeScript SDKReference
Safety Types
TypeScript types for content safety filtering, templates, and evaluation.
SDK-Level Safety Layer: Safety types are SDK-specific — they parse and evaluate content filter results embedded in API responses from the Chat Completions API and Responses API (see Content Filtering). The SDK provides template-based filtering (SafetyTemplates), evaluation helpers, and unified checking without additional API calls.
See Safety for usage. See Responsible AI.
SafetyCategory
enum SafetyCategory {
HATE = 'hate',
VIOLENCE = 'violence',
SEXUAL = 'sexual',
SELF_HARM = 'self_harm',
PROTECTED_MATERIAL_CODE = 'protected_material_code',
PROTECTED_MATERIAL_TEXT = 'protected_material_text',
JAILBREAK = 'jailbreak',
}SafetySeverity
enum SafetySeverity {
SAFE = 'safe',
LOW = 'low',
MEDIUM = 'medium',
HIGH = 'high',
}SafetyTemplates
const SafetyTemplates = {
STRICT: { id: 'strict', severityThreshold: 'safe', failOnFiltered: true },
MODERATE: { id: 'moderate', severityThreshold: 'medium', failOnFiltered: true },
MINIMAL: { id: 'minimal', severityThreshold: 'high', failOnFiltered: false },
CHILD_SAFE:{ id: 'child_safe',severityThreshold: 'low',
categories: ['sexual','violence','self_harm','hate'] },
ENTERPRISE:{ id: 'enterprise',severityThreshold: 'safe', categories: 'all' },
}SafetyTemplateConfig
interface SafetyTemplateConfig {
id: string;
categories: (SafetyCategory | string)[] | 'all';
severityThreshold: SafetySeverity | string;
failOnFiltered: boolean;
}| Field | Type | Description |
|---|---|---|
id | string | Template ID. |
categories | (SafetyCategory | string)[] | 'all' | Categories to check. |
severityThreshold | SafetySeverity | string | Minimum severity to trigger. |
failOnFiltered | boolean | Whether to fail when content is filtered. |
SafetyCheckResult
interface SafetyCheckResult {
passed: boolean;
failedCategories: (SafetyCategory | string)[];
template: string;
contentFilterResults: ChoiceContentFilterResults;
}Returned by checkText() and checkImage().
| Field | Type | Description |
|---|---|---|
passed | boolean | Whether content passed. |
failedCategories | (SafetyCategory | string)[] | Categories that triggered. |
template | string | Template ID used. |
contentFilterResults | ChoiceContentFilterResults | Raw per-category results. |
SafetyEvaluationResult
interface SafetyEvaluationResult {
passed: boolean;
failedCategories: (SafetyCategory | string)[];
template: string;
details: SafetyFilterSummary;
}Returned by evaluate().
| Field | Type | Description |
|---|---|---|
passed | boolean | Whether content passed. |
failedCategories | (SafetyCategory | string)[] | Failed categories. |
template | string | Template ID used. |
details | SafetyFilterSummary | Full breakdown. |
SafetyFilterSummary
interface SafetyFilterSummary {
anyFiltered: boolean;
choice: Partial<Record<SafetyCategory, SafetyFilterCategoryResult>>;
prompt: Array<{
prompt_index: number;
results: Partial<Record<SafetyCategory, SafetyFilterCategoryResult>>;
}>;
}Returned by parseFilterResults().
| Field | Type | Description |
|---|---|---|
anyFiltered | boolean | Whether any category was filtered. |
choice | Partial<Record<SafetyCategory, ...>> | Per-category results for the completion. |
prompt | Array<{ prompt_index, results }> | Per-category results per prompt. |
SafetyCheckableInput
type SafetyCheckableInput =
| ChatCompletion
| ChatCompletionChoice
| ChatCompletionChoice[]
| { choices: ChatCompletionChoice[]; prompt_filter_results?: PromptFilterResult[] }
| { content_filter_results?: ChoiceContentFilterResults }EvaluateInput
type EvaluateInput =
| SafetyCheckableInput
| string
| { url: string }
| EvaluateInput[]ContentFilterResult
interface ContentFilterResult {
filtered: boolean;
severity: SafetySeverity | string;
}| Field | Type | Description |
|---|---|---|
filtered | boolean | Whether content was filtered. |
severity | SafetySeverity | string | Severity level. |
Related
- SDK Safety — Complete safety implementation guide with templates
- Responsible AI — Content safety policies and guidelines
- Safety Controls — Safety controls overview
How is this guide?