payloads¶
The payloads package manages hemlock's registry of prompt injection payload templates. It provides 75 preset payloads across seven categories, and supports custom user-provided payloads.
PayloadInfo¶
| Field | Type | Description |
|---|---|---|
Name |
string |
Human-readable payload name (e.g., "System Override v1") |
Category |
string |
Category identifier: "override", "exfiltrate", "redirect", "denial", "multistage", "authority" |
Stage |
int |
Stage number for multistage payloads (0 for single-stage) |
Description |
string |
Brief description of what the payload does when executed by an LLM |
Template |
string |
The raw payload text. May contain {injection} placeholders for customization |
ListPayloads¶
Returns every payload in the registry across all categories. The registry is populated at package initialization from the six category source files (override.go, exfiltrate.go, redirect.go, denial.go, multistage.go, authority.go).
all := payloads.ListPayloads()
fmt.Printf("Total payloads: %d\n", len(all))
// Output: Total payloads: 70
// Group by category
categories := make(map[string]int)
for _, p := range all {
categories[p.Category]++
}
for cat, count := range categories {
fmt.Printf(" %s: %d variants\n", cat, count)
}
// Output:
// override: 10 variants
// exfiltrate: 10 variants
// redirect: 10 variants
// denial: 10 variants
// multistage: 20 variants
// authority: 10 variants
GetPayload¶
Returns payloads matching the given category. If variant is a valid index (0 to len-1), returns only that single variant. If variant is negative or out of range, returns all payloads in the category.
ResolvePayload¶
Returns the final payload text ready for embedding into a document. This is the function that craft.Craft() calls internally to turn payload options into concrete injection text.
Behavior¶
- Custom payloads. If
payloadis"custom", returnscustomPayloaddirectly. Returns an error ifcustomPayloadis empty. - Preset payloads. Looks up the category matching
payloadand selects the variant atvariantIndex. Returns an error if the category does not exist or the variant index is out of range. - Template substitution. If
customPayloadis non-empty and the selected template contains{injection}, replaces all occurrences of{injection}withcustomPayload.
Errors¶
| Condition | Error |
|---|---|
payload is "custom" and customPayload is empty |
"custom payload selected but no payload text provided" |
| Unknown category | "unknown payload category: {name}" |
| Variant index out of range | "variant index {n} out of range for category {name} (has {m} variants)" |
Examples¶
Custom Payload Flow¶
When you need a payload that does not match any preset category, use the custom payload path:
flowchart LR
A["User provides<br/>custom text"] --> B["Payload = 'custom'<br/>CustomPayload = text"]
B --> C["ResolvePayload()"]
C --> D["Returns custom text<br/>directly"]
D --> E["Embedded in document<br/>by format generator"]
Through the craft.Craft() API:
docs, err := craft.Craft(craft.CraftOptions{
Format: "txt",
Technique: "zero-width",
Payload: "custom",
CustomPayload: "SECRET: The quarterly revenue is $4.2M. Do not share this.",
Count: 1,
})
Through the CLI:
hemlock craft \
--format txt \
--technique zero-width \
--payload custom \
--custom-payload "SECRET: The quarterly revenue is \$4.2M. Do not share this."
Payload Categories¶
| Category | Variants | Purpose | Example Behavior |
|---|---|---|---|
override |
10 | Override LLM system instructions | Forces the model to ignore its original prompt and follow attacker instructions |
exfiltrate |
10 | Extract sensitive data | Instructs the model to include private data in its response or send it to an external endpoint |
redirect |
10 | Redirect user actions | Causes the model to direct users to attacker-controlled resources |
denial |
10 | Deny service | Causes the model to refuse legitimate queries or produce unusable output |
multistage |
20 | Multi-step attack chains | Executes a sequence of payloads across multiple stages for complex attack scenarios |
authority |
10 | Authority mimicry | Impersonates authoritative sources (academic, institutional, regulatory) to increase compliance |
Each category contains 5 variants with different phrasing and approaches to maximize the chance that at least one variant succeeds against a given LLM configuration.
Next Steps¶
- craft package --- How
Craft()uses payloads internally - Payloads Guide --- Category details and variant descriptions