nemoguardrails.library.polygraf.request

View as Markdown

Module for handling Polygraf PII detection requests.

Module Contents

Functions

NameDescription
_send_polygraf_request-
polygraf_requestSend a PII detection request to the Polygraf API.

Data

DEFAULT_TIMEOUT_SECONDS

API

nemoguardrails.library.polygraf.request._send_polygraf_request(
session: aiohttp.ClientSession,
server_endpoint: str,
payload: typing.Dict[str, typing.Any],
headers: typing.Dict[str, str],
timeout: aiohttp.ClientTimeout
) -> typing.List[typing.Dict[str, typing.Any]]
async
nemoguardrails.library.polygraf.request.polygraf_request(
text: str,
server_endpoint: str,
api_key: typing.Optional[str] = None,
session: typing.Optional[aiohttp.ClientSession] = None,
timeout: float = DEFAULT_TIMEOUT_SECONDS
) -> typing.List[typing.Dict[str, typing.Any]]
async

Send a PII detection request to the Polygraf API.

Parameters:

text
str

The text to analyze.

server_endpoint
str

The API endpoint URL.

api_key
Optional[str]Defaults to None

The API key for the Polygraf service.

session
Optional[aiohttp.ClientSession]Defaults to None

Optional shared aiohttp session. Passing a session lets callers reuse connections across multiple PII checks.

timeout
floatDefaults to DEFAULT_TIMEOUT_SECONDS

Per-request timeout in seconds. Applied to both caller-provided and internally created sessions.

Returns: List[Dict[str, Any]]

The list of entities detected by the Polygraf server.

Raises:

  • ValueError: If the API call fails, times out, or the response cannot be parsed as JSON.
nemoguardrails.library.polygraf.request.DEFAULT_TIMEOUT_SECONDS = 30