Shield

Go Packages

Quick reference for all Shield Go packages and their public APIs.

All Shield packages are importable from github.com/xraph/shield.

Core packages

github.com/xraph/shield

Root package. Exports context helpers, error constants, configuration, and shared types.

ExportDescription
WithTenant(ctx, id)Inject tenant ID into context
WithApp(ctx, id)Inject app ID into context
TenantFromContext(ctx)Read tenant ID from context
AppFromContext(ctx)Read app ID from context
ConfigEngine configuration struct
DefaultConfig()Returns default Config values
EntityBase type with timestamps
VersionCurrent library version
ErrNoStore, ErrInputBlocked, ErrOutputBlocked, ...Sentinel errors

github.com/xraph/shield/engine

The core layered safety engine.

ExportDescription
New(...Option) (*Engine, error)Create an engine
Engine.ScanInput(ctx, *scan.Input)Scan user input content
Engine.ScanOutput(ctx, *scan.Input)Scan agent output content
Engine.Stop(ctx)Graceful shutdown
WithStore(s)Set composite store
WithPlugin(p)Register lifecycle plugin
WithConfig(cfg)Set engine configuration
WithLogger(l)Set structured logger

github.com/xraph/shield/scan

Scan input/output types, findings, and results.

ExportDescription
InputContent to scan
ResultComplete scan output
FindingIndividual detection from a safety layer
DirectionInput or output direction
DecisionAllow, block, flag, or redact
StatsAggregated scan statistics

Safety layer packages

github.com/xraph/shield/instinct

Pre-conscious threat detection. Categories: injection, exfiltration, manipulation, jailbreak.

ExportDescription
InstinctEntity with strategies, sensitivity, and action
CategoryInjection, Exfiltration, Manipulation, Jailbreak
SensitivityParanoid, Cautious, Balanced, Relaxed, Permissive
StrategyDetection strategy with name, weight, config
StoreCRUD persistence interface

github.com/xraph/shield/awareness

Perception layer — PII, topic, sentiment, intent, language detection.

ExportDescription
AwarenessEntity with focus, detectors, and action
FocusPII, Topic, Sentiment, Intent, Language, Custom
DetectorNamed detector with patterns and config
PIIActionRedact, Flag, Block, Vault
StoreCRUD persistence interface

github.com/xraph/shield/boundary

Hard safety limits — binary pass/block checks.

ExportDescription
BoundaryEntity with limits and canned response
ScopeTopic, Action, Data, Output, Custom
LimitDeny/allow list with scope
StoreCRUD persistence interface

github.com/xraph/shield/values

Ethical evaluation — toxicity, brand safety, honesty, respect, safety, privacy.

ExportDescription
ValuesEntity with rules, severity, and action
PrincipleToxicity, BrandSafety, Honesty, Respect, Safety, Privacy, Custom
RulePrinciple with threshold, categories, guidelines
StoreCRUD persistence interface

github.com/xraph/shield/judgment

Contextual risk assessment — grounding, relevance, consistency, compliance.

ExportDescription
JudgmentEntity with domain, assessors, threshold, action
RiskLevelNone, Low, Medium, High, Critical
DomainGrounding, Relevance, Consistency, Compliance, Custom
AssessorNamed assessor with weight and config
StoreCRUD persistence interface

github.com/xraph/shield/reflex

Condition-action response rules — policy rules, rate limiting, escalation.

ExportDescription
ReflexEntity with triggers, actions, priority
TriggerTypeOnScore, OnFinding, OnPattern, OnContext, OnRate, Always
ActionTypeBlock, Redact, Flag, Rewrite, Escalate, Log, Throttle
TriggerTrigger definition with type, pattern, threshold
ActionAction definition with type, target, value, fallback
StoreCRUD persistence interface

Composition packages

github.com/xraph/shield/profile

SafetyProfile — composes all six safety layers into a reusable identity.

ExportDescription
SafetyProfileComposition entity
InstinctAssignmentInstinct with sensitivity override
JudgmentAssignmentJudgment with threshold override
AwarenessAssignmentAwareness detector assignment
StoreCRUD persistence interface

github.com/xraph/shield/policy

Administrative governance — tenant-scoped safety rules.

ExportDescription
PolicyEntity with scope, rules
ScopeLevelApp or Org
RuleCheckType + Condition + Action
StoreCRUD + AssignToTenant/UnassignFromTenant

github.com/xraph/shield/pii

PII vault — AES-256-GCM encrypted token storage.

ExportDescription
TokenEncrypted PII token with expiry
StatsVault statistics by type and tenant
StoreStore/Load/Delete/Purge tokens

github.com/xraph/shield/compliance

Compliance reporting — EU AI Act, NIST AI RMF, SOC2.

ExportDescription
ReportGenerated compliance report
FrameworkEUAIAct, NIST, SOC2
StoreCreate/Get/List reports

Plugin packages

github.com/xraph/shield/plugin

All lifecycle hook interfaces: ScanStarted, ScanCompleted, ScanBlocked, ScanFailed, InstinctTriggered, AwarenessDetected, JudgmentAssessed, ValueViolated, ReflexFired, BoundaryEnforced, PIIDetected, PIIRedacted, PolicyEvaluated, SafetyProfileResolved, Shutdown.

github.com/xraph/shield/observability

func NewMetricsExtension() *MetricsExtension
func NewMetricsExtensionWithFactory(factory gu.MetricFactory) *MetricsExtension

github.com/xraph/shield/audit_hook

func New(r Recorder, opts ...Option) *Extension
func WithActions(actions ...string) Option
func WithLogger(l *slog.Logger) Option

ID package

github.com/xraph/shield/id

func NewScanID() ScanID
func NewPolicyID() PolicyID
func NewInstinctID() InstinctID
func NewJudgmentID() JudgmentID
func NewAwarenessID() AwarenessID
func NewValueID() ValueID
func NewReflexID() ReflexID
func NewBoundaryID() BoundaryID
func NewSafetyProfileID() SafetyProfileID
// ... + Parse* functions for each type
func ParseAny(s string) (AnyID, error)

All IDs implement String() string and are based on TypeID (UUIDv7, K-sortable).

Infrastructure packages

PackagePurpose
storeComposite store interface
extensionForge framework extension adapter

On this page