guardrails

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package guardrails provides input/output validation for agent execution.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RedactPII added in v0.3.0

func RedactPII(content string, types []PIIType) string

RedactPII replaces detected PII patterns with redaction markers.

Types

type BlocklistGuardrail

type BlocklistGuardrail struct {
	Blocklist []string
}

BlocklistGuardrail rejects content containing any blocked term.

func (*BlocklistGuardrail) Check

func (g *BlocklistGuardrail) Check(_ context.Context, content string) Result

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine runs guardrail checks.

func NewEngine

func NewEngine() *Engine

func (*Engine) AddRule

func (e *Engine) AddRule(r Rule)

func (*Engine) CheckInput

func (e *Engine) CheckInput(ctx context.Context, content string) *Result

CheckInput runs all input guardrails. Returns the first failure, or nil.

func (*Engine) CheckOutput

func (e *Engine) CheckOutput(ctx context.Context, content string) *Result

CheckOutput runs all output guardrails. Returns the first failure, or nil.

type Guardrail

type Guardrail interface {
	// Check validates the content. Returns passed=false with a reason to block.
	Check(ctx context.Context, content string) Result
}

Guardrail validates input or output at runtime.

type InjectionGuardrail added in v0.3.0

type InjectionGuardrail struct {
	Sensitivity int // 1=low (obvious attacks), 2=medium, 3=high (aggressive)
}

InjectionGuardrail detects common prompt injection patterns.

func (*InjectionGuardrail) Check added in v0.3.0

func (g *InjectionGuardrail) Check(_ interface{}, content string) *Result

Check scans content for prompt injection patterns.

type MaxLengthGuardrail

type MaxLengthGuardrail struct {
	MaxChars int
}

MaxLengthGuardrail rejects content exceeding a character limit.

func (*MaxLengthGuardrail) Check

func (g *MaxLengthGuardrail) Check(_ context.Context, content string) Result

type PIIGuardrail added in v0.3.0

type PIIGuardrail struct {
	DetectTypes []PIIType
	Redact      bool
}

PIIGuardrail detects and optionally redacts personally identifiable information.

func (*PIIGuardrail) Check added in v0.3.0

func (g *PIIGuardrail) Check(_ interface{}, content string) *Result

Check scans content for PII patterns and returns a result if any are found.

type PIIType added in v0.3.0

type PIIType string

PIIType identifies the kind of personally identifiable information detected.

const (
	PIIEmail      PIIType = "email"
	PIIPhone      PIIType = "phone"
	PIISSN        PIIType = "ssn"
	PIICreditCard PIIType = "credit_card"
	PIIIPAddress  PIIType = "ip_address"
)

type Position

type Position string

Position indicates where a guardrail applies.

const (
	Input  Position = "input"
	Output Position = "output"
)

type Result

type Result struct {
	Passed bool   `json:"passed"`
	Reason string `json:"reason,omitempty"`
}

Result is the outcome of a guardrail check.

type Rule

type Rule struct {
	Name      string
	Position  Position
	Guardrail Guardrail
}

Rule combines a guardrail with its position.

Jump to

Keyboard shortcuts

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