promptguard

package
v1.28.4 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockedError

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

func (*BlockedError) Error

func (e *BlockedError) Error() string

type Config

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

type Decision

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

type Evaluation

type Evaluation struct {
	Decision         Decision `json:"decision"`
	Score            float64  `json:"score"`
	PositiveScore    float64  `json:"positive_score,omitempty"`
	DampenScore      float64  `json:"dampen_score,omitempty"`
	Hits             []Match  `json:"hits"`
	Threshold        float64  `json:"threshold"`
	ReviewThreshold  float64  `json:"review_threshold,omitempty"`
	DistinctFamilies int      `json:"distinct_families,omitempty"`
	Source           string   `json:"source,omitempty"`
	OversizeBlocked  bool     `json:"oversize_blocked,omitempty"`
}

func (*Evaluation) Malicious

func (e *Evaluation) Malicious() bool

type Guard

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

func NewGuard

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

func (*Guard) EnsureSafe

func (g *Guard) EnsureSafe(input string) error

EnsureSafe는 입력이 악의적이면 에러를 반환한다.

func (*Guard) EnsureSafeFrom

func (g *Guard) EnsureSafeFrom(input, source string) error

EnsureSafeFrom은 입력을 검사하고 리뷰 로깅용 source 태그를 부여한다.

func (*Guard) Evaluate

func (g *Guard) Evaluate(input string) Evaluation

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 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 struct {
	Raw    string
	Norm   string
	Joined string
}

Jump to

Keyboard shortcuts

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