judge

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache wraps a Provider with an in-memory verdict cache. Identical requests (same model, prompt, content) return cached verdicts without calling the underlying provider. Errors are not cached.

func NewCache

func NewCache(provider Provider, opts ...CacheOption) *Cache

NewCache creates a caching wrapper around a Provider.

func (*Cache) Judge

func (c *Cache) Judge(ctx context.Context, req Request) (Verdict, error)

Judge returns a cached verdict if available, otherwise calls the underlying provider and caches the result. Errors are not cached.

type CacheOption

type CacheOption func(*Cache)

CacheOption configures a Cache.

func WithMaxSize

func WithMaxSize(n int) CacheOption

WithMaxSize sets the maximum number of cached verdicts. When exceeded, the oldest entries are evicted. Default: 10,000. Values less than 1 are clamped to 1.

type Decision

type Decision string

Decision is the judge's binary outcome.

const (
	Allow Decision = "allow"
	Deny  Decision = "deny"
)

type Provider

type Provider interface {
	Judge(ctx context.Context, req Request) (Verdict, error)
}

Provider sends content to an LLM and returns a structured verdict.

type Request

type Request struct {
	Prompt  string // The judgment prompt from the rule
	Content string // The content to judge
	Model   string // Model identifier (shortcut or full ID)
}

Request is the input to a judge call.

type Usage

type Usage struct {
	InputTokens  int
	OutputTokens int
}

Usage tracks token consumption for a judge call.

type Verdict

type Verdict struct {
	Decision Decision // allow or deny
	Reason   string   // LLM's reasoning
	Usage    Usage    // Token consumption
	Cached   bool     // true if returned from cache
}

Verdict is the judge's response.

Directories

Path Synopsis
Package anthropic implements a judge.Provider backed by the Anthropic Messages API.
Package anthropic implements a judge.Provider backed by the Anthropic Messages API.

Jump to

Keyboard shortcuts

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