Skip to main content
The guardrails-blindfold package integrates Blindfold with Guardrails AI, letting you add PII protection to any Guard with one line. Detect and fix PII in LLM outputs automatically.

Installation

pip install guardrails-blindfold
Set your API key:
export BLINDFOLD_API_KEY=your-api-key
Get a free API key at app.blindfold.dev.

Quick Start

from guardrails import Guard
from guardrails_blindfold import BlindfoldPII

guard = Guard().use(BlindfoldPII(on_fail="fix"))

result = guard.validate("Contact John Doe at john@example.com")
print(result.validated_output)
# → "Contact <Person_1> at <Email Address_1>"

Parameters

ParameterTypeDefaultDescription
policystr"basic"Detection policy
pii_methodstr"tokenize"How to fix detected PII
regionstrNone"eu" or "us" for data residency
entitieslistNoneSpecific entity types to detect
score_thresholdfloatNoneConfidence threshold (0.0–1.0)
api_keystrNoneFalls back to BLINDFOLD_API_KEY env var
on_failstrNoneGuardrails failure action

Policies

PolicyEntitiesBest For
basicNames, emails, phones, locationsGeneral PII protection
gdpr_euEU-specific: IBANs, addresses, dates of birthGDPR compliance
hipaa_usPHI: SSNs, MRNs, medical termsHIPAA compliance
pci_dssCard numbers, CVVs, expiry datesPCI DSS compliance
strictAll entity types, lower thresholdMaximum detection
See Policies for details.

PII Methods

The pii_method parameter controls how detected PII is fixed when on_fail="fix":
MethodOutputReversible
tokenize<Person_1>, <Email Address_1>Yes
redactPII removed entirelyNo
maskJ****oe, j****omNo
hashHASH_abc123No
synthesizeJane Smith, jane@example.orgNo
encryptAES-256 encrypted valueYes (with key)

Usage Examples

GDPR Compliance with EU Region

guard = Guard().use(
    BlindfoldPII(
        policy="gdpr_eu",
        region="eu",
        on_fail="fix",
    )
)

result = guard.validate("Hans Mueller, hans.mueller@example.de, IBAN DE89370400440532013000")
print(result.validated_output)
# → "<Person_1>, <Email Address_1>, IBAN <IBAN_1>"

HIPAA — Redact PHI

guard = Guard().use(
    BlindfoldPII(
        policy="hipaa_us",
        pii_method="redact",
        region="us",
        on_fail="fix",
    )
)

result = guard.validate("Patient Sarah Jones, SSN 123-45-6789, MRN 4567890")
print(result.validated_output)
# → PHI redacted from output

Block Output if PII Detected

Use on_fail="exception" to raise an error instead of fixing:
from guardrails.errors import ValidationError

guard = Guard().use(
    BlindfoldPII(policy="strict", on_fail="exception")
)

try:
    result = guard.validate("Email john@example.com")
except ValidationError as e:
    print("PII detected — output blocked")

Detect Specific Entity Types

guard = Guard().use(
    BlindfoldPII(
        entities=["Email Address", "Phone Number", "Credit Card Number"],
        on_fail="fix",
    )
)

Chain with Other Validators

Blindfold can be combined with any other Guardrails validator:
guard = Guard().use(
    BlindfoldPII(policy="strict", on_fail="fix"),
).use(
    AnotherValidator(on_fail="exception"),
)

Protect LLM Output in a Chain

from guardrails import Guard
from guardrails_blindfold import BlindfoldPII
from openai import OpenAI

client = OpenAI()
guard = Guard().use(BlindfoldPII(policy="gdpr_eu", on_fail="fix"))

response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "Write a sample customer profile"}],
)

# Validate and protect PII in the LLM output
result = guard.validate(response.choices[0].message.content)
print(result.validated_output)  # PII tokenized

On-Fail Actions

Guardrails supports several failure handling strategies:
ActionBehavior
fixReplace PII with the protected version (tokenized, redacted, etc.)
exceptionRaise ValidationError — blocks the output entirely
noopLog the failure but return the original output unchanged
reaskRe-prompt the LLM to regenerate without PII

Data Residency

Use the region parameter to ensure PII is processed in a specific jurisdiction:
RegionEndpointLocation
eueu-api.blindfold.devFrankfurt, Germany
usus-api.blindfold.devVirginia, US
See Regions for details.