> This page is for version v0.24.0.
> For other versions, use one of these documentation indexes:
> - Latest (default): https://docs.nvidia.com/nemo/guardrails/latest/llms.txt
> - v0.24.1: https://docs.nvidia.com/nemo/guardrails/v0.24.1/llms.txt
> - v0.24.0: https://docs.nvidia.com/nemo/guardrails/v0.24.0/llms.txt
> - v0.23.0: https://docs.nvidia.com/nemo/guardrails/v0.23.0/llms.txt
> - v0.22.0: https://docs.nvidia.com/nemo/guardrails/v0.22.0/llms.txt

> 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 AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/nemo/guardrails/_mcp/server.

# nemoguardrails.library.gliner.actions

PII detection using GLiNER.

## Module Contents

### Functions

| Name                                                                                          | Description                                                                      |
| --------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- |
| [`_mask_pii_outcome`](#nemoguardrails-library-gliner-actions-_mask_pii_outcome)               | -                                                                                |
| [`_mask_text_with_entities`](#nemoguardrails-library-gliner-actions-_mask_text_with_entities) | Mask detected entities in text with their labels.                                |
| [`_pii_detection_outcome`](#nemoguardrails-library-gliner-actions-_pii_detection_outcome)     | -                                                                                |
| [`_resolve_api_key`](#nemoguardrails-library-gliner-actions-_resolve_api_key)                 | Resolve the GLiNER API key from the configured env var, logging a warning if the |
| [`gliner_detect_pii`](#nemoguardrails-library-gliner-actions-gliner_detect_pii)               | Checks whether the provided text contains any PII using GLiNER.                  |
| [`gliner_mask_pii`](#nemoguardrails-library-gliner-actions-gliner_mask_pii)                   | Masks any detected PII in the provided text using GLiNER.                        |

### Data

[`log`](#nemoguardrails-library-gliner-actions-log)

### API

```python
nemoguardrails.library.gliner.actions._mask_pii_outcome(
    source: str,
    original_text: str,
    masked_text: str
) -> nemoguardrails.actions.rail_outcome.RailOutcome
```

```python
nemoguardrails.library.gliner.actions._mask_text_with_entities(
    text: str,
    entities: typing.List[dict]
) -> str
```

Mask detected entities in text with their labels.

**Parameters:**

**`text`** `str`

Original text

---

**`entities`** `List[dict]`

List of entity dictionaries with 'value', 'suggested\_label',
'start\_position', 'end\_position' keys

---

**Returns:** `str`

Text with entities replaced by \[LABEL] placeholders

```python
nemoguardrails.library.gliner.actions._pii_detection_outcome(
    has_pii: bool
) -> nemoguardrails.actions.rail_outcome.RailOutcome
```

```python
nemoguardrails.library.gliner.actions._resolve_api_key(
    gliner_config: nemoguardrails.rails.llm.config.GLiNERDetection
) -> typing.Optional[str]
```

Resolve the GLiNER API key from the configured env var, logging a warning if the
env var is named but not set in the environment.

```python
nemoguardrails.library.gliner.actions.gliner_detect_pii(
    source: str,
    text: str,
    config: nemoguardrails.RailsConfig,
    http_client: nemoguardrails.http.HTTPClient | None = None,
    kwargs = {}
) -> nemoguardrails.actions.rail_outcome.RailOutcome
```

async

Checks whether the provided text contains any PII using GLiNER.

**Parameters:**

**`source`** `str`

The source for the text, i.e. "input", "output", "retrieval".

---

**`text`** `str`

The text to check.

---

**`config`** `RailsConfig`

The rails configuration object.

---

**Returns:** `RailOutcome`

RailOutcome.block() if PII is detected, RailOutcome.allow() otherwise.

**Raises:**

* `ValueError`: If the response is invalid or source is not valid.

```python
nemoguardrails.library.gliner.actions.gliner_mask_pii(
    source: str,
    text: str,
    config: nemoguardrails.RailsConfig,
    http_client: nemoguardrails.http.HTTPClient | None = None
) -> nemoguardrails.actions.rail_outcome.RailOutcome
```

async

Masks any detected PII in the provided text using GLiNER.

**Parameters:**

**`source`** `str`

The source for the text, i.e. "input", "output", "retrieval".

---

**`text`** `str`

The text to check.

---

**`config`** `RailsConfig`

The rails configuration object.

---

**Returns:** `RailOutcome`

RailOutcome.transform() with the altered text if it changed, RailOutcome.allow() otherwise.

**Raises:**

* `ValueError`: If the response is invalid or source is not valid.

```python
nemoguardrails.library.gliner.actions.log = logging.getLogger(__name__)
```