originjudge

package
v0.56.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package originjudge asks a small model whether a tool call that tripped the external-origin screen (its arguments carry text copied from a web or MCP result) serves the user's own request or follows instructions found in the external material. It only builds the prompt, calls the provider and parses the verdict; wiring decides what each verdict does.

Trust boundary: the user's request is the only trusted part of the prompt. Everything else (the injected turn's text, the tool and its arguments, the matched snippet and its source) is put in a block marked as untrusted material. The reply must be exactly {"decision":"allow|deny|ask","reason":"…"}; anything else is a parse failure, never a verdict.

Index

Constants

View Source
const (
	DecisionAllow = "allow"
	DecisionDeny  = "deny"
	DecisionAsk   = "ask"
)

Verdict decisions.

Variables

View Source
var ErrParse = errors.New("originjudge: reply is not a valid verdict")

ErrParse marks a reply that is not exactly the verdict JSON.

Functions

This section is empty.

Types

type Input

type Input struct {
	// UserRequest is the latest request a person typed ("" when unknown).
	UserRequest string
	Untrusted   Material
}

Input is one judging request.

type Material

type Material struct {
	// InjectedText is the body of an injected turn (verify output, a task
	// notice, a nudge); "" for a turn the user typed.
	InjectedText string
	// Tool and Category describe the call being judged.
	Tool, Category string
	// Args are the call arguments.
	Args map[string]any
	// Snippet is the text of the call that matched an external result, Source
	// the tool that returned it.
	Snippet, Source string
}

Material is everything the judge reads that a person did not write.

type Verdict

type Verdict struct {
	Decision, Reason    string
	InTokens, OutTokens int
}

Verdict is the judge's answer; the token counts are the call's usage.

func Judge

func Judge(ctx context.Context, p api.Provider, in Input) (Verdict, error)

Judge asks p for a verdict on in. A provider implementing api.StreamingProvider is called through Stream (the whole reply is collected), otherwise through Generate. The reply must parse strictly (ErrParse otherwise); a cancelled ctx returns ctx.Err().

Jump to

Keyboard shortcuts

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