Documentation
¶
Overview ¶
Package guardrails runs Blitz's guardrails on a model's request and reply, for a program that has those rather than an engine turn: a gateway between Blitz and the models (spec_053_enterprise EN-23). The rules and their checks are the engine's own (pkg/engine/gates), so a guardrail means the same there as on the desktop:
- a tool's result going back to the model: the injection guardrail takes out instructions aimed at the agent (confirmed by the judge when it asks), and custom tool-result guardrails are judged;
- what the client sends: the secrets guardrail masks or refuses credentials;
- a tool call the model makes: the limits guardrail's domains and commands, and custom action guardrails, judged;
- the model's text as it streams: the secrets guardrail, over a window held back so a secret split between pieces is still caught.
Custom output guardrails judge a whole answer, which a gateway has only once it's been sent: they aren't run here.
Index ¶
- Constants
- type Asker
- type Finding
- type Guardrail
- type Limits
- type Output
- type Set
- func (s Set) Input(text string) (string, bool, []Finding)
- func (s Set) Output() *Output
- func (s Set) ToolCall(ctx context.Context, tool string, args map[string]any, external bool) (refusal string, fs []Finding)
- func (s Set) ToolResult(ctx context.Context, tool string, external bool, text string) (out string, withheld bool, fs []Finding)
Constants ¶
const ( Block = gates.Block Warn = gates.Warn Redact = gates.Redact StageToolResult = gates.StageToolResult StageOutput = gates.StageOutput StageAction = gates.StageAction Injection = gates.BuiltinInjection Secrets = gates.BuiltinSecrets LimitsID = gates.BuiltinLimits )
Actions and stages, as the engine names them.
const Window = 160
Window is how much of the model's text Output holds back: a secret shorter than this is caught even when it comes in pieces.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Finding ¶
type Finding struct {
Guardrail string `json:"guardrail"`
Action string `json:"action"` // block, warn, redact or pass
Reason string `json:"reason,omitempty"`
}
Finding is what a guardrail did: for the log of what acted.
type Guardrail ¶
Guardrail is one guardrail: a built-in one or a custom check.
func Defaults ¶
func Defaults() []Guardrail
Defaults are the built-in guardrails as they run with no files: on, each with its default action.
type Output ¶
type Output struct {
// contains filtered or unexported fields
}
Output checks the model's text as it streams, with the secrets guardrail: each piece goes in, and what's safe to send comes out.
type Set ¶
type Set struct {
All []Guardrail
Agent string // the agent the request is for ("" for none)
// Ask is the judge, for custom guardrails and the injection
// guardrail's confirmation. Nil: patterns only; a custom guardrail
// that blocks then refuses, as it can't be judged.
Ask Asker
// Redactor masks known values as well as the built-in patterns (nil:
// the patterns and remembered values).
Redactor *redact.Redactor
}
Set is the guardrails one request runs under.
func (Set) Input ¶
Input checks text the client sends to the model with the secrets guardrail: masked when it redacts, refused when it blocks.
func (Set) ToolCall ¶
func (s Set) ToolCall(ctx context.Context, tool string, args map[string]any, external bool) (refusal string, fs []Finding)
ToolCall checks a tool call the model makes before the client sees it: the limits guardrail's domains (web_fetch, a browser's navigate) and commands (run_shell_command), and custom action guardrails. A refusal is what to tell the agent instead of the call.
func (Set) ToolResult ¶
func (s Set) ToolResult(ctx context.Context, tool string, external bool, text string) (out string, withheld bool, fs []Finding)
ToolResult checks a tool's result going back to the model. external is whether the tool brings in outside content (the web, a browser, an MCP server), which the injection guardrail checks. It returns the result to send (instructions aimed at the agent taken out), or withheld with the reason to send instead.