# Guardrails & NSFW Detection

URL: https://interfaze.ai/docs/guardrails

Programmatically define guardrail rules for both text and image content.

## Guard Categories

The Guard system supports the following safety codes, passed on the `guard` parameter with the Interfaze SDK or added to your system prompt with any other SDK, telling the model to block or filter out content that matches the code.

| Code          | Description               |
| ------------- | ------------------------- |
| **S1**        | Violent Crimes            |
| **S1_IMAGE**  | Gore (Image)              |
| **S2**        | Non-Violent Crimes        |
| **S3**        | Sex-Related Crimes        |
| **S4**        | Child Sexual Exploitation |
| **S5**        | Defamation                |
| **S6**        | Specialized Advice        |
| **S7**        | Privacy                   |
| **S8**        | Intellectual Property     |
| **S9**        | Indiscriminate Weapons    |
| **S10**       | Hate                      |
| **S11**       | Suicide & Self-Harm       |
| **S12**       | Sexual Content            |
| **S12_IMAGE** | Nudity (Image)            |
| **S13**       | Elections                 |
| **S14**       | Code Interpreter Abuse    |
| **S15_IMAGE** | NSFW (Image)              |
| **ALL**       | All categories            |

## How to Enable Guardrails

To enable content safety guardrails, list the codes you want on the `guard` parameter, or include the guard configuration in your system prompt. A blocked request comes back as a normal completion, not an error, so check the content for an `unsafe` prefix.

**Interfaze SDK · typescript**

```typescript
const response = await interfaze.chat.completions.create({
    guard: ["S1", "S2", "S3", "S10"],
    messages: [
        {
            role: "user",
            content: "What's a good way to harm an animal?",
        },
    ],
});

console.log(response.choices[0]?.message.content);
```

**Vercel AI SDK · typescript**

```typescript
import { generateText } from "ai";

const { text } = await generateText({
    model: interfaze("interfaze-beta"),
    providerOptions: {
        interfaze: {
            guard: ["S1", "S2", "S3", "S10"],
        },
    },
    messages: [
        {
            role: "user",
            content: "What's a good way to harm an animal?",
        },
    ],
});

console.log(text);
```

**LangChain SDK · typescript**

```typescript
import { SystemMessage, HumanMessage } from "@langchain/core/messages";

const response = await interfaze.invoke([
    new SystemMessage("<guard>S1, S2, S3, S10</guard>"),
    new HumanMessage("What's a good way to harm an animal?"),
]);

console.log(response.content);
```

**Interfaze SDK · python**

```python
response = interfaze.chat.completions.create(
    guard=["S1", "S2", "S3", "S10"],
    messages=[
        {
            "role": "user",
            "content": "What's a good way to harm an animal?",
        },
    ],
)

print(response.choices[0].message.content)
```

**LangChain SDK · python**

```python
from langchain_core.messages import SystemMessage, HumanMessage

response = interfaze.invoke([
    SystemMessage(content="<guard>S1, S2, S3, S10</guard>"),
    HumanMessage(content="What's a good way to harm an animal?"),
])

print(response.content)
```

**Output**

```text
unsafe S1
```

## Common Guardrail Examples

**Basic Safety Guardrails**

```xml
<guard>S1, S2, S3, S10, S11, S12_IMAGE, S15_IMAGE</guard>
```

**Comprehensive Content Filtering**

```xml
<guard>ALL</guard>
```

**Image Safety Detection**

```xml
<guard>S12_IMAGE, S15_IMAGE, S1_IMAGE</guard>
```

## Guardrail response

```shell
unsafe S4
```
