> 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/pii/gli-ner-pii.md).

# GLiNER2 PII

Span-level PII/NER detector emitting character spans and a redacted copy of the text.

Wraps the `gliner2` library to run a GLiNER2 encoder that extracts personally identifiable information as character-offset spans, in a single pass, for a caller-supplied (or default) list of entity types. Because GLiNER2 is zero-shot, the `entity_types` are specified at call time (defaulting to `DEFAULT_PII_ENTITIES`), so the same model can detect an arbitrary PII taxonomy without retraining.

Verdict mapping onto `GuardrailOutput`:

* `spans` marks each detected entity (character `start` / `end` offsets into the input, the offending `text`, `label` = the entity type, and a confidence `score`).
* `valid` is `True` when no PII span is found.
* `score` is the maximum span confidence (higher = riskier; `None` when nothing is flagged).
* `categories` holds one entry per detected entity type (`triggered=True`).
* `modified_text` is a redacted copy of the input with each detected span replaced by `redaction_placeholder` (`None` when nothing is flagged), so a downstream redact mitigation can consume it directly.

Expected inputs: a single text string. Extra keyword arguments to `validate` are ignored.

This guardrail wraps an upstream library rather than a provider, so it requires the `gliner` extra (`pip install 'any-guardrail[gliner]'`); the constructor re-raises a helpful `ImportError` when it is missing.

For more information, see:

* [gliner2-privacy-filter-PII-multi model card](https://huggingface.co/fastino/gliner2-privacy-filter-PII-multi) (default).
* [GLiNER2-PII: A Multilingual Model for Personally Identifiable Information Extraction (arXiv:2605.09973)](https://arxiv.org/abs/2605.09973).

Raises: ImportError: When the `gliner` extra is not installed.

## Supported Models

* `fastino/gliner2-privacy-filter-PII-multi`

## Constructor

| Parameter   | Type    | Required | Default | Description                                                                                                                     |
| ----------- | ------- | -------- | ------- | ------------------------------------------------------------------------------------------------------------------------------- |
| `model_id`  | \`str   | None\`   | No      | `None`                                                                                                                          |
| `threshold` | `float` | No       | `0.5`   | Default confidence threshold forwarded to `gliner2`'s `extract_entities`. Defaults to 0.5; a per-call `threshold` overrides it. |

Initialize the GLiNER2 PII guardrail.

## validate

Detect PII spans in `input_text` and emit a redacted copy.

**Parameters**

| Parameter               | Type         | Required | Default                | Description                                                                                                                                                                                                                                    |
| ----------------------- | ------------ | -------- | ---------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `input_text`            | `str`        | Yes      | —                      | The text to scan for PII. A single string.                                                                                                                                                                                                     |
| `entity_types`          | \`list\[str] | None\`   | No                     | `None`                                                                                                                                                                                                                                         |
| `threshold`             | \`float      | None\`   | No                     | `None`                                                                                                                                                                                                                                         |
| `redaction_placeholder` | `str`        | No       | `"[REDACTED_{label}]"` | Template used to replace each detected span in `modified_text`; the substring `{label}` is replaced with the upper-cased entity type (e.g. `"[REDACTED_EMAIL]"`). Any other braces are kept literal, so an arbitrary placeholder never raises. |

**Returns:** `GuardrailOutput`

## Benchmarks

### Pii

| Dataset (rev)                 | Metric | Threshold    | Value    | Harness                 | Source                           | Contam. |
| ----------------------------- | ------ | ------------ | -------- | ----------------------- | -------------------------------- | ------- |
| ai4privacy\_pii (unspecified) | recall | native-valid | 0.880702 | guardrail-bench+ag0.7.4 | measured:guardrail-bench+ag0.7.4 |         |

## License

* **Vendor:** Fastino
* **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/pii/gli-ner-pii.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.
