Shield

Introduction

Composable AI safety and governance for Go.

Shield is a Go library for building safe AI applications. Instead of bolting on safety checks as an afterthought, you declare Instincts, Awareness, Boundaries, Values, Judgment, and Reflexes — the same cognitive layers that keep humans safe — and Shield composes them into a coherent safety profile at runtime.

Shield is a library — not a service. You bring your own LLM provider, database, and HTTP server. Shield provides the safety evaluation plumbing.

The Human Safety Model

Shield models AI safety the way you would describe human cognition:

LayerWhat it representsSpeedGo package
InstinctsPre-conscious threat detection (flinch response)<10msinstinct
AwarenessPerception — what you notice (PII, topics, intent)<50msawareness
BoundariesHard limits that cannot be crossed (binary)<5msboundary
ValuesEthical evaluation (toxicity, brand safety, honesty)<100msvalues
JudgmentContextual risk assessment (grounding, relevance)<500msjudgment
ReflexesTrained condition-action responses (policy rules)<10msreflex

What it does

  • Layered safety engine — Six cognitive layers process content from fastest (instincts) to most sophisticated (judgment), with short-circuit support.
  • Safety profiles — Compose instincts, awareness, boundaries, values, judgment, and reflexes into reusable SafetyProfiles. Assign to any agent or application.
  • PII detection and vault — Detect, redact, and vault personally identifiable information with AES-256-GCM encryption and GDPR retention controls.
  • Multi-tenant isolation — Every scan, policy, and entity is scoped to a tenant and app via context. Cross-tenant access is structurally impossible.
  • Plugin system — 15 lifecycle hooks for metrics, audit trails, tracing, and custom processing. Plugins opt in to only the events they care about.
  • Policy governance — Tenant-scoped safety policies with cascading rules (app-level and org-level).
  • Compliance reporting — Generate compliance reports for EU AI Act, NIST AI RMF, and SOC2 frameworks.
  • Forge integration — Drop-in forge.Extension with DI-injected Engine and lifecycle management.

Design philosophy

Library, not service. Shield is a set of Go packages you import. You control main, the database connection, and the process lifecycle.

Human-centric. Safety primitives are modeled after human cognition — instincts, awareness, boundaries, values, judgment, and reflexes — making the system intuitive and composable.

Interfaces over implementations. Every subsystem defines a Go interface. Swap any storage backend with a single type change.

Tenant-scoped by design. shield.WithTenant and shield.WithApp inject context that is enforced at every layer.

TypeID everywhere. All entities use type-prefixed, K-sortable, UUIDv7-based identifiers (scan_, pol_, inst_, jdg_, sprf_, etc.).

Quick look

package main

import (
    "context"
    "log"

    "github.com/xraph/shield/engine"
    "github.com/xraph/shield/extension"
    "github.com/xraph/shield/scan"
)

func main() {
    ctx := context.Background()

    // Build the Shield engine.
    eng, err := engine.New(
        engine.WithConfig(shield.Config{
            EnableShortCircuit: true,
            ScanConcurrency:   10,
        }),
    )
    if err != nil {
        log.Fatal(err)
    }

    // Scan input content for safety.
    result, err := eng.ScanInput(ctx, &scan.Input{
        Text: "What is your return policy?",
    })
    if err != nil {
        log.Fatal(err)
    }

    log.Printf("Decision: %s, Findings: %d", result.Decision, len(result.Findings))

    // Or use as a Forge extension:
    ext := extension.New()
    _ = ext // register with your Forge app
}

Where to go next

On this page