FastPII Docs
AI Gateway

Gateway Policies

Create, test, and manage FastPII Gateway policies for real-time LLM traffic enforcement.

Gateway Policies

Gateway policies define how FastPII should respond when PII is detected in LLM traffic. Policies let you control behavior per provider, model, entity type, user role, country, or confidence threshold.

Use this page together with Gateway Setup and Audit.

How policies work

Each policy contains:

  • A name and description
  • A numeric priority
  • An action to take when the policy matches
  • One or more conditions
  • A workspace scope
  • An optional is_default flag

When a request passes through the Gateway, matching policies are evaluated by priority and the highest-priority match decides what happens.

Evaluation order

Policies are priority-based.

FieldMeaning
priorityInteger priority value
Lower numberHigher priority
Higher numberLower priority

Example order:

PolicyPriorityEffect
Block credit cards on external models10Evaluated first
Warn on personal email addresses50Evaluated after higher-priority rules
Default mask policy100Fallback behavior

Available actions

The Gateway supports seven policy actions:

ActionWhat it doesCommon use
ALLOWLets the request pass unchangedTrusted internal workflows
WARNAllows the request but records a warningDeveloper or analyst review flows
MASKReplaces sensitive spans before forwardingDefault protection for prompts
BLOCKStops the requestHigh-risk or prohibited data
ESCALATEFlags the request for higher reviewSensitive regulated workflows
LOGRecords the event without changing contentObservation and tuning
QUARANTINEHolds or isolates the request for manual handlingIncident response and strict review

Supported conditions

Each policy can include one or more condition objects.

Condition fieldTypeDescription
entity_typestringMatch a detected entity type, such as EMAIL or CREDIT_CARD
countrystringMatch a country or region code
providerstringMatch a provider, such as openai
modelstringMatch a specific model
workspace_idstringMatch a workspace explicitly
user_rolestringMatch caller role or user segment
confidence_minfloatRequire a minimum detection confidence
sensitivitystringMatch a sensitivity label from your policy model

Example condition set:

[
  {
    "entity_type": "CREDIT_CARD",
    "provider": "openai",
    "confidence_min": 0.9,
    "sensitivity": "restricted"
  }
]

Create a policy

Use POST /api/v1/gateway/policies?workspace_id=... to create a policy.

Request body

{
  "name": "Block payment card data",
  "description": "Block card data before it reaches third-party models",
  "priority": 10,
  "action": "BLOCK",
  "conditions": [
    {
      "entity_type": "CREDIT_CARD",
      "confidence_min": 0.9,
      "provider": "openai"
    }
  ],
  "workspace_id": "ws_prod_eu",
  "is_default": false
}

curl

curl -X POST "$FASTPII_BASE_URL/api/v1/gateway/policies?workspace_id=$FASTPII_WORKSPACE_ID" \
  -H "Content-Type: application/json" \
  -H "X-Service-Token: $FASTPII_SERVICE_TOKEN" \
  -d '{
    "name": "Block payment card data",
    "description": "Block card data before it reaches third-party models",
    "priority": 10,
    "action": "BLOCK",
    "conditions": [
      {
        "entity_type": "CREDIT_CARD",
        "confidence_min": 0.9,
        "provider": "openai"
      }
    ],
    "workspace_id": "ws_prod_eu",
    "is_default": false
  }'

Python

import requests

base_url = "https://gateway.fastpii.com"
service_token = "your-gateway-service-token"
workspace_id = "ws_prod_eu"

payload = {
    "name": "Block payment card data",
    "description": "Block card data before it reaches third-party models",
    "priority": 10,
    "action": "BLOCK",
    "conditions": [
        {
            "entity_type": "CREDIT_CARD",
            "confidence_min": 0.9,
            "provider": "openai",
        }
    ],
    "workspace_id": workspace_id,
    "is_default": False,
}

response = requests.post(
    f"{base_url}/api/v1/gateway/policies",
    params={"workspace_id": workspace_id},
    headers={
        "X-Service-Token": service_token,
        "Content-Type": "application/json",
    },
    json=payload,
    timeout=30,
)
response.raise_for_status()
print(response.json())

Example response:

{
  "id": "pol_01J9X85SP6VC0Y5WKH4WMS83VY",
  "name": "Block payment card data",
  "description": "Block card data before it reaches third-party models",
  "priority": 10,
  "action": "BLOCK",
  "conditions": [
    {
      "entity_type": "CREDIT_CARD",
      "country": null,
      "provider": "openai",
      "model": null,
      "workspace_id": null,
      "user_role": null,
      "confidence_min": 0.9,
      "sensitivity": null
    }
  ],
  "is_default": false,
  "workspace_id": "ws_prod_eu",
  "created_at": "2026-07-10T10:01:12.200000Z",
  "updated_at": "2026-07-10T10:01:12.200000Z"
}

List policies

Use GET /api/v1/gateway/policies to retrieve policies for a workspace. You can filter by action, is_default, page, and page_size.

curl

curl -X GET "$FASTPII_BASE_URL/api/v1/gateway/policies?workspace_id=$FASTPII_WORKSPACE_ID&action=BLOCK&is_default=false&page=1&page_size=20" \
  -H "X-Service-Token: $FASTPII_SERVICE_TOKEN"

Python

import requests

response = requests.get(
    f"{base_url}/api/v1/gateway/policies",
    params={
        "workspace_id": workspace_id,
        "action": "BLOCK",
        "is_default": "false",
        "page": 1,
        "page_size": 20,
    },
    headers={"X-Service-Token": service_token},
    timeout=30,
)
response.raise_for_status()
print(response.json())

Example response:

{
  "policies": [
    {
      "id": "pol_01J9X85SP6VC0Y5WKH4WMS83VY",
      "name": "Block payment card data",
      "description": "Block card data before it reaches third-party models",
      "priority": 10,
      "action": "BLOCK",
      "conditions": [
        {
          "entity_type": "CREDIT_CARD",
          "country": null,
          "provider": "openai",
          "model": null,
          "workspace_id": null,
          "user_role": null,
          "confidence_min": 0.9,
          "sensitivity": null
        }
      ],
      "is_default": false,
      "workspace_id": "ws_prod_eu",
      "created_at": "2026-07-10T10:01:12.200000Z",
      "updated_at": "2026-07-10T10:01:12.200000Z"
    }
  ],
  "total": 1,
  "page": 1,
  "page_size": 20
}

Get a single policy

Use GET /api/v1/gateway/policies/{policy_id} to inspect one policy.

curl

curl -X GET "$FASTPII_BASE_URL/api/v1/gateway/policies/pol_01J9X85SP6VC0Y5WKH4WMS83VY" \
  -H "X-Service-Token: $FASTPII_SERVICE_TOKEN"

Python

import requests

policy_id = "pol_01J9X85SP6VC0Y5WKH4WMS83VY"

response = requests.get(
    f"{base_url}/api/v1/gateway/policies/{policy_id}",
    headers={"X-Service-Token": service_token},
    timeout=30,
)
response.raise_for_status()
print(response.json())

Update a policy

Use PUT /api/v1/gateway/policies/{policy_id} to change the action, conditions, description, or priority.

Request body

{
  "name": "Mask payment card data",
  "description": "Mask card data instead of blocking for trusted support flows",
  "priority": 20,
  "action": "MASK",
  "conditions": [
    {
      "entity_type": "CREDIT_CARD",
      "provider": "openai",
      "user_role": "support_agent",
      "confidence_min": 0.9
    }
  ]
}

curl

curl -X PUT "$FASTPII_BASE_URL/api/v1/gateway/policies/pol_01J9X85SP6VC0Y5WKH4WMS83VY" \
  -H "Content-Type: application/json" \
  -H "X-Service-Token: $FASTPII_SERVICE_TOKEN" \
  -d '{
    "name": "Mask payment card data",
    "description": "Mask card data instead of blocking for trusted support flows",
    "priority": 20,
    "action": "MASK",
    "conditions": [
      {
        "entity_type": "CREDIT_CARD",
        "provider": "openai",
        "user_role": "support_agent",
        "confidence_min": 0.9
      }
    ]
  }'

Python

import requests

policy_id = "pol_01J9X85SP6VC0Y5WKH4WMS83VY"

payload = {
    "name": "Mask payment card data",
    "description": "Mask card data instead of blocking for trusted support flows",
    "priority": 20,
    "action": "MASK",
    "conditions": [
        {
            "entity_type": "CREDIT_CARD",
            "provider": "openai",
            "user_role": "support_agent",
            "confidence_min": 0.9,
        }
    ],
}

response = requests.put(
    f"{base_url}/api/v1/gateway/policies/{policy_id}",
    headers={
        "X-Service-Token": service_token,
        "Content-Type": "application/json",
    },
    json=payload,
    timeout=30,
)
response.raise_for_status()
print(response.json())

Example response:

{
  "id": "pol_01J9X85SP6VC0Y5WKH4WMS83VY",
  "name": "Mask payment card data",
  "description": "Mask card data instead of blocking for trusted support flows",
  "priority": 20,
  "action": "MASK",
  "conditions": [
    {
      "entity_type": "CREDIT_CARD",
      "country": null,
      "provider": "openai",
      "model": null,
      "workspace_id": null,
      "user_role": "support_agent",
      "confidence_min": 0.9,
      "sensitivity": null
    }
  ],
  "is_default": false,
  "workspace_id": "ws_prod_eu",
  "created_at": "2026-07-10T10:01:12.200000Z",
  "updated_at": "2026-07-10T10:04:19.801000Z"
}

Delete a policy

Use DELETE /api/v1/gateway/policies/{policy_id} to remove a policy. A successful delete returns 204 No Content.

curl

curl -X DELETE "$FASTPII_BASE_URL/api/v1/gateway/policies/pol_01J9X85SP6VC0Y5WKH4WMS83VY" \
  -H "X-Service-Token: $FASTPII_SERVICE_TOKEN"

Python

import requests

policy_id = "pol_01J9X85SP6VC0Y5WKH4WMS83VY"

response = requests.delete(
    f"{base_url}/api/v1/gateway/policies/{policy_id}",
    headers={"X-Service-Token": service_token},
    timeout=30,
)
response.raise_for_status()
print(response.status_code)

Expected response status:

204

Test a policy

Use POST /api/v1/gateway/policies/{policy_id}/test to evaluate sample text before putting the policy into production.

Request body

{
  "text": "Send john.doe@example.com and 4111 1111 1111 1111 to OpenAI",
  "entity_types": ["EMAIL", "CREDIT_CARD"],
  "country": "CZ",
  "provider": "openai",
  "model": "gpt-4o-mini"
}

curl

curl -X POST "$FASTPII_BASE_URL/api/v1/gateway/policies/pol_01J9X85SP6VC0Y5WKH4WMS83VY/test" \
  -H "Content-Type: application/json" \
  -H "X-Service-Token: $FASTPII_SERVICE_TOKEN" \
  -d '{
    "text": "Send john.doe@example.com and 4111 1111 1111 1111 to OpenAI",
    "entity_types": ["EMAIL", "CREDIT_CARD"],
    "country": "CZ",
    "provider": "openai",
    "model": "gpt-4o-mini"
  }'

Python

import requests

policy_id = "pol_01J9X85SP6VC0Y5WKH4WMS83VY"

payload = {
    "text": "Send john.doe@example.com and 4111 1111 1111 1111 to OpenAI",
    "entity_types": ["EMAIL", "CREDIT_CARD"],
    "country": "CZ",
    "provider": "openai",
    "model": "gpt-4o-mini",
}

response = requests.post(
    f"{base_url}/api/v1/gateway/policies/{policy_id}/test",
    headers={
        "X-Service-Token": service_token,
        "Content-Type": "application/json",
    },
    json=payload,
    timeout=30,
)
response.raise_for_status()
print(response.json())

Example response:

{
  "matched": true,
  "action": "MASK",
  "matched_policy": {
    "id": "pol_01J9X85SP6VC0Y5WKH4WMS83VY",
    "name": "Mask payment card data",
    "description": "Mask card data instead of blocking for trusted support flows",
    "priority": 20,
    "action": "MASK",
    "conditions": [
      {
        "entity_type": "CREDIT_CARD",
        "country": null,
        "provider": "openai",
        "model": null,
        "workspace_id": null,
        "user_role": "support_agent",
        "confidence_min": 0.9,
        "sensitivity": null
      }
    ],
    "is_default": false,
    "workspace_id": "ws_prod_eu",
    "created_at": "2026-07-10T10:01:12.200000Z",
    "updated_at": "2026-07-10T10:04:19.801000Z"
  },
  "entity_types_detected": ["EMAIL", "CREDIT_CARD"]
}

Default policies

Set is_default to true for fallback policies that should apply when no more specific rule wins. A common pattern is:

  • High-priority BLOCK rules for critical entities
  • Mid-priority WARN or ESCALATE rules for special workflows
  • Lower-priority MASK default policy for general traffic

Example default policy body:

{
  "name": "Default mask policy",
  "description": "Apply masking to unmatched medium-risk traffic",
  "priority": 100,
  "action": "MASK",
  "conditions": [
    {
      "confidence_min": 0.7
    }
  ],
  "workspace_id": "ws_prod_eu",
  "is_default": true
}
  • Keep critical BLOCK rules at low numeric priority values
  • Use MASK for most production prompt sanitization
  • Add LOG or WARN policies first when you are learning traffic patterns
  • Test every policy with representative prompts before rollout
  • Review policy outcomes in Audit and dashboard metrics regularly

On this page