Skip to content

ContextShield

ContextShield is the security perimeter of ContextUnity. It provides declarative security through prompt injection detection, policy-based authorization, compliance auditing, and cryptographic token management.

AI Firewall

Prompt injection, jailbreak, and PII leak detection with configurable YAML rule sets.

Policy Engine

Declarative ABAC policies with ContextToken integration for fine-grained access control.

Compliance

SOC 2, GDPR, HIPAA, and PCI DSS posture validation and audit trails.

Delegation Chains

Cryptographic permission attenuation for multi-hop agent architectures.

Architecture

shield

Key Components

AI Firewall (firewall/)

The Shield orchestrates multiple validators:

  • InjectionValidator — detects prompt injection attempts
  • JailbreakValidator — detects jailbreak patterns
  • PIIValidator — detects PII (names, phones, IDs) via regex + Presidio ML
  • RAGContextValidator — validates retrieval context integrity

PII detection rules are loaded from firewall/rules/pii.yaml — no redeployment needed to add new rules.

Policy Engine (policy.py)

Declarative attribute-based access control:

from contextshield import PolicyEngine, Policy
engine = PolicyEngine()
engine.add_policy(Policy(
name="brain_read",
conditions={"permission": "brain:read", "tenant": "my_project"},
effect="allow",
))
result = engine.evaluate(token, resource="brain", action="read")

Delegation Chains (delegation.py)

Cryptographic permission attenuation for multi-hop calls:

from contextshield.delegation import DelegationChain
# Parent delegates subset of permissions to child
chain = DelegationChain(parent_token)
child_token = chain.attenuate(
permissions=("brain:read",), # Subset of parent's permissions
ttl_seconds=3600,
)

gRPC Service (14 RPCs)

RPCDescription
ScanAI firewall scan (injection/PII detection)
EvaluatePolicyPolicy engine evaluation
CheckComplianceCompliance posture check
RecordAuditRecord audit event
MintTokenCreate signed ContextToken
VerifyTokenVerify token signature and validity
RevokeTokenAdd to revocation list
GetStatsSecurity metrics and statistics
GetSecretRetrieve a secret
PutSecretStore a secret
ListSecretsList stored secrets
RotateSecretRotate a secret
EncryptEncrypt data
DecryptDecrypt data

CLI

Terminal window
# Key management
python -m contextshield keygen
python -m contextshield rotate
# Token operations
python -m contextshield mint --tenant my_project --permissions brain:read
python -m contextshield verify --token <token>
# Status
python -m contextshield status