Skip to main content

Guardrails

Rules on what is sent to a model (input) and what it returns (output).

Access it as client.ai.guardrails on a Strongly client, or the same path on AsyncStrongly with await. All methods exist on both with identical signatures.

Quick start​

from strongly import Strongly

client = Strongly()

# Retrieve one by id
item = client.ai.guardrails.retrieve("<id>")

Methods​

Core​

retrieve​

retrieve(model_id: str) -> ModelGuardrails

Get a model's guardrails.

Other​

logs​

logs(model_id: str) -> SyncPaginator[GuardrailLog]

List what a model's guardrails did, newest first.

overview​

overview() -> GuardrailOverview

Every model guardrails can check, with its guardrails, and the last 24 hours' totals.

replace​

replace(model_id: str, *, enabled: bool, rules: Sequence[Mapping[str, Any]]) -> ModelGuardrails

Replace a model's guardrails with the state given.

Parameters

  • enabled (bool): Whether the guardrails are on.
  • rules (Sequence[Mapping[str, Any]]): Every rule the model is to have: id, template, name, enabled, priority and config (the template's settings by direction, every setting given, in snake_case). A rule the template cannot apply is refused, naming it.

set_enabled​

set_enabled(model_id: str, enabled: bool) -> ModelGuardrails

Turn a model's guardrails on or off, keeping its rules.

statistics​

statistics() -> GuardrailTotals

Count what guardrails did across your models in the last 24 hours.

templates​

templates() -> list[GuardrailTemplate]

List the rule templates, with whether the gateway can apply each.

test​

test(model_id: str, *, input: str, direction: str, rules: Sequence[Mapping[str, Any]]) -> GuardrailTestResult

Run rules on a sample text as the gateway would, without a model call or a record.

direction is input (sent to the model) or output (returned by it).