Skip to main content

Overview

Formal policies can enforce different actions at three evaluation stages: session, request, and response. Each stage has specific actions available based on when the policy is evaluated.

Evaluation Stages

Session

When: Connection establishment Actions: allow, block, mfa Use for: Authentication, connection-level access control

Request

When: Before query reaches resource Actions: allow, block, rewrite, decrypt Use for: Query validation, SQL rewriting, blocking writes, decrypting secrets for the upstream

Response

When: After data returns from resource Actions: allow, filter, mask, encrypt Use for: Data masking, PII redaction, filtering results, encrypting secrets before they leave

Common Action Parameters

All actions support these parameters:

Block Action

Deny access and terminate the connection or query.

Parameters

block_with_formal_message returns Formal’s default block text. That message includes the policy ID plus the session ID and request ID when they are available, so users can share those identifiers with their security team.

Example

Allow Action

Explicitly permit an operation. Use in combination with default deny policies.

Example

Rewrite Action

Modify the query or HTTP headers before the request reaches the resource.

Parameters

Example

Example: Rewrite LLM request headers

Example: Redact SSNs from LLM request bodies

String-replace sensitive values in the outbound LLM body so coding agents can continue without sending SSNs upstream. Prefer body rewrites over blocking the session when the goal is redaction.

Filter Action

Remove rows from the result set based on conditions.

Example

Mask Action

Redact or obfuscate sensitive data in responses.

Parameters

Masking Types

Masking Subtypes

  • email_mask_username: ****@example.com
  • email_mask_domain_name: user@*****.***
  • email_mask_while_preserving: a****@e******.com
  • email_mask_with_fake: fake.email@example.com
  • person_full_name_mask_with_fake
  • person_first_name_mask_with_fake
  • person_last_name_mask_with_fake
  • person_ssn_mask_with_fake
  • postal_address_mask_with_fake
  • city_mask_with_fake
  • state_mask_with_fake
  • zip_mask_with_fake
  • location_mask_except_state_country
  • payment_credit_card_number_mask_with_fake
  • payment_credit_card_cvv_mask_with_fake
  • payment_credit_card_exp_mask_with_fake
  • payment_ach_routing_with_fake
  • payment_bitcoin_address_with_fake
  • network_url_mask_with_fake
  • network_ipv4_mask_with_fake
  • network_ipv6_mask_with_fake
  • network_mac_mask_with_fake
  • redact.constant_characters: Replace with custom string
  • redact.first_n_characters: Mask first N chars
  • redact.last_n_characters: Mask last N chars
  • mask_everything_except_last: Show only last N chars

Examples

Mask email usernames:
Replace PII with fake data:
Redact with constant value:

Encrypt & Decrypt Actions

Encrypt and decrypt sensitive HTTP values in-line, so plaintext secrets never reach places that should not see them. Formal encrypts secrets on the way out and decrypts them on the way back in, so tokens stay protected end to end.
  • The encrypt action on the Formal Endpoint is only available on macOS.
  • The encrypt action on the Connector requires configuring a cloud KMS key for token encryption. See Token Encryption for more information.
  • decrypt runs at the request stage. It decrypts Formal-encrypted values before the upstream receives them. If a value fails to decrypt, the request is forwarded unchanged.
  • encrypt runs at the response stage. It encrypts values before they leave the proxy. If encryption fails, the response is blocked.

Parameters

Each target is an object:

Example: Encrypt tokens in a response

Example: Decrypt a request header for the upstream

For an end-to-end Notion MCP walkthrough (Endpoint Secure Enclave or Connector KMS), see Encrypt MCP OAuth Tokens.

MFA Action

The MFA action requires device-owner verification before proceeding with the connection. When a policy returns the mfa action, the Formal Desktop App prompts for device-owner verification before the connection proceeds. On macOS this is Touch ID or the device passcode. On Windows this is Windows Hello (fingerprint, facial recognition, or PIN).
MFA on Windows requires Windows Hello. It’s the strongest form of device-owner verification available. A device with no Windows Hello method configured, or accessed over a remote desktop session where Windows Hello is unavailable, fails the challenge closed and is denied access.

Example

Rule Conflicts and Precedence

When multiple policies apply to the same query, Formal resolves conflicts using least privilege:

Example of Conflict Resolution

Use included_connectors or included_resources to avoid unintended policy conflicts.

Scoping Policies with Connectors and Resources

To prevent policy conflicts when using the default keyword, you can limit which Connectors or Resources a policy applies to.

Include/Exclude Connectors

Use included_connectors to apply a policy only to specific connectors:
Use excluded_connectors to exclude specific connectors:
A single policy cannot use both included_connectors and excluded_connectors. Choose one or the other.

Include/Exclude Resources

Use included_resources to apply a policy only to specific resources:
Use excluded_resources to exclude specific resources:
A single policy cannot use both included_resources and excluded_resources. Choose one or the other.