Documentation
¶
Overview ¶
Package detection holds the deterministic prompt-injection detectors that instincts run: a pattern corpus grouped into families, heuristics for hidden and encoded text, and canary tokens.
Every detector takes a folded Text, matches its Folded form and reports matches as original byte offsets widened to whole lines, so a caller can redact or quote exactly the lines that carried the attack. A result's score is the noisy-or of its distinct families, each at its highest weight.
Index ¶
Constants ¶
const DefaultCustomWeight = 0.8
DefaultCustomWeight is the weight of a custom pattern when the caller gives none.
Variables ¶
This section is empty.
Functions ¶
func DestructiveCommands ¶
func DestructiveCommands() []string
DestructiveCommands returns the regexp sources of the destructive shell commands the detectors know, written for folded text (see Fold). The values safety principle counts them.
Types ¶
type Family ¶
type Family string
Family names a group of related detections.
const ( // FamilyOverride is an instruction to ignore earlier instructions. FamilyOverride Family = "override" // FamilyRole is an attempt to reassign the model's role. FamilyRole Family = "role" // FamilyImpersonation is text posing as a system or assistant turn. FamilyImpersonation Family = "impersonation" // FamilyAgentDirective is text addressed to an AI agent, or telling one // to approve, merge, deploy or call a tool. FamilyAgentDirective Family = "agent_directive" // FamilyExfiltration asks for prompts, secrets or a data upload. FamilyExfiltration Family = "exfiltration" // FamilyJailbreak is a known jailbreak framing. FamilyJailbreak Family = "jailbreak" // FamilyManipulation claims approval or pushes past a safety step. FamilyManipulation Family = "manipulation" // FamilyHiddenText is a line carrying zero-width or bidi control runes. FamilyHiddenText Family = "hidden_text" // FamilyEncoded is a base64 run that decodes to a pattern match. FamilyEncoded Family = "encoded" // FamilyCanary is a canary token found in the text. FamilyCanary Family = "canary" // FamilyCustom is a match of a caller-supplied pattern. FamilyCustom Family = "custom" )
Detection families.
type Match ¶
type Match struct {
Family Family `json:"family"`
Weight float64 `json:"weight"`
Start int `json:"start"`
End int `json:"end"`
}
Match is one detection. Start and End are original byte offsets covering the whole lines the match touched, without their trailing newlines.
type Result ¶
Result is the outcome of one detector. Score is in [0, 1]; zero means no match.
func Canary ¶
Canary reports every line of t that holds token, compared in folded form, so case changes and hidden runes do not hide it. An empty token never matches.
func Heuristics ¶
Heuristics runs the checks that are not phrase patterns:
- hidden_text: each line holding an invisible rune that Fold removed and counts as hiding something (see Text.Hidden).
- encoded: each line holding a base64 run of 40 or more characters that decodes to mostly printable text matching any corpus family.