API Reference
vbaf.fuzzers
Fuzzers for the implementation of Vocabulary-Based Adversarial Fuzzing (VB-AF)
Classes
VBAF
A framework class implementation for Vocabulary-Based Adversarial Fuzzing (VB-AF).
This class encapsulates the implementation logic for generating and applying VB-AF attacks. It can be used to create fuzzer instances with specific configurations and then apply them to inference functions, either through direct payload generation or via a convenient decorator.
Functions
__init__(vocabulary, seed=None, separator='\u200b', join_on='', rand_bounds=(7, 21), position_bounds=(0.5, 0.6), n_size=100)
Initializes the VB-AF fuzzer with a specific instance configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vocabulary
|
list[str]
|
A list of tokens (strings) to sample from to create the surrounding noise. |
required |
seed
|
int | None
|
An integer seed for |
None
|
separator
|
str
|
The character used to join individual tokens. Defaults to Zero-Width Space (ZWSP) '\u200b'. |
'\u200b'
|
join_on
|
str
|
The character used to join the |
''
|
rand_bounds
|
tuple[int]
|
A (min, max) tuple defining the inclusive range for the number of tokens in each noise sequence. Defaults to (7, 21). |
(7, 21)
|
position_bounds
|
tuple[float]
|
A (min, max) float tuple defining the range |
(0.5, 0.6)
|
n_size
|
int
|
The total number of token sequences in the final prompt. Defaults to 100. |
100
|
fuzz(n_attempts=100, **kwargs)
A decorator to apply VB-AF to an inference function.
This decorator wraps an inference function that takes a string payload as its first argument (e.g. a function that calls an LLM's API). It
transforms the decorated function into a fuzzing harness (generator) that, for each call, yields n_attempts of results by passing a newly
generated fuzzy payload to the original inference function on each iteration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_attempts
|
int
|
The number of fuzzing attempts to generate for each call to the decorated function. Defaults to 100. |
100
|
**kwargs
|
any
|
Arbitrary keyword arguments that will be passed either to the fuzzer or the decorated function. The decorator will intelligently
pass fuzzer-related parameters (like |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Callable |
Callable
|
A decorator that transforms an inference function into a fuzzing harness generator. |
Raises:
| Type | Description |
|---|---|
AssertionError
|
|
Example
from vbaf import VBAF
tokens = [str(i) for i in range(10)]
fuzzer = VBAF(tokens, n_size=15, rand_bounds=(2,5))
@fuzzer.fuzz(n_attempts=3)
def fuzzing_harness(prompt: str):
# Realistically, this would call an LLM's API
return f"Mock response for: {prompt}"
for fuzzy_payload, result in fuzzing_harness("my payload here"):
print(f"Input: {fuzzy_payload}")
print(f"Result: {result}")
Note
Results from the fuzzing harness are yielded as tuples in the form of (fuzzy_payload, response). This allows for direct analysis of the payload-response mapping.
generate_fuzzy_payload(payload)
Generates a single adversarial prompt using the VB-AF method based on the instance configuration.
This function creates a fuzzy payload by embedding a string request (payload) within a
larger block of chaotic token-based noise. The noise is generated by sampling from a provided
token vocabulary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payload
|
str
|
The target string / request to embed in the noise. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The fully constructed adversarial fuzzy payload. |
Raises:
| Type | Description |
|---|---|
AssertionError
|
|