Skip to main content

grid-safety

GRID Safety layer and Cognitive Privacy Shield: real-time safety enforcement, PII detection, masking, and compliance presets (GDPR, HIPAA, PCI-DSS) for AI inference.

Install

pip install grid-safety

Minimal usage

Cognitive Privacy Shield (library)

from safety.privacy import get_privacy_engine, PrivacyPreset, AsyncPIIDetector

# Get engine with a compliance preset
engine = get_privacy_engine(preset=PrivacyPreset.BALANCED)

# Detect PII
detections = await engine.detect("Contact me at user@example.com")

# Process (detect + mask/block/ask)
result = await engine.process("My SSN is 123-45-6789")
print(result.processed_text)  # Masked or blocked per preset
print(result.detections)

Run the Safety API server

safety-api

Runs the FastAPI app (auth, rate limiting, pre-check, Privacy Shield middleware, inference queue). Configure via environment variables:

Variable Default Description
SAFETY_API_HOST 0.0.0.0 Bind host
SAFETY_API_PORT 8000 Bind port
SAFETY_API_RELOAD (off) Set to 1, true, or yes to enable reload

Endpoints include:

  • POST /infer — Submit inference (enqueued to Redis)
  • POST /privacy/detect — Detect PII in text
  • POST /privacy/mask — Mask or block PII
  • POST /privacy/batch — Batch PII detection/masking (up to 100 texts)
  • GET /health, GET /metrics

Set SAFETY_DEGRADED_MODE=true to run without Redis (e.g. for tests).

Architecture

The Cognitive Privacy Shield is GRID's core safety and privacy API. For pipeline details, integration points, and key files, see:

License

MIT. See LICENSE.

Metadata

Release files for grid-safety 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for grid-safety 1.0.2
File Interpreter ABI Platform
grid_safety-1.0.2-py3-none-any.whl Python 3 none any Details

Release files / grid_safety-1.0.2-py3-none-any.whl

Download URL grid_safety-1.0.2-py3-none-any.whl
Size 244.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2c3dfd3254167eb3a38609d65c71f19ccb123035747a127a4ba83b2f0b6e0576
BLAKE2b-256 checksum
How to use checksums
1c38dce1510c24c73cbd33d09b1992706dd041ac948fd5021dbcc5a1ebbdfb56
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

1.0.2 This release

1 release file

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page