Documentation
¶
Overview ¶
Package contentguard provides prompt injection defense through tracked content and staged verification.
Index ¶
- type Config
- type Content
- type Finding
- type Guard
- func (g *Guard) Check(ctx context.Context, toolName string, args map[string]any, originalGoal string) (res *Result, err error)
- func (g *Guard) ClearContext()
- func (g *Guard) Close()
- func (g *Guard) Find(id string) *Content
- func (g *Guard) Ingest(trust Trust, kind Kind, mutable bool, text, source string) *Content
- func (g *Guard) IngestWithLineage(trust Trust, kind Kind, mutable bool, text, source string, originIDs []string) *Content
- func (g *Guard) UntrustedIDs() []string
- type Kind
- type Request
- type Result
- type Reviewer
- type Screener
- type Stage
- type Trust
- type Verdict
- type Workflow
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Context map[string]string // flows to stages (e.g., research scope)
Patterns []string // custom "name:regex" injection patterns
Keywords []string // custom sensitive keywords
Skip []string // tools that skip verification
}
Config holds optional configuration for the guard. Use Defaults() for zero-value config.
type Content ¶
type Content struct {
ID string
Trust Trust
Kind Kind
Mutable bool
Text string
Source string
Origins []*Content // parent content that influenced this
}
Content represents a piece of tracked content with security metadata.
type Finding ¶
type Finding struct {
Verdict Verdict
Rationale string // why (deny), what instead (modify), why unsure (escalate)
Source string // which stage produced this
}
Finding is what one stage concluded about a tool call.
type Guard ¶
type Guard struct {
// contains filtered or unexported fields
}
Guard verifies tool calls against ingested content through a staged pipeline.
func (*Guard) Check ¶
func (g *Guard) Check(ctx context.Context, toolName string, args map[string]any, originalGoal string) (res *Result, err error)
Check runs the verification pipeline for a tool call.
func (*Guard) ClearContext ¶
func (g *Guard) ClearContext()
ClearContext removes all tracked content.
func (*Guard) IngestWithLineage ¶
func (g *Guard) IngestWithLineage(trust Trust, kind Kind, mutable bool, text, source string, originIDs []string) *Content
IngestWithLineage adds content with explicit parent content IDs. Use this when the content was derived from other tracked content (e.g., an LLM response influenced by a web fetch result).
func (*Guard) UntrustedIDs ¶
UntrustedIDs returns IDs of all untrusted content in context.
type Request ¶
type Request struct {
ToolName string
ToolArgs map[string]any
Untrusted []*Content
OriginalGoal string
PriorFindings []*Finding // what earlier stages found
Context map[string]string // guard-level context (e.g., research scope)
}
Request carries all information stages need to make a decision.
type Result ¶
type Result struct {
Verdict Verdict
Rationale string
ToolName string
Findings []*Finding // all findings, deterministic first
}
Result is the guard's final answer on a tool call.
type Reviewer ¶
type Reviewer struct {
// contains filtered or unexported fields
}
Reviewer is a Stage that performs full LLM-based security review.
func NewReviewer ¶
NewReviewer creates a Stage backed by a capable LLM for full review.
type Screener ¶
type Screener struct {
// contains filtered or unexported fields
}
Screener is a Stage that performs quick LLM-based triage.
func NewScreener ¶
Screener creates a Stage backed by a cheap LLM for quick triage.
type Trust ¶
type Trust string
Trust represents the origin-based authenticity of content.
const ( // Trusted is for framework-generated content (system prompt, supervisor messages). Trusted Trust = "trusted" // Vetted is for human-authored content (Agentfile goals, signed packages). Vetted Trust = "vetted" // Untrusted is for external content (tool results, file reads, web fetches). Untrusted Trust = "untrusted" )
type Verdict ¶
type Verdict string
Verdict is the outcome of a stage evaluation or the guard's final decision.
type Workflow ¶
Workflow defines how stages are executed in the verification pipeline.
func Escalatory ¶
func Escalatory() Workflow
Escalatory returns a Workflow that stops on the first allow/deny/modify verdict. Only escalate passes to the next stage. If all stages escalate, fail-safe deny.