> 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.gliner.actions

PII detection using GLiNER.

## Module Contents

### Functions

| Name                                                                                          | Description                                                                      |
| --------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- |
| [`_mask_text_with_entities`](#nemoguardrails-library-gliner-actions-_mask_text_with_entities) | Mask detected entities in text with their labels.                                |
| [`_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 |
| [`detect_pii_mapping`](#nemoguardrails-library-gliner-actions-detect_pii_mapping)             | Mapping for detect\_pii.                                                         |
| [`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_text_with_entities(
    text: str,
    entities: typing.List[dict]
) -> str
```

Mask detected entities in text with their labels.

**Parameters:**

Original text

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._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.detect_pii_mapping(
    result: bool
) -> bool
```

Mapping for detect\_pii.

Since the function returns True when PII is detected,
we block if result is True.

```python
nemoguardrails.library.gliner.actions.gliner_detect_pii(
    source: str,
    text: str,
    config: nemoguardrails.RailsConfig,
    kwargs = {}
)
```

async

Checks whether the provided text contains any PII using GLiNER.

**Parameters:**

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

The text to check.

The rails configuration object.

**Returns:**

True if PII is detected, False 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
)
```

async

Masks any detected PII in the provided text using GLiNER.

**Parameters:**

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

The text to check.

The rails configuration object.

**Returns:**

The altered text with PII masked.

**Raises:**

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

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