Skip to main content

Policies

A policy tells PromptVeil what to do when a detector finds an entity. It is a YAML file (or a PolicyConfig built in code).

policy.yaml
version: "1.0"
default_action: allow # fallback when no rule matches: mask | block | allow

rules:
- type: email
action: mask
min_confidence: 0.8 # optional: skip this rule below 0.8 confidence
- type: credit_card
action: block
- type: api_key
action: block

Actions​

ActionBehaviour
maskReplaces the value with a partially hidden placeholder (a***@example.com, last-4 for cards)
blockRaises SensitiveDataError; the prompt is never forwarded
allowPasses the value through unchanged

Loading a policy​

from promptveil import Shield

shield = Shield(config_path="policy.yaml")

Or build one in code, no YAML needed:

from promptveil.policy import Action, PolicyConfig, Rule

config = PolicyConfig(
default_action=Action.ALLOW,
rules=[Rule(type="email", action=Action.MASK)],
)
shield = Shield(config=config)

Choosing detectors​

Rules only fire for entity types some detector produces. RegexDetector is the default; add regional detectors explicitly:

from promptveil import Shield
from promptveil.detector import RegexDetector, IndiaDetector

shield = Shield(
config_path="policy.yaml",
detectors=[RegexDetector(), IndiaDetector()],
)

Entity types​

TypeDetectorExample
email, phone, credit_card, api_keyRegexDetectoralice@example.com
in_aadhaar, in_pan, in_gstin, in_ifsc, in_passport, in_voter_id, in_phoneIndiaDetectorABCDE1234F
ssn, us_passport, us_einUSDetector123-45-6789

See the API reference for the full schema.