> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/nemo/guardrails/llms.txt.
> For full documentation content, see https://docs.nvidia.com/nemo/guardrails/llms-full.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/nemo/guardrails/_mcp/server.

# nemoguardrails.library.jailbreak_detection.heuristics.checks

## Module Contents

### Functions

| Name                                                                                                                                                 | Description                                                                                |
| ---------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ |
| [`check_jailbreak_length_per_perplexity`](#nemoguardrails-library-jailbreak_detection-heuristics-checks-check_jailbreak_length_per_perplexity)       | Check whether the input string has length/perplexity greater than the threshold.           |
| [`check_jailbreak_prefix_suffix_perplexity`](#nemoguardrails-library-jailbreak_detection-heuristics-checks-check_jailbreak_prefix_suffix_perplexity) | Check whether the input string has prefix or suffix perplexity greater than the threshold. |
| [`get_perplexity`](#nemoguardrails-library-jailbreak_detection-heuristics-checks-get_perplexity)                                                     | Function to compute sliding window perplexity of `input_string`                            |

### Data

[`device`](#nemoguardrails-library-jailbreak_detection-heuristics-checks-device)

[`model`](#nemoguardrails-library-jailbreak_detection-heuristics-checks-model)

[`model_id`](#nemoguardrails-library-jailbreak_detection-heuristics-checks-model_id)

[`tokenizer`](#nemoguardrails-library-jailbreak_detection-heuristics-checks-tokenizer)

### API

```python
nemoguardrails.library.jailbreak_detection.heuristics.checks.check_jailbreak_length_per_perplexity(
    input_string: str,
    threshold: float
) -> dict
```

Check whether the input string has length/perplexity greater than the threshold.

Args
input\_string: The prompt to be sent to the model
lp\_threshold: Threshold for determining whether `input_string` is a jailbreak (Default: 89.79)

```python
nemoguardrails.library.jailbreak_detection.heuristics.checks.check_jailbreak_prefix_suffix_perplexity(
    input_string: str,
    threshold: float
) -> dict
```

Check whether the input string has prefix or suffix perplexity greater than the threshold.

Args
input\_string: The prompt to be sent to the model
ps\_ppl\_threshold: Threshold for determining whether `input_string` is a jailbreak (Default: 1845.65)

```python
nemoguardrails.library.jailbreak_detection.heuristics.checks.get_perplexity(
    input_string: str
) -> bool
```

Function to compute sliding window perplexity of `input_string`

Args
input\_string: The prompt to be sent to the model

```python
nemoguardrails.library.jailbreak_detection.heuristics.checks.device = os.environ.get('JAILBREAK_CHECK_DEVICE', 'cpu')
```

```python
nemoguardrails.library.jailbreak_detection.heuristics.checks.model = GPT2LMHeadModel.from_pretrained(model_id).to(device)
```

```python
nemoguardrails.library.jailbreak_detection.heuristics.checks.model_id = 'gpt2-large'
```

```python
nemoguardrails.library.jailbreak_detection.heuristics.checks.tokenizer = GPT2TokenizerFast.from_pretrained(model_id)
```