# Safety Filter

> Evaluates text against safety guidelines to block harmful content.

Source: https://docs.sommatic.ai/en/nodes/ai.safety.filter/

- Slug: `ai.safety.filter`
- Family: AI
- Version: 1.0.0
- Status: Experimental. Stub: returns a fixed `{ message, timestamp }` object without evaluating the input. Nothing is blocked.
- Execution: async

Evaluates text against safety guidelines to block harmful content.

Uses a moderation model (e.g., OpenAI Moderation API, Llama Guard) to detect categories like Hate, Harassment, Self-Harm, Sexual, or Violence.

**Use Cases:**
- Moderating user input before sending to an LLM.
- Validating LLM output before showing to user.
- Ensuring brand safety.

## Configuration

- `policies` (array<string>, optional): List of categories to block (e.g. ["hate", "violence"]). Empty = All.

Its configuration shows the shared execution settings, but this node does not apply retries (`retryOnFail`, `maxTries`) yet. `continueOnFail` is not applied by any node.

## Output ports

- `safe` (default): Content passed checks.
- `blocked`: Content violated safety policy.
- `error`: Moderation service failure.

## Input contract

- `text` (string, required): Creating content to moderate.

## Output contract

- `is_safe` (boolean, optional)
- `flagged_categories` (array<string>, optional)
- `scores` (object, optional)

## In expressions

What a later node can read from this node's output with `$("Safety Filter").item.json.<path>`, as the workflow editor suggests it under Previous Nodes (the output contract).

- `$("Safety Filter").item.json.is_safe` (boolean)
- `$("Safety Filter").item.json.flagged_categories` (array)
- `$("Safety Filter").item.json.scores` (object)


## How it works

Experimental stub. It returns a fixed `{ message, timestamp }` object without evaluating the input and without a port, so the engine routes it to `out`, which this node does not declare: nothing connected to `safe` or `blocked` runs.

1. Resolves the node config: expressions in config keys are evaluated against the run; the incoming item is used as-is.
2. Returns `{ message: "Executed ai.safety.filter", timestamp }` with no port. The engine routes to `out`; with no `out` edges the branch ends here.

## In a workflow

### Node

```json
{
  "node_id": "node-safety-filter",
  "label": "Moderate content",
  "operator_slug": "ai.safety.filter",
  "operator_version": "1.0.0",
  "config": {
    "policies": [
      "hate",
      "violence"
    ]
  }
}
```

### Envelope

```json
{
  "ok": true,
  "port": "out",
  "data": {
    "message": "Executed ai.safety.filter",
    "timestamp": "2026-11-26T15:04:05.000Z"
  }
}
```

## Output ports (behaviour in the code)

### `safe`

Never fires.

### `blocked`

Never fires: nothing is blocked.

### `error`

Never emitted by the code.

## Behaviour in the code

- `policies`: Declared but ignored.

## Notes and limits

- Not implemented: moderation, category scores and blocking. For a working safety check use `ai.safety.scan`, which routes to `pass`/`fail`.


## Contracts (JSON Schema)

### All (`*.definition.js`)

```json
{
  "slug": "ai.safety.filter",
  "name": "Safety Filter",
  "category": "ai",
  "version": "1.0.0",
  "description": "Evaluates text against safety guidelines to block harmful content.\n\n  Uses a moderation model (e.g., OpenAI Moderation API, Llama Guard) to detect categories like Hate, Harassment, Self-Harm, Sexual, or Violence.\n\n  **Use Cases:**\n  - Moderating user input before sending to an LLM.\n  - Validating LLM output before showing to user.\n  - Ensuring brand safety.",
  "capabilities": [
    "moderation",
    "safety",
    "guardrails"
  ],
  "config_schema": {
    "type": "object",
    "properties": {
      "policies": {
        "type": "array",
        "items": {
          "type": "string"
        },
        "title": "Blocked Categories",
        "description": "List of categories to block (e.g. [\"hate\", \"violence\"]). Empty = All."
      },
      "execution": {
        "type": "object",
        "title": "Execution Settings",
        "properties": {
          "alwaysOutputData": {
            "type": "boolean",
            "title": "Always Output Data",
            "description": "Always output data, even on error (if configured).",
            "default": false
          },
          "retryOnFail": {
            "type": "boolean",
            "title": "Retry On Fail",
            "description": "Retry the execution if it fails.",
            "default": false
          },
          "maxTries": {
            "type": "integer",
            "title": "Max Retries",
            "description": "Number of retries.",
            "default": 3,
            "displayOptions": {
              "show": {
                "retryOnFail": [
                  true
                ]
              }
            }
          },
          "waitBetweenTries": {
            "type": "integer",
            "title": "Wait Between Retries (ms)",
            "default": 1000,
            "displayOptions": {
              "show": {
                "retryOnFail": [
                  true
                ]
              }
            }
          },
          "continueOnFail": {
            "type": "boolean",
            "title": "Continue On Fail",
            "description": "Do not crash workflow on error.",
            "default": false
          },
          "timeout_ms": {
            "type": "integer",
            "title": "Timeout (ms)",
            "description": "Max execution time for this node before it is killed, in milliseconds. Honored by long-running operators (e.g. OCR/extraction, inline code). Default 300000 (5 min).",
            "default": 300000
          }
        }
      }
    }
  },
  "input_contract_schema": {
    "type": "object",
    "properties": {
      "text": {
        "type": "string",
        "description": "Creating content to moderate."
      }
    },
    "required": [
      "text"
    ]
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "is_safe": {
        "type": "boolean"
      },
      "flagged_categories": {
        "type": "array",
        "items": {
          "type": "string"
        }
      },
      "scores": {
        "type": "object"
      }
    }
  },
  "ports": [
    {
      "port_id": "safe",
      "label": "Safe",
      "is_default": true,
      "description": "Content passed checks."
    },
    {
      "port_id": "blocked",
      "label": "Blocked",
      "description": "Content violated safety policy."
    },
    {
      "port_id": "error",
      "label": "Error",
      "description": "Moderation service failure."
    }
  ],
  "execution_mode": "async",
  "tags": [
    "safety",
    "moderation",
    "guardrail"
  ],
  "is_stateful": false,
  "publisher": {
    "identity": "org_sommatic_ai",
    "profile": {
      "name": "Sommatic AI",
      "verified": true,
      "url": "https://me.veripass.com/sommatic",
      "logo_url": null
    }
  }
}
```

### config_schema

```json
{
  "type": "object",
  "properties": {
    "policies": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "title": "Blocked Categories",
      "description": "List of categories to block (e.g. [\"hate\", \"violence\"]). Empty = All."
    },
    "execution": {
      "type": "object",
      "title": "Execution Settings",
      "properties": {
        "alwaysOutputData": {
          "type": "boolean",
          "title": "Always Output Data",
          "description": "Always output data, even on error (if configured).",
          "default": false
        },
        "retryOnFail": {
          "type": "boolean",
          "title": "Retry On Fail",
          "description": "Retry the execution if it fails.",
          "default": false
        },
        "maxTries": {
          "type": "integer",
          "title": "Max Retries",
          "description": "Number of retries.",
          "default": 3,
          "displayOptions": {
            "show": {
              "retryOnFail": [
                true
              ]
            }
          }
        },
        "waitBetweenTries": {
          "type": "integer",
          "title": "Wait Between Retries (ms)",
          "default": 1000,
          "displayOptions": {
            "show": {
              "retryOnFail": [
                true
              ]
            }
          }
        },
        "continueOnFail": {
          "type": "boolean",
          "title": "Continue On Fail",
          "description": "Do not crash workflow on error.",
          "default": false
        },
        "timeout_ms": {
          "type": "integer",
          "title": "Timeout (ms)",
          "description": "Max execution time for this node before it is killed, in milliseconds. Honored by long-running operators (e.g. OCR/extraction, inline code). Default 300000 (5 min).",
          "default": 300000
        }
      }
    }
  }
}
```

### input_contract_schema

```json
{
  "type": "object",
  "properties": {
    "text": {
      "type": "string",
      "description": "Creating content to moderate."
    }
  },
  "required": [
    "text"
  ]
}
```

### output_contract_schema

```json
{
  "type": "object",
  "properties": {
    "is_safe": {
      "type": "boolean"
    },
    "flagged_categories": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "scores": {
      "type": "object"
    }
  }
}
```

### ports

```json
[
  {
    "port_id": "safe",
    "label": "Safe",
    "is_default": true,
    "description": "Content passed checks."
  },
  {
    "port_id": "blocked",
    "label": "Blocked",
    "description": "Content violated safety policy."
  },
  {
    "port_id": "error",
    "label": "Error",
    "description": "Moderation service failure."
  }
]
```
