nemoguardrails.library.gliner.request

View as Markdown

Module for handling GLiNER detection requests.

Module Contents

Functions

NameDescription
gliner_requestSend a PII detection request to the GLiNER API.

Data

log

API

nemoguardrails.library.gliner.request.gliner_request(
text: str,
server_endpoint: str,
enabled_entities: typing.Optional[typing.List[str]] = None,
threshold: typing.Optional[float] = None,
chunk_length: typing.Optional[int] = None,
overlap: typing.Optional[int] = None,
flat_ner: typing.Optional[bool] = None,
api_key: typing.Optional[str] = None,
model: str = 'nvidia/gliner-pii'
) -> typing.Dict[str, typing.Any]
async

Send a PII detection request to the GLiNER API.

Supports two server formats:

  • Custom server (/v1/extract): plain JSON request, no auth required.
  • NIM API (/v1/chat/completions): OpenAI-compatible chat completions format, used by both the locally-run NIM container and the NVIDIA-hosted endpoint. Requires an API key for the hosted endpoint.

Parameters:

text
str

The text to analyze.

server_endpoint
str

The API endpoint URL.

enabled_entities
Optional[List[str]]Defaults to None

List of entity types to detect. If None, uses server defaults.

threshold
Optional[float]Defaults to None

Confidence threshold for entity detection (0.0 to 1.0).

chunk_length
Optional[int]Defaults to None

Length of text chunks for processing.

overlap
Optional[int]Defaults to None

Overlap between chunks.

flat_ner
Optional[bool]Defaults to None

Whether to use flat NER mode.

api_key
Optional[str]Defaults to None

Optional Bearer token for authenticated endpoints.

Returns: Dict[str, Any]

Normalized response dict with keys:

Raises:

  • ValueError: If the API call fails or the response cannot be parsed.
nemoguardrails.library.gliner.request.log = logging.getLogger(__name__)