Documentation
¶
Overview ¶
Package guardrails provides built-in ProviderHook implementations that bridge the unified eval system to the pipeline's hook infrastructure.
Index ¶
- func NewGuardrailHook(typeName string, params map[string]any, opts ...GuardrailOption) (hooks.ProviderHook, error)
- func NewGuardrailHookFromRegistry(typeName string, params map[string]any, registry *evals.EvalTypeRegistry, ...) (hooks.ProviderHook, error)
- type GuardrailHookAdapter
- func (a *GuardrailHookAdapter) AfterCall(ctx context.Context, req *hooks.ProviderRequest, resp *hooks.ProviderResponse) hooks.Decision
- func (a *GuardrailHookAdapter) BeforeCall(ctx context.Context, req *hooks.ProviderRequest) hooks.Decision
- func (a *GuardrailHookAdapter) Name() string
- func (a *GuardrailHookAdapter) OnChunk(ctx context.Context, chunk *providers.StreamChunk) hooks.Decision
- type GuardrailOption
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
func (a *GuardrailHookAdapter) AfterCall( ctx context.Context, req *hooks.ProviderRequest, resp *hooks.ProviderResponse, ) hooks.Decision
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
func (a *GuardrailHookAdapter) BeforeCall( ctx context.Context, req *hooks.ProviderRequest, ) hooks.Decision
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
func (a *GuardrailHookAdapter) OnChunk( ctx context.Context, chunk *providers.StreamChunk, ) hooks.Decision
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.