guardrails

package
v1.3.12 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package guardrails provides built-in ProviderHook implementations that bridge the unified eval system to the pipeline's hook infrastructure.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewGuardrailHook

func NewGuardrailHook(typeName string, params map[string]any, opts ...GuardrailOption) (hooks.ProviderHook, error)

NewGuardrailHook creates a guardrail ProviderHook using the default eval registry.

func NewGuardrailHookFromRegistry added in v1.3.12

func NewGuardrailHookFromRegistry(
	typeName string, params map[string]any, registry *evals.EvalTypeRegistry,
	opts ...GuardrailOption,
) (hooks.ProviderHook, error)

NewGuardrailHookFromRegistry creates a guardrail ProviderHook using the eval registry. Any registered eval handler (including aliases) can be used as a guardrail.

Types

type GuardrailHookAdapter added in v1.3.12

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

GuardrailHookAdapter wraps an evals.EvalTypeHandler as a hooks.ProviderHook. This bridges the unified eval system to the pipeline's hook infrastructure, allowing any registered eval handler to be used as a guardrail.

When a guardrail triggers, the adapter enforces in-place (truncating or replacing content) and returns an Enforced decision so the pipeline continues.

func (*GuardrailHookAdapter) AfterCall added in v1.3.12

AfterCall checks provider output when direction is "output" or "both". When the guardrail triggers, it enforces in-place on resp.Message (truncating or replacing content) and returns an Enforced decision.

func (*GuardrailHookAdapter) BeforeCall added in v1.3.12

BeforeCall checks input messages when direction is "input" or "both". For input direction, it evaluates the last user message.

func (*GuardrailHookAdapter) Name added in v1.3.12

func (a *GuardrailHookAdapter) Name() string

Name returns the eval type identifier for this guardrail.

func (*GuardrailHookAdapter) OnChunk added in v1.3.12

OnChunk evaluates streaming chunks via StreamableEvalHandler.EvalPartial. When a guardrail triggers, it truncates the chunk content and returns an Enforced decision so the provider stage can stop reading but continue the pipeline.

type GuardrailOption added in v1.3.12

type GuardrailOption func(*GuardrailHookAdapter)

GuardrailOption configures a GuardrailHookAdapter.

func WithMessage added in v1.3.12

func WithMessage(msg string) GuardrailOption

WithMessage sets the user-facing message shown when content is blocked.

func WithMonitorOnly added in v1.3.12

func WithMonitorOnly() GuardrailOption

WithMonitorOnly disables enforcement — the guardrail evaluates and records results but does not modify content. Useful for monitoring guardrails without affecting output.

Jump to

Keyboard shortcuts

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