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

# AI Context Rules

> Contacts and sessions can carry custom data — plan type, preferred language, order IDs, and more.

## What's This?

Contacts and sessions can carry custom data — plan type, preferred language, order IDs, and more. AI Context Rules let you control which of those fields the AI can see when crafting responses, helping you balance personalization with data privacy.

## Filtering Modes

<CardGroup cols={2}>
  <Card title="Allow All" icon="check-double">
    AI sees all custom data fields. Best when no data is sensitive.
  </Card>

  <Card title="Block All" icon="ban">
    No custom data is shared with the AI. Most restrictive.
  </Card>

  <Card title="Allow Only Specific Keys" icon="list-check">
    Only whitelisted keys are visible. Good for selectively sharing relevant fields.
  </Card>

  <Card title="Block Specific Keys" icon="filter">
    All data is shared except blacklisted keys. Good for excluding a few sensitive fields.
  </Card>
</CardGroup>

## How to Configure

<Steps>
  <Step title="Open AI Context Settings">
    Navigate to **Settings → AI Context** in the dashboard.
  </Step>

  <Step title="Choose a Filtering Mode">
    Select a mode for **Contact Custom Data** and/or **Session Custom Data**.
  </Step>

  <Step title="Specify Keys (if applicable)">
    If using "Allow only specific keys" or "Block specific keys", type key names and press Enter to add them.
  </Step>

  <Step title="Save">
    Click **Save** to apply the rules.
  </Step>
</Steps>

## How Custom Data Reaches the AI

* Custom data is attached to contacts (via API or CRM sync) and sessions (via widget, API, or integrations).
* When the AI responds, the filter rules are applied before any data is included.
* Only allowed fields make it into the AI's context.
* Filtered data appears in the AI's system prompt as structured context.

## Default Behavior

<Note>
  By default, no custom data is shared with the AI. You must configure rules to enable it. This ensures sensitive data isn't accidentally exposed.
</Note>

## Passing Custom Data

<CardGroup cols={2}>
  <Card title="Via Chat Widget" icon="browser" href="/widget/configuration">
    Pass custom data using `sessionCustomData` and context parameters when initializing the widget.
  </Card>

  <Card title="Via API" icon="code" href="/api-reference/contacts/introduction">
    Set contact `custom_data` when [creating contacts](/api-reference/contacts/create), or set session-level `custom_data` when [creating sessions](/api-reference/chat-sessions/create) or with [Send Message](/api-reference/chat-sessions/send).
  </Card>
</CardGroup>
