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 controlRequest
When: Before query reaches resource Actions:
allow, block,
rewrite, decrypt Use for: Query validation, SQL rewriting, blocking writes, decrypting secrets for the upstreamResponse
When: After data returns from resource Actions:
allow, filter,
mask, encrypt Use for: Data masking, PII redaction, filtering results, encrypting secrets before they leaveCommon 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. Preferbody 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 Masking
Email Masking
email_mask_username:****@example.comemail_mask_domain_name:user@*****.***email_mask_while_preserving:a****@e******.comemail_mask_with_fake:fake.email@example.com
Personal Information
Personal Information
person_full_name_mask_with_fakeperson_first_name_mask_with_fakeperson_last_name_mask_with_fakeperson_ssn_mask_with_fake
Location Data
Location Data
postal_address_mask_with_fakecity_mask_with_fakestate_mask_with_fakezip_mask_with_fakelocation_mask_except_state_country
Payment Data
Payment Data
payment_credit_card_number_mask_with_fakepayment_credit_card_cvv_mask_with_fakepayment_credit_card_exp_mask_with_fakepayment_ach_routing_with_fakepayment_bitcoin_address_with_fake
Network Data
Network Data
network_url_mask_with_fakenetwork_ipv4_mask_with_fakenetwork_ipv6_mask_with_fakenetwork_mac_mask_with_fake
General Redaction
General Redaction
redact.constant_characters: Replace with custom stringredact.first_n_characters: Mask first N charsredact.last_n_characters: Mask last N charsmask_everything_except_last: Show only last N chars
Examples
Mask email usernames: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
encryptaction on the Formal Endpoint is only available on macOS. - The
encryptaction on the Connector requires configuring a cloud KMS key for token encryption. See Token Encryption for more information.
decryptruns 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.encryptruns 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
MFA Action
The MFA action requires device-owner verification before proceeding with the connection. When a policy returns themfa 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).
Example
Rule Conflicts and Precedence
When multiple policies apply to the same query, Formal resolves conflicts using least privilege:Example of Conflict Resolution
Scoping Policies with Connectors and Resources
To prevent policy conflicts when using thedefault keyword, you can limit which Connectors or Resources a policy applies to.
Include/Exclude Connectors
Useincluded_connectors to apply a policy only to specific connectors:
excluded_connectors to exclude specific connectors:
Include/Exclude Resources
Useincluded_resources to apply a policy only to specific resources:
excluded_resources to exclude specific resources: