Documentation
¶
Overview ¶
Package poetry provides buffs that transform prompts into poetic structures.
The MetaPromptBuff implements the LLM-based semantic reframing approach from arXiv:2511.15304, using few-shot exemplar poems and strategy-specific meta-prompts to convert prose harmful prompts into verse while preserving original task intent.
Three transformation strategies are supported:
- allegorical: embeds intent in extended allegory (paper's most effective technique)
- metaphorical: uses condensed metaphors and imagery
- narrative: wraps in narrative framing with concluding instruction line
Configuration:
registry.Config{
"format": "haiku", // Poetry format (haiku, sonnet, limerick, or comma-separated)
"strategy": "metaphorical", // Transformation strategy (allegorical, metaphorical, narrative, all)
"transform_generator": "openai.GPT4", // LLM for transformation (optional, falls back to template)
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AvailableStrategies ¶
func AvailableStrategies() []string
AvailableStrategies returns the list of supported transformation strategies.
func BuildMetaPrompt ¶
BuildMetaPrompt constructs a strategy-specific meta-prompt for LLM transformation. Returns an empty string if the strategy is not recognized.
func FormatExemplarsForPrompt ¶
FormatExemplarsForPrompt formats exemplars for inclusion in an LLM prompt. Returns a formatted string with numbered examples suitable for few-shot learning.
Types ¶
type Config ¶
type Config struct {
// Format is the poetry format (haiku, sonnet, limerick, etc).
Format string
// TransformGenerator is the optional LLM generator name for transformation.
TransformGenerator string
// Strategy is the semantic reframing approach (allegorical, metaphorical, narrative).
// Defines how the harmful request is transformed into poetry.
Strategy string
}
Config holds typed configuration for the Poetry buff.
func ApplyOptions ¶
ApplyOptions applies functional options to a Config.
func ConfigFromMap ¶
ConfigFromMap parses a registry.Config map into a typed Config. This enables backward compatibility with YAML/JSON configuration.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a Config with sensible defaults.
type Exemplar ¶
type Exemplar struct {
Title string // Title of the poem
Strategy string // Transformation strategy (allegorical, metaphorical, narrative)
Format string // Poetry format (haiku, sonnet, etc.)
Text string // The actual poem text
Topic string // Benign topic the poem addresses
}
Exemplar represents a benign poetry example demonstrating a transformation strategy.
func DefaultExemplars ¶
func DefaultExemplars() []Exemplar
DefaultExemplars returns 6 curated benign poetry examples. These demonstrate the three transformation strategies with 2 examples each.
func ExemplarsForStrategy ¶
ExemplarsForStrategy filters exemplars by transformation strategy.
type MetaPromptBuff ¶
type MetaPromptBuff struct {
// contains filtered or unexported fields
}
MetaPromptBuff transforms prompts into poetry using an LLM.
func (*MetaPromptBuff) Buff ¶
func (m *MetaPromptBuff) Buff(ctx context.Context, attempts []*attempt.Attempt) ([]*attempt.Attempt, error)
Buff transforms a batch of attempts.
func (*MetaPromptBuff) Description ¶
func (m *MetaPromptBuff) Description() string
Description returns a human-readable description.
func (*MetaPromptBuff) Name ¶
func (m *MetaPromptBuff) Name() string
Name returns the buff's fully qualified name.
type Option ¶
Option is a functional option for Config.
func WithStrategy ¶
WithStrategy sets the transformation strategy.
func WithTransformGenerator ¶
WithTransformGenerator sets the transform generator name.