promptguard

package
v1.30.0 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2026 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const EngineVersion = "promptguard-engine-v3.1.0"

Variables

View Source
var (
	ErrInvalidCheckRequest = errors.New("invalid prompt guard check request")
	ErrGuardUnavailable    = errors.New("prompt guard unavailable")
)

Functions

func JoinParts added in v1.29.0

func JoinParts(parts ...string) string

Types

type BlockedError

type BlockedError struct {
	Score     float64
	Threshold float64
	Families  []string
	Rules     []string
	Source    string
	Decision  Decision
}

func (*BlockedError) Error

func (e *BlockedError) Error() string

type CheckRequest added in v1.29.0

type CheckRequest struct {
	Text        string
	Source      Source
	Enforcement Enforcement
}

type Config

type Config struct {
	Enabled             bool
	RulepacksDir        string
	RulepackFS          fs.FS
	RulepackRoot        string
	UseEmbeddedDefaults bool
	CacheMaxSize        int
	CacheTTL            time.Duration
	MaxInputBytes       int
	OnEvaluation        func(EvaluationEvent)
}

type Decision

type Decision string
const (
	DecisionAllow  Decision = "allow"
	DecisionReview Decision = "review"
	DecisionBlock  Decision = "block"
)

type Enforcement added in v1.29.0

type Enforcement uint8
const (
	EnforcementUnspecified Enforcement = iota
	EnforcementObserve
	EnforcementInteractive
	EnforcementPersistent
)

type Evaluation

type Evaluation struct {
	Decision              Decision `json:"decision"`
	Score                 float64  `json:"score"`
	Hits                  []Match  `json:"hits"`
	Threshold             float64  `json:"threshold"`
	ReviewThreshold       float64  `json:"review_threshold,omitempty"`
	DistinctFamilies      int      `json:"distinct_families,omitempty"`
	Source                Source   `json:"source,omitempty"`
	OversizeBlocked       bool     `json:"oversize_blocked,omitempty"`
	FallbackBlocked       bool     `json:"fallback_blocked,omitempty"`
	SegmentBudgetExceeded bool     `json:"segment_budget_exceeded,omitempty"`
}

type EvaluationEvent added in v1.29.0

type EvaluationEvent struct {
	Source       Source
	Decision     Decision
	CacheHit     bool
	PolicyDigest string
	Score        float64
	Families     []string
	RuleIDs      []string
	InputBytes   int
}

type Guard

type Guard struct {
	// contains filtered or unexported fields
}

func NewGuard

func NewGuard(cfg Config, logger *slog.Logger) (*Guard, error)

func (*Guard) Check added in v1.29.0

func (g *Guard) Check(req CheckRequest) (Evaluation, error)

func (*Guard) PolicyDigest added in v1.29.0

func (g *Guard) PolicyDigest() string

type Match

type Match struct {
	ID      string `json:"id"`
	Family  string `json:"family,omitempty"`
	Action  string `json:"action,omitempty"`
	View    string `json:"view,omitempty"`
	Segment string `json:"segment,omitempty"`

	Weight float64 `json:"weight"`
	// contains filtered or unexported fields
}

type Source added in v1.29.0

type Source string
const (
	SourceUserPrompt      Source = "user_prompt"
	SourcePromptBundle    Source = "prompt_bundle"
	SourceRetrievedMemory Source = "retrieved_memory"
	SourceMemoryCandidate Source = "memory_candidate"
	SourceSessionPatch    Source = "session_patch"
	SourceSimulationState Source = "simulation_state"
	SourceLawContext      Source = "law_context"
	SourceSessionContext  Source = "session_context"
	SourceChatLog         Source = "chat_log"
	SourceWebSearchResult Source = "web_search_result"
	SourceImagePrompt     Source = "image_prompt"
)

type TTLCache

type TTLCache[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func NewTTLCache

func NewTTLCache[K comparable, V any](maxSize int, ttl time.Duration) *TTLCache[K, V]

func (*TTLCache[K, V]) Get

func (c *TTLCache[K, V]) Get(key K) (V, bool)

func (*TTLCache[K, V]) Len

func (c *TTLCache[K, V]) Len() int

func (*TTLCache[K, V]) Set

func (c *TTLCache[K, V]) Set(key K, value V)

type Views

type Views = guardtext.Views

Jump to

Keyboard shortcuts

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