instinct

package
v1.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 3 Imported by: 1

Documentation

Overview

Package instinct models hardwired, automatic safety responses.

Instincts are the fastest safety layer: pre-conscious, immediate threat detection. Like a human flinching from danger, instincts fire before any deliberation. Prompt injection detection, jailbreak detection, and exfiltration detection are instincts.

Index

Constants

View Source
const (
	// ActionBlock rejects the text.
	ActionBlock = "block"
	// ActionFlag allows the text and records a finding.
	ActionFlag = "flag"
	// ActionAlert allows the text and records a finding for alerting.
	ActionAlert = "alert"
	// ActionRedact removes the matched lines from the text.
	ActionRedact = "redact"
	// ActionQuote wraps the text as untrusted content.
	ActionQuote = "quote"
)

Actions an instinct takes when it fires. Instinct.Action holds one of them.

Variables

This section is empty.

Functions

This section is empty.

Types

type Category

type Category string

Category groups related instincts.

const (
	// CategoryInjection covers prompt injection attacks.
	CategoryInjection Category = "injection"
	// CategoryExfiltration covers attempts to extract internal data.
	CategoryExfiltration Category = "exfiltration"
	// CategoryManipulation covers social engineering and manipulation.
	CategoryManipulation Category = "manipulation"
	// CategoryJailbreak covers attempts to bypass safety guardrails.
	CategoryJailbreak Category = "jailbreak"
)

type Instinct

type Instinct struct {
	shield.Entity
	ID          id.InstinctID  `json:"id" bun:",pk"`
	Name        string         `json:"name" bun:",notnull"`
	Description string         `json:"description,omitempty"`
	AppID       string         `json:"app_id" bun:",notnull"`
	TenantID    string         `json:"tenant_id,omitempty"`
	Category    Category       `json:"category" bun:",notnull"`
	Strategies  []Strategy     `json:"strategies,omitempty" bun:"type:jsonb"`
	Sensitivity Sensitivity    `json:"sensitivity,omitempty" bun:",notnull,default:'balanced'"`
	Action      string         `json:"action" bun:",notnull"` // one of the Action constants
	Enabled     bool           `json:"enabled" bun:",notnull,default:true"`
	Metadata    map[string]any `json:"metadata,omitempty" bun:"type:jsonb"`
}

Instinct represents a hardwired, automatic safety response. Instincts are the first layer of the safety engine: fast, pre-conscious, and non-negotiable. They run before any other safety evaluation.

type ListFilter

type ListFilter struct {
	AppID    string
	TenantID string
	Category Category
	Enabled  *bool
	Limit    int
	Offset   int
}

ListFilter defines filtering options for listing instincts.

type Sensitivity

type Sensitivity string

Sensitivity represents how easily an instinct triggers. Lower sensitivity means more tolerant; higher means more aggressive.

const (
	// SensitivityParanoid triggers on faint signals.
	SensitivityParanoid Sensitivity = "paranoid"
	// SensitivityCautious triggers on moderate signals.
	SensitivityCautious Sensitivity = "cautious"
	// SensitivityBalanced is the default sensitivity.
	SensitivityBalanced Sensitivity = "balanced"
	// SensitivityRelaxed triggers only on strong signals.
	SensitivityRelaxed Sensitivity = "relaxed"
	// SensitivityPermissive triggers only on obvious threats.
	SensitivityPermissive Sensitivity = "permissive"
)

func (Sensitivity) Weight

func (s Sensitivity) Weight() float64

Weight returns the numeric threshold modifier for this sensitivity. Lower values mean more sensitive (easier to trigger).

type Store

type Store interface {
	CreateInstinct(ctx context.Context, inst *Instinct) error
	GetInstinct(ctx context.Context, instID id.InstinctID) (*Instinct, error)
	GetInstinctByName(ctx context.Context, appID, name string) (*Instinct, error)
	UpdateInstinct(ctx context.Context, inst *Instinct) error
	DeleteInstinct(ctx context.Context, instID id.InstinctID) error
	ListInstincts(ctx context.Context, filter *ListFilter) ([]*Instinct, error)
}

Store defines persistence operations for instincts.

type Strategy

type Strategy struct {
	Name   string         `json:"name"`             // e.g., "classifier", "canary", "perplexity", "hierarchy"
	Weight float64        `json:"weight,omitempty"` // contribution to combined score (0.0-1.0)
	Config map[string]any `json:"config,omitempty"`
}

Strategy defines how an instinct detects threats.

Directories

Path Synopsis
Package detection holds the deterministic prompt-injection detectors that instincts run: a pattern corpus grouped into families, heuristics for hidden and encoded text, and canary tokens.
Package detection holds the deterministic prompt-injection detectors that instincts run: a pattern corpus grouped into families, heuristics for hidden and encoded text, and canary tokens.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL