> ## Documentation Index
> Fetch the complete documentation index at: https://docs.useagentflow.co/llms.txt
> Use this file to discover all available pages before exploring further.

# SDK: Guardrails

> Configure tenant guardrail policies and manage per-agent assignments

Guardrail administration spans two SDK namespaces: `client.settings` owns tenant policy, while `client.agents.guardrails` owns assignment to a specific agent.

## Read the tenant catalog

<CodeGroup>
  ```python Python theme={null}
  catalog = await client.settings.list_guardrails()
  for guardrail in catalog.guardrails:
      print(guardrail.id, guardrail.enabled, guardrail.available_in_catalog)
  ```

  ```ts TypeScript theme={null}
  const catalog = await client.settings.list_guardrails();
  for (const guardrail of catalog.guardrails) {
    console.log(guardrail.id, guardrail.enabled, guardrail.available_in_catalog);
  }
  ```
</CodeGroup>

The three stable IDs are `pii_detection`, `adherence_detection`, and `roost_open_safety`. Each setting includes its current and default policy, replacement message, model, enabled state, cadence, and catalog availability.

## Update tenant policy

Updates replace all four mutable fields. Read the current setting first when changing only one value.

<CodeGroup>
  ```python Python theme={null}
  from agentflow.models import TenantGuardrailUpdate

  current = next(item for item in catalog.guardrails if item.id == "pii_detection")
  updated = await client.settings.update_guardrail(
      "pii_detection",
      TenantGuardrailUpdate(
          policy=current.policy,
          replacement_message="I can't provide that response because it may expose personal information.",
          model=current.model,
          enabled=True,
      ),
  )
  ```

  ```ts TypeScript theme={null}
  const catalog = await client.settings.list_guardrails();
  const current = catalog.guardrails.find((item) => item.id === "pii_detection");
  if (!current) throw new Error("pii_detection guardrail is unavailable");

  const updated = await client.settings.update_guardrail("pii_detection", {
    policy: current.policy,
    replacement_message:
      "I can't provide that response because it may expose personal information.",
    model: current.model,
    enabled: true,
  });
  ```
</CodeGroup>

Control whether a guardrail can be newly assigned from the agent catalog:

<CodeGroup>
  ```python Python theme={null}
  await client.settings.set_guardrail_available(
      "pii_detection",
      available_in_catalog=True,
  )
  ```

  ```ts TypeScript theme={null}
  await client.settings.set_guardrail_availability("pii_detection", true);
  ```
</CodeGroup>

## Assign guardrails to an agent

<CodeGroup>
  ```python Python theme={null}
  guardrails = await client.agents.guardrails.list(agent_id)
  await client.agents.guardrails.assign(agent_id, "pii_detection")
  await client.agents.guardrails.detach(agent_id, "pii_detection")
  ```

  ```ts TypeScript theme={null}
  const guardrails = await client.agents.guardrails.list(agentId);
  await client.agents.guardrails.assign(agentId, "pii_detection");
  await client.agents.guardrails.detach(agentId, "pii_detection");
  ```
</CodeGroup>

Assignment writes and every tenant policy write require tenant-admin permission. Assign is idempotent. Detach returns `404` when the guardrail is not assigned.
