Skip to main content

AI Guard | Python SDK

AI Guard service client.

AIGuard(token, config, logger_name, config_id)

Initializes a new AI Guard client.

str

Pangea API token.

PangeaConfig | None

Pangea service configuration.

str

Logger name.

str | None

Configuration ID.

from pangea import PangeaConfig
from pangea.services import AIGuard

config = PangeaConfig(domain="aws.us.pangea.cloud")
ai_guard = AIGuard(token="pangea_token", config=config)

Download file

AIGuard.download_file(url, filename)

Download a file from the specified URL and save it with the given filename.

str

URL of the file to download

str | None

Name to save the downloaded file as. If not provided, the filename will be determined from the Content-Disposition header or the URL.

Text Guard for scanning LLM inputs and outputs

AIGuard.guard_text(text, messages, llm_input, recipe, debug, llm_info, log_field)

Analyze and redact text to avoid manipulation of the model, addition of malicious content, and other undesirable data transfers.

str | None

Text to be scanned by AI Guard for PII, sensitive data, malicious content, and other data types defined by the configuration. Supports processing up to 10KB of text.

_T | None

Structured messages data to be scanned by AI Guard for PII, sensitive data, malicious content, and other data types defined by the configuration. Supports processing up to 10KB of JSON text

_T | None

Structured full llm payload data to be scanned by AI Guard for PII, sensitive data, malicious content, and other data types defined by the configuration. Supports processing up to 10KB of JSON text

str | None

Recipe key of a configuration of data types and settings defined in the Pangea User Console. It specifies the rules that are to be applied to the text, such as defang malicious URLs.

bool | None

Setting this value to true will provide a detailed analysis of the text data

str | None

Short string hint for the LLM Provider information

Additional fields to include in activity log

response = ai_guard.guard_text("text")

Poll result

AIGuard.poll_result(exception)

Returns request's result that has been accepted by the server

Optional[AcceptedRequestException]

Exception that was previously raised by the SDK on a call that is being processed.

PangeaResponse

response = service.poll_result(exception)