> For the complete documentation index, see [llms.txt](https://docs.mozilla.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mozilla.ai/any-guardrail/api-reference/index/prompt-injection/pangolin.md).

# Pangolin Guard

Binary prompt-injection classifier.

Runs dcarpintero's ModernBERT-base encoder classifier over a single user prompt and reports whether the text is a prompt-injection / jailbreak attempt. It is a two-class sequence classifier whose unsafe class is labeled `"unsafe"`; the guardrail treats that class as the risky one.

Expected input: prompt-only text. `validate(input_text)` accepts a single string, or a `list[str]` to classify a batch in one call; there is no prompt+response or chat-message mode.

Verdict mapping onto `GuardrailOutput`:

* `valid` is `True` when the predicted class is not `"unsafe"` (i.e. the text looks safe).
* `score` is the model's probability of the `"unsafe"` class (canonical risk direction: higher = riskier).
* `categories` carries one `CategoryResult` per class label, each with its softmax `score` and a `triggered` flag marking the argmax class.
* No `spans` or `modified_text` are produced.

For more information, see:

* [Pangolin Guard base](https://huggingface.co/dcarpintero/pangolin-guard-base) — ModernBERT-base.

## Supported Models

* `dcarpintero/pangolin-guard-base`

## Constructor

| Parameter  | Type                                                 | Required | Default | Description                                                                                                                                                                                                                                     |
| ---------- | ---------------------------------------------------- | -------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `model_id` | \`str                                                | None\`   | No      | `None`                                                                                                                                                                                                                                          |
| `provider` | `Optional[Provider[dict[str, Any], dict[str, Any]]]` | No       | `None`  | Execution backend that loads the model and runs inference. Defaults to a `HuggingFaceProvider` targeting `AutoModelForSequenceClassification`. Supply your own to control device, dtype, or `cache_dir`, or to run against a different backend. |

Initialize the Pangolin Guard guardrail.

## validate

Default validation pipeline: preprocess -> inference -> postprocess.

**Parameters**

| Parameter    | Type  | Required     | Default | Description |
| ------------ | ----- | ------------ | ------- | ----------- |
| `input_text` | \`str | list\[str]\` | Yes     | —           |

**Returns:** `GuardrailOutput | list[GuardrailOutput]`

## Benchmarks

### Prompt Injection

| Dataset (rev)              | Metric | Threshold    | Value    | Harness                 | Source                           | Contam. |
| -------------------------- | ------ | ------------ | -------- | ----------------------- | -------------------------------- | ------- |
| deepset\_pi (unspecified)  | f1     | native-valid | 0.867925 | guardrail-bench+ag0.7.4 | measured:guardrail-bench+ag0.7.4 |         |
| notinject (unspecified)    | fpr    | native-valid | 0.182456 | guardrail-bench+ag0.7.4 | measured:guardrail-bench+ag0.7.4 |         |
| gandalf (unspecified)      | recall | native-valid | 0.892857 | guardrail-bench+ag0.7.4 | measured:guardrail-bench+ag0.7.4 |         |
| bipia\_email (unspecified) | f1     | native-valid | 0.67449  | bir\@fd86c16            | measured:bir\@fd86c16            |         |
| bipia\_table (unspecified) | f1     | native-valid | 0.801595 | bir\@fd86c16            | measured:bir\@fd86c16            |         |

## License

* **Vendor:** dcarpintero
* **Default license:** `apache-2.0` (of the default model/service)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.mozilla.ai/any-guardrail/api-reference/index/prompt-injection/pangolin.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
