> ## Documentation Index
> Fetch the complete documentation index at: https://docs.formal.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Govern Notion AI prompts with Formal

> Audit, block, and redact Notion AI chat prompts with Formal Endpoint and HTTP policies.

## Overview

Audit, block, or mask Notion AI chat prompts with Formal Endpoint. The [HTTP policies](https://docs.formal.ai/docs/guides/core-concepts/resources/http.md#policy-evaluation) leave ordinary edits, comments, and sync alone.

Employee laptop

Browser or Notion app

Formal Endpoint

Block: stop here

![](https://docs.formal.ai/static/brands/notion.svg)
Notion

Allow or mask

To govern MCP tool calls instead, see [Notion MCP](https://docs.formal.ai/docs/guides/core-concepts/connectors/mcp-servers/notion.md).

## 1. Add a network rule

1. Enable [Transparent Mode](https://docs.formal.ai/docs/guides/client-apps/transparent-mode.md) and trust the Formal CA.
2. Create this [network rule](https://app.formal.ai/network-rules) and set it to **Active**. No Connector is required.
3. Open Notion in your browser and in Notion Desktop. Confirm the app loads and the hostname appears in [Logs](https://app.formal.ai/logs).

```cel theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
{
  "condition": {
    "pre_tcp": port == 443,
    "pre_tls": port == 443 && (
      hostname in ["app.notion.com", "www.notion.so", "realtime.app.notion.com", "realtime.www.notion.so"] ||
      hostname.matches("^msgstore(-[0-9]+(-v2)?)?[.](app[.]notion[.]com|www[.]notion[.]so)$")
    ),
    "post_tls": technology == "http" && (
      hostname in ["app.notion.com", "www.notion.so", "realtime.app.notion.com", "realtime.www.notion.so"] ||
      hostname.matches("^msgstore(-[0-9]+(-v2)?)?[.](app[.]notion[.]com|www[.]notion[.]so)$")
    )
  }
}
```

The rule matches `app.notion.com`, `www.notion.so`, and their `realtime` and `msgstore` hosts, including numbered hosts like `msgstore-001.app.notion.com`.

The policies below match AI POSTs on the two app hosts only. To restrict workspace access instead, see [Notion's network control guidance](https://www.notion.com/help/network-control).

## 2. Policy examples

To scope a policy to one user, add `input.user.email == "alice@example.com"` to its `request` rule. [Dry run](https://docs.formal.ai/docs/guides/policies/enforcement.md) logs policy decisions without enforcing them.

### 2.1 Audit prompt requests

Set this policy to **Dry run**. In [Logs](https://docs.formal.ai/docs/guides/observability/logs.md), filter for `createAgentThread` or `sendEventToAgentThread`. A matching request shows a dry-run block decision but still reaches Notion.

```rego theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
package formal.v2

import rego.v1

notion_ai_paths := {
	"/api/v3/createAgentThread",
	"/api/v3/sendEventToAgentThread",
	"/api/v3/runInferenceTranscript",
	"/api/v3/getCompletion",
}

request := {"action": "block", "type": "block_with_formal_message", "reason": "Notion AI prompt detected"} if {
	input.resource.technology == "http"
	input.http.hostname in {"app.notion.com", "www.notion.so"}
	input.http.method == "POST"
	input.http.path in notion_ai_paths
}
```

### 2.2 Block chat requests

Set this policy to **Active** to block new chats, follow-ups, and legacy inference. Notion may show its own error instead of the policy message.

```rego theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
package formal.v2

import rego.v1

notion_ai_paths := {
	"/api/v3/createAgentThread",
	"/api/v3/sendEventToAgentThread",
	"/api/v3/runInferenceTranscript",
	"/api/v3/getCompletion",
}

request := {
	"action": "block",
	"type": "block_with_custom_message",
	"message": "Notion AI is disabled on this device.",
	"reason": "Notion AI kill switch",
} if {
	input.resource.technology == "http"
	input.http.hostname in {"app.notion.com", "www.notion.so"}
	input.http.method == "POST"
	input.http.path in notion_ai_paths
}
```

### 2.3 Block requests containing sensitive data

This policy looks for emails, OpenAI and Anthropic key patterns, and AWS access key IDs. It scans the full body, including metadata.

```rego theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
package formal.v2

import rego.v1

notion_ai_paths := {
	"/api/v3/createAgentThread",
	"/api/v3/sendEventToAgentThread",
	"/api/v3/runInferenceTranscript",
	"/api/v3/getCompletion",
}

pattern := `(?i)[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}|sk-(proj-|ant-)?[A-Za-z0-9_-]{16,}|AKIA[A-Z0-9]{16}`

request := {
	"action": "block",
	"type": "block_with_custom_message",
	"message": "Notion AI prompt contains sensitive data.",
	"reason": "Sensitive data in Notion AI prompt",
} if {
	input.resource.technology == "http"
	input.http.hostname in {"app.notion.com", "www.notion.so"}
	input.http.method == "POST"
	input.http.path in notion_ai_paths
	regex.match(pattern, input.http.body)
}
```

### 2.4 Redact matching prompt text

This [body rewrite](https://docs.formal.ai/docs/guides/core-concepts/resources/http.md#body-rewrites) replaces matching prompt text with `[REDACTED]` in new chats and follow-ups. It strips annotations from changed spans so links cannot carry the original value. It does not rewrite legacy inference requests.

Start in **Dry run**. Activate redaction for one user and check the forwarded body in **Logs**. A block policy on the same request takes precedence.

> [!WARNING]
>
> To exclude original bodies from Logs, drop `log.request.http.body.received` in the Endpoint [log schema](https://docs.formal.ai/docs/guides/observability/log-schemas.md). Policy inputs have separate retention settings.

```rego theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
package formal.v2

import rego.v1

pattern := `(?i)[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}|sk-(proj-|ant-)?[A-Za-z0-9_-]{16,}|AKIA[A-Z0-9]{16}`

content_prefix := ["content"] if input.http.path == "/api/v3/createAgentThread"

content_prefix := ["event", "content"] if {
	input.http.path == "/api/v3/sendEventToAgentThread"
	input.http.json.event.type == "user.message"
}

patches := [{"op": "replace", "path": array.concat(content_prefix, [i, "text", j]), "value": [regex.replace(span[0], pattern, "[REDACTED]")]} |
	some i, part in object.get(input.http.json, content_prefix, [])
	part.type == "text"
	some j, span in part.text
	is_string(span[0])
	regex.match(pattern, span[0])
]

request := {
	"action": "rewrite",
	"json": json.patch(input.http.json, patches),
	"reason": "Redact sensitive data in Notion AI prompt",
} if {
	input.resource.technology == "http"
	input.http.hostname in {"app.notion.com", "www.notion.so"}
	input.http.method == "POST"
	count(patches) > 0
}
```

Redaction and the raw-body block can miss values split across formatted text spans.

## 3. Verify on a pilot device

| Notion action | Sensitive data block | Redaction | Chat block |
| - | - | - | - |
| New chat: `Email test@example.com about the roadmap` | Blocked | Notion receives `Email [REDACTED] about the roadmap` | Blocked |
| Follow-up: `Check sk-proj-AAAAAAAAAAAAAAAAAAAA` | Blocked | Notion receives `Check [REDACTED]` | Blocked |
| `Write a haiku about databases` | Sent unchanged | Sent unchanged | Blocked |
| Edit a page and add a comment | Both sync | Both sync | Both sync |

In **Logs**, check the policy decision and, for redaction, the forwarded body.

## Reference: Notion AI request shapes

| Purpose | HTTP request | Prompt field |
| - | - | - |
| First message in a chat | `POST /api/v3/createAgentThread` | `content[].text` |
| Follow-up message | `POST /api/v3/sendEventToAgentThread` with `event.type == "user.message"` | `event.content[].text` |
| Legacy inference | `POST /api/v3/runInferenceTranscript` or `POST /api/v3/getCompletion` | `transcript[].value` or `context.prompt` |
| Page edits, comments, and sync | `saveTransactions*`, `syncRecordValues*`, `loadPageChunk`, and other shared paths | Not targeted by the block or rewrite examples |

Each prompt span starts with a string and can include annotations such as links.

### New chat

```json theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
{
  "content": [
    {
      "type": "text",
      "text": [
        ["Email "],
        ["a@example.com"]
      ]
    }
  ]
}
```

### Follow-up message

```json theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
{
  "event": {
    "type": "user.message",
    "content": [
      {
        "type": "text",
        "text": [
          ["Write a poem"]
        ]
      }
    ]
  }
}
```

## Limitations

* **Private API:** Notion can change request paths and payloads without notice.
* **Answers are not inspected:** A follow-up request can return a `disposition` of `steered`. Notion can send the answer separately over its realtime sync channel. These policies block or redact prompts, not answers.
* **Logs show raw request JSON:** When body logging is enabled, Logs show the HTTP body. Formal does not extract separate Notion AI prompt or answer fields as it does for ChatGPT, Claude, and Cursor.
* **Chat only:** Inline **Ask AI**, AI blocks, database autofill, and meeting notes may use different request paths.
* **Shared writes:** Some Notion clients can save a prompt through a shared transaction path before inference. These policies leave those writes alone.
* **Body capture:** HTTP audit events have a shared body budget of about 500 KiB. Larger bodies can be truncated in Logs.
* **Workspace-wide stop:** To stop AI across the workspace, disable Notion AI in Notion's workspace settings where available.


## Related topics

- [Govern Claude with Formal](https://docs.formal.ai/docs/guides/ai-governance/tools/claude.md)
- [Govern Cursor with Formal](https://docs.formal.ai/docs/guides/ai-governance/tools/cursor.md)
- [Govern AI Usage](https://docs.formal.ai/docs/guides/use-cases/govern-ai-usage.md)
- [Govern ChatGPT and Codex with Formal](https://docs.formal.ai/docs/guides/ai-governance/tools/chatgpt.md)
- [Notion](https://docs.formal.ai/docs/guides/core-concepts/connectors/mcp-servers/notion.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.