guardrails_ai.sdk.guards_api¶
Classes¶
API for managing Guards and running validations. |
Module Contents¶
- class guardrails_ai.sdk.guards_api.GuardsApi(*, http_client: httpx.AsyncClient, headers: dict[str, str], max_retries: int)¶
Bases:
guardrails_ai.sdk.abstract_client.ClientAPI for managing Guards and running validations.
Accessed via
client.guards.- async create(guard: guardrails_ai.types.CreateGuardRequest) guardrails_ai.types.Guard¶
Creates a Guard on the Guardrails API.
Retries with exponential back-off up to
max_retriestimes on failure.- Parameters:
guard – The request body of the Guard to create.
- Returns:
A validated
Guardinstance.- Raises:
tenacity.RetryError – If all retry attempts are exhausted.
- async delete(id: str) guardrails_ai.types.Guard¶
Deletes a Guard on the Guardrails API.
Retries with exponential back-off up to
max_retriestimes on failure.- Parameters:
id – The unique id of the Guard to delete.
- Returns:
A validated
Guardinstance.- Raises:
tenacity.RetryError – If all retry attempts are exhausted.
- async list(*, name: str | None = None) list[guardrails_ai.types.Guard]¶
List Guards from the Guardrails API.
Retries with exponential back-off up to
max_retriestimes on failure.- Parameters:
name – If provided, will fetch guards only with the designated name. Defaults to None.
- Returns:
A validated list of
Guardinstances.- Raises:
tenacity.RetryError – If all retry attempts are exhausted.
- async retrieve(id: str) guardrails_ai.types.Guard¶
Fetch a Guard by id from the Guardrails API.
Retries with exponential back-off up to
max_retriestimes on failure.- Parameters:
id – The id of the Guard to retrieve.
- Returns:
A validated
Guardinstance.- Raises:
tenacity.RetryError – If all retry attempts are exhausted.
- async update(guard: guardrails_ai.types.Guard) guardrails_ai.types.Guard¶
Updates a Guard on the Guardrails API.
Retries with exponential back-off up to
max_retriestimes on failure.- Parameters:
guard – The updated Guard to persist.
- Returns:
A validated
Guardinstance.- Raises:
tenacity.RetryError – If all retry attempts are exhausted.
- async validate(id: str, content: str, **kwargs) guardrails_ai.types.ValidationOutcome¶
Validate content against a Guard.
Retries with exponential back-off up to
max_retriestimes on failure.- Parameters:
id – The unique id of the Guard to validate against.
content – The text content (typically LLM output) to validate.
**kwargs – Additional fields merged into the request body.
- Returns:
A
ValidationOutcomedescribing whether validation passed and, if so, the validated output.- Raises:
tenacity.RetryError – If all retry attempts are exhausted.
- http_client: httpx.AsyncClient¶