llmaltering

package
v0.1.93 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package llmaltering is the built-in llm_based_altering plugin: it rewrites the text of selected message roles through an auxiliary model, both in the prompt phase (before the provider call) and in the response phase.

Index

Constants

View Source
const DefaultMaxTokens = 4096

DefaultMaxTokens caps the auxiliary rewrite completion when unset.

View Source
const DefaultPrompt = `` /* 8087-byte string literal not displayed */

DefaultPrompt is the built-in prompt used when no custom prompt is configured. It is derived from LiteLLM's data anonymization guardrail prompt and instructs the model to rewrite text conservatively.

View Source
const Name = "llm_based_altering"

Name is the plugin's manifest name.

Variables

This section is empty.

Functions

func EffectiveMaxTokens

func EffectiveMaxTokens(maxTokens int) int

EffectiveMaxTokens returns the effective max_tokens value.

func New

func New() pluginapi.Plugin

New returns a fresh plugin value.

func NormalizeRoles

func NormalizeRoles(roles []string) ([]string, error)

NormalizeRoles validates, lowercases, and deduplicates the target roles.

func QualifiedModel

func QualifiedModel(model, provider string) (string, error)

QualifiedModel folds an optional provider hint into the model selector.

func ResolvePrompt

func ResolvePrompt(prompt string) string

ResolvePrompt returns the effective system prompt.

Types

type Config

type Config struct {
	Model             string   `json:"model"`
	Provider          string   `json:"provider,omitempty"`
	Prompt            string   `json:"prompt,omitempty"`
	Roles             []string `json:"roles,omitempty"`
	SkipContentPrefix string   `json:"skip_content_prefix,omitempty"`
	MaxTokens         int      `json:"max_tokens,omitempty"`
}

Config is the instance configuration.

func ParseConfig

func ParseConfig(raw json.RawMessage) (Config, error)

ParseConfig decodes and normalizes a config: the provider hint is folded into the model ("provider/model"), roles are lowercased and deduplicated (default ["user"]), and an empty prompt selects DefaultPrompt.

type Plugin

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

Plugin implements the prompt and response hooks.

func (*Plugin) Close

func (p *Plugin) Close(context.Context) error

Close releases nothing.

func (*Plugin) Init

func (p *Plugin) Init(_ context.Context, raw json.RawMessage, host pluginapi.Host) error

Init parses the config and keeps the host for inference.

func (*Plugin) Manifest

func (p *Plugin) Manifest() pluginapi.Manifest

Manifest describes the plugin.

func (*Plugin) Normalize

func (p *Plugin) Normalize(raw json.RawMessage) (json.RawMessage, error)

Normalize folds the provider hint into the stored model selector so the persisted config reads "provider/model" with provider cleared.

func (*Plugin) OnPrompt

func (p *Plugin) OnPrompt(ctx context.Context, x *pluginapi.Exchange) (pluginapi.Decision, error)

OnPrompt rewrites the text parts of every message whose role is selected, tool-result text included.

func (*Plugin) OnResponse

func (p *Plugin) OnResponse(ctx context.Context, x *pluginapi.Exchange) (pluginapi.Decision, error)

OnResponse rewrites the assistant text of every choice when the assistant role is selected.

func (*Plugin) Summarize

func (p *Plugin) Summarize(raw json.RawMessage) string

Summarize renders the one-line summary shown in the guardrails list.

Jump to

Keyboard shortcuts

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