# Content safety

> Remove personal data before it reaches a model, and check what goes in and comes out.

Applies to: the Sypnia engine (open source, self-hosted) and Sypnia Cloud (paid service).  
Source: https://ai.docs.sypnia.com/safety/content-safety/

For agents: Redaction (route safety.redact: email, phone, card, national-id, address; custom regex patterns): replaced before sending with placeholders [email-1]…; restore: true puts originals back in the answer (not in streamed chunks until complete per placeholder). Moderation (safety.moderation off|input|both; categories violence, hate, sexual, self-harm, harassment, illegal): blocked → 422 content_blocked {stage, categories}; self-harm returns help text option; costs a small classification call counted in usage. POST /v1/moderations to check text on its own. Off by default; recommended for browser routes.

## Redaction: personal data stays out

A route can remove personal data from what it sends, so the model never sees it:

`sypnia.toml`

```toml
[ai.tasks.chat]
safety = { redact = ["email", "phone", "card"], restore = true }
```

| Kind             | What is found                               |
| ---------------- | ------------------------------------------- |
| `email`, `phone` | e-mail addresses and phone numbers          |
| `card`           | payment card numbers                        |
| `national-id`    | identity numbers in common national formats |
| `address`        | street addresses                            |
| `patterns`       | your own, as regular expressions            |

The model sees `[email-1]`, `[phone-1]`. With `restore: true`, the gateway puts the originals back in the answer before your app gets it.

## Moderation: check what goes in and comes out

```yaml
    safety:
      moderation: input      # off | input | both
```

The gateway checks the text for violence, hate, sexual content, self-harm, harassment and illegal requests. What is blocked answers `422 content_blocked`, with the stage (`input` or `output`) and the categories, so your app can show its own message. Each check is a small call, counted in usage like any other.

Both are off by default. For a task that browsers may call, turn on at least `moderation: input`.

To check a text on its own, without asking a model anything: `POST /v1/moderations`.
