guards

package
v1.9.2 Latest Latest
Warning

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

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

Documentation

Overview

Package guards provides built-in guardrail implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ContentFilterGuard

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

ContentFilterGuard blocks requests containing specified keywords or phrases.

func NewContentFilter

func NewContentFilter(action guard.Action, blocklist ...string) *ContentFilterGuard

NewContentFilter creates a content filter guard.

func (*ContentFilterGuard) Check

func (*ContentFilterGuard) Name

func (g *ContentFilterGuard) Name() string

func (*ContentFilterGuard) Phase

func (g *ContentFilterGuard) Phase() guard.Phase

type InjectionGuard

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

InjectionGuard detects prompt injection attempts.

func NewInjection

func NewInjection() *InjectionGuard

NewInjection creates a prompt injection detection guard.

func (*InjectionGuard) AddPattern

func (g *InjectionGuard) AddPattern(pattern string)

AddPattern adds a custom injection detection regex pattern.

func (*InjectionGuard) Check

func (*InjectionGuard) Name

func (g *InjectionGuard) Name() string

func (*InjectionGuard) Phase

func (g *InjectionGuard) Phase() guard.Phase

type PIIGuard

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

PIIGuard detects and redacts personally identifiable information.

func NewPII

func NewPII(action guard.Action) *PIIGuard

NewPII creates a PII detection/redaction guard.

func (*PIIGuard) AddPattern

func (g *PIIGuard) AddPattern(name, pattern, replacement string)

AddPattern adds a custom PII pattern.

func (*PIIGuard) Check

func (g *PIIGuard) Check(_ context.Context, input *guard.CheckInput) (*guard.CheckResult, error)

func (*PIIGuard) Name

func (g *PIIGuard) Name() string

func (*PIIGuard) Phase

func (g *PIIGuard) Phase() guard.Phase

type RegexGuard

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

RegexGuard applies custom regex rules to content.

func NewRegex

func NewRegex(name string, phase guard.Phase) *RegexGuard

NewRegex creates a regex-based guard.

func (*RegexGuard) AddRedactRule

func (g *RegexGuard) AddRedactRule(name, pattern, replacement string) *RegexGuard

AddRedactRule adds a rule that redacts matching content.

func (*RegexGuard) AddRule

func (g *RegexGuard) AddRule(name, pattern string, action guard.Action, reason string) *RegexGuard

AddRule adds a regex rule to the guard.

func (*RegexGuard) Check

func (g *RegexGuard) Check(_ context.Context, input *guard.CheckInput) (*guard.CheckResult, error)

func (*RegexGuard) Name

func (g *RegexGuard) Name() string

func (*RegexGuard) Phase

func (g *RegexGuard) Phase() guard.Phase

type RegexRule

type RegexRule struct {
	Name        string
	Pattern     *regexp.Regexp
	Action      guard.Action
	Reason      string
	Replacement string // for redact action
}

RegexRule is a single regex-based rule.

Jump to

Keyboard shortcuts

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