guardrails

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: MIT Imports: 3 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

This section is empty.

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 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 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