guardrail

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2026 License: Apache-2.0 Imports: 2 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package guardrail wraps tool output in untrusted-data sentinels and defangs known prompt-injection markers (role tags, "ignore previous instructions" phrasings, fenced system blocks).

Defense in depth, not a guarantee. Consumers feed every untrusted tool result through WrapToolOutput before appending it to the LLM message history.

Index

Constants

This section is empty.

Variables

View Source
var TrustedTools = map[string]bool{
	"load_skill":     true,
	"load_reference": true,
}

TrustedTools is a default whitelist of tool names whose output is considered author-controlled and therefore exempt from wrapping. Consult and delegation results are deliberately absent: they contain model output or selected external data and must cross back as untrusted data.

Functions

func DefangInjection

func DefangInjection(s string) string

DefangInjection inserts a zero-width space into known injection markers so they no longer parse as control tokens.

func ShouldWrap

func ShouldWrap(toolName string, trusted map[string]bool) bool

ShouldWrap returns true when the named tool's output should be wrapped. Pass nil for `trusted` to use the package-level TrustedTools whitelist.

func WrapToolOutput

func WrapToolOutput(callID, content string) string

WrapToolOutput applies the full guardrail (defang + sentinel wrapping + policy header) to a tool result. callID disambiguates concurrent calls in the same turn; pass "" if none is available.

Types

This section is empty.

Jump to

Keyboard shortcuts

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