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

# Guardrail Rules SDK Reference

> Manage guardrail rules with the Node.js and Python SDKs: create, list, update, and delete rules and list guardrails used across your workspace.

## Guardrail Rules

### List Guardrail Rules

Returns guardrail rules with cursor pagination, search, status, project, sort, and referenced-guardrail filters.

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  from orq_ai_sdk import Orq
  import os

  with Orq(
      api_key=os.getenv("ORQ_API_KEY", ""),
  ) as orq:

      res = orq.guardrail_rules.list(limit=10)

      # Handle response
      print(res)

  ```

  ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import { Orq } from "@orq-ai/node";

  const orq = new Orq({
    apiKey: process.env["ORQ_API_KEY"] ?? "",
  });

  async function run() {
    const result = await orq.guardrailRules.list({
      limit: 10,
    });

    console.log(result);
  }

  run();
  ```
</CodeGroup>

<Expandable title="Parameters">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "limit": Optional[int],
        "starting_after": Optional[str],
        "ending_before": Optional[str],
        "project_id": Optional[str],
        "search": Optional[str],
        "sort_by": Optional[str],
        "enabled": Optional[bool],
        "guardrail_id": List[str],  # optional
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      limit?: number;
      startingAfter?: string;
      endingBefore?: string;
      projectId?: string;
      search?: string;
      sortBy?: string;
      enabled?: boolean;
      guardrailId?: string[];
    }
    ```
  </CodeGroup>
</Expandable>

<Expandable title="Response">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "object": str,
        "data": [{
            "id": str,
            "created_at": str,
            "updated_at": str,
            "created_by_id": str,
            "updated_by_id": str,
            "project_id": str,
            "display_name": str,
            "description": str,
            "enabled": bool,
            "expression": {  # optional
                "config": Dict[str, Any],  # optional
                "cel": Optional[str],
            },
            "guardrails": [{
                "id": str,
                "execute_on": str,
                "sample_rate": Optional[float],
                "is_guardrail": Optional[bool],
            }],
            "plugins": [{
                "id": Optional[str],
                "language": Optional[str],
                "entities": List[str],  # optional
                "on_failure": Optional[str],
                "threshold": Optional[float],
                "regions": List[str],  # optional
                "entity_thresholds": Dict[str, float],  # optional
            }],
        }],
        "has_more": bool,
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      object: string;
      data: {
        id: string;
        createdAt: Date;
        updatedAt: Date;
        createdById: string;
        updatedById: string;
        projectId: string;
        displayName: string;
        description: string;
        enabled: boolean;
        expression?: {
          config?: Record<string, unknown>;
          cel?: string;
        };
        guardrails: {
          id: string;
          executeOn: string;
          sampleRate?: number;
          isGuardrail?: boolean;
        }[];
        plugins: {
          id?: string;
          language?: string;
          entities?: string[];
          onFailure?: string;
          threshold?: number;
          regions?: string[];
          entityThresholds?: Record<string, number>;
        }[];
      }[];
      hasMore: boolean;
    }
    ```
  </CodeGroup>
</Expandable>

### Create a Guardrail Rule

Creates a guardrail rule with metadata and optional evaluator, plugin, and matching configuration. Rules default to disabled when `enabled` is omitted.

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  from orq_ai_sdk import Orq
  import os

  with Orq(
      api_key=os.getenv("ORQ_API_KEY", ""),
  ) as orq:

      res = orq.guardrail_rules.create(display_name="Content policy")

      # Handle response
      print(res)

  ```

  ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import { Orq } from "@orq-ai/node";

  const orq = new Orq({
    apiKey: process.env["ORQ_API_KEY"] ?? "",
  });

  async function run() {
    const result = await orq.guardrailRules.create({
      displayName: "Content policy",
    });

    console.log(result);
  }

  run();
  ```
</CodeGroup>

<Expandable title="Parameters">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "display_name": str,  # required
        "description": Optional[str],
        "project_id": Optional[str],
        "enabled": Optional[bool],
        "expression": {  # optional
            "config": Dict[str, Any],  # optional
            "cel": Optional[str],
        },
        "guardrails": [{  # optional
            "id": str,  # required
            "execute_on": str,  # required
            "sample_rate": Optional[float],
            "is_guardrail": Optional[bool],
        }],
        "plugins": [{  # optional
            "id": Optional[str],
            "language": Optional[str],
            "entities": List[str],  # optional
            "on_failure": Optional[str],
            "threshold": Optional[float],
            "regions": List[str],  # optional
            "entity_thresholds": Dict[str, float],  # optional
        }],
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      displayName: string;  // required
      description?: string;
      projectId?: string;
      enabled?: boolean;
      expression?: {
        config?: Record<string, unknown>;
        cel?: string;
      };
      guardrails?: {
        id: string;  // required
        executeOn: string;  // required
        sampleRate?: number;
        isGuardrail?: boolean;
      }[];
      plugins?: {
        id?: string;
        language?: string;
        entities?: string[];
        onFailure?: string;
        threshold?: number;
        regions?: string[];
        entityThresholds?: Record<string, number>;
      }[];
    }
    ```
  </CodeGroup>
</Expandable>

<Expandable title="Response">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "guardrail_rule": {
            "id": str,
            "created_at": str,
            "updated_at": str,
            "created_by_id": str,
            "updated_by_id": str,
            "project_id": str,
            "display_name": str,
            "description": str,
            "enabled": bool,
            "expression": {  # optional
                "config": Dict[str, Any],  # optional
                "cel": Optional[str],
            },
            "guardrails": [{
                "id": str,
                "execute_on": str,
                "sample_rate": Optional[float],
                "is_guardrail": Optional[bool],
            }],
            "plugins": [{
                "id": Optional[str],
                "language": Optional[str],
                "entities": List[str],  # optional
                "on_failure": Optional[str],
                "threshold": Optional[float],
                "regions": List[str],  # optional
                "entity_thresholds": Dict[str, float],  # optional
            }],
        },
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      guardrailRule: {
        id: string;
        createdAt: Date;
        updatedAt: Date;
        createdById: string;
        updatedById: string;
        projectId: string;
        displayName: string;
        description: string;
        enabled: boolean;
        expression?: {
          config?: Record<string, unknown>;
          cel?: string;
        };
        guardrails: {
          id: string;
          executeOn: string;
          sampleRate?: number;
          isGuardrail?: boolean;
        }[];
        plugins: {
          id?: string;
          language?: string;
          entities?: string[];
          onFailure?: string;
          threshold?: number;
          regions?: string[];
          entityThresholds?: Record<string, number>;
        }[];
      };
    }
    ```
  </CodeGroup>
</Expandable>

### List Used Guardrails

Returns the distinct guardrail identifiers used by guardrail rules in the requested scope.

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  from orq_ai_sdk import Orq
  import os

  with Orq(
      api_key=os.getenv("ORQ_API_KEY", ""),
  ) as orq:

      res = orq.guardrail_rules.list_used_guardrails()

      # Handle response
      print(res)

  ```

  ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import { Orq } from "@orq-ai/node";

  const orq = new Orq({
    apiKey: process.env["ORQ_API_KEY"] ?? "",
  });

  async function run() {
    const result = await orq.guardrailRules.listUsedGuardrails();

    console.log(result);
  }

  run();
  ```
</CodeGroup>

<Expandable title="Parameters">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "project_id": Optional[str],
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      projectId?: string;
    }
    ```
  </CodeGroup>
</Expandable>

<Expandable title="Response">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "object": str,
        "guardrail_ids": List[str],
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      object: string;
      guardrailIds: string[];
    }
    ```
  </CodeGroup>
</Expandable>

### Retrieve a Guardrail Rule

Retrieves a guardrail rule by its unique identifier.

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  from orq_ai_sdk import Orq
  import os

  with Orq(
      api_key=os.getenv("ORQ_API_KEY", ""),
  ) as orq:

      res = orq.guardrail_rules.retrieve(guardrail_rule_id="<id>")

      # Handle response
      print(res)

  ```

  ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import { Orq } from "@orq-ai/node";

  const orq = new Orq({
    apiKey: process.env["ORQ_API_KEY"] ?? "",
  });

  async function run() {
    const result = await orq.guardrailRules.retrieve({
      guardrailRuleId: "<id>",
    });

    console.log(result);
  }

  run();
  ```
</CodeGroup>

<Expandable title="Parameters">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "guardrail_rule_id": str,  # required
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      guardrailRuleId: string;  // required
    }
    ```
  </CodeGroup>
</Expandable>

<Expandable title="Response">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "guardrail_rule": {
            "id": str,
            "created_at": str,
            "updated_at": str,
            "created_by_id": str,
            "updated_by_id": str,
            "project_id": str,
            "display_name": str,
            "description": str,
            "enabled": bool,
            "expression": {  # optional
                "config": Dict[str, Any],  # optional
                "cel": Optional[str],
            },
            "guardrails": [{
                "id": str,
                "execute_on": str,
                "sample_rate": Optional[float],
                "is_guardrail": Optional[bool],
            }],
            "plugins": [{
                "id": Optional[str],
                "language": Optional[str],
                "entities": List[str],  # optional
                "on_failure": Optional[str],
                "threshold": Optional[float],
                "regions": List[str],  # optional
                "entity_thresholds": Dict[str, float],  # optional
            }],
        },
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      guardrailRule: {
        id: string;
        createdAt: Date;
        updatedAt: Date;
        createdById: string;
        updatedById: string;
        projectId: string;
        displayName: string;
        description: string;
        enabled: boolean;
        expression?: {
          config?: Record<string, unknown>;
          cel?: string;
        };
        guardrails: {
          id: string;
          executeOn: string;
          sampleRate?: number;
          isGuardrail?: boolean;
        }[];
        plugins: {
          id?: string;
          language?: string;
          entities?: string[];
          onFailure?: string;
          threshold?: number;
          regions?: string[];
          entityThresholds?: Record<string, number>;
        }[];
      };
    }
    ```
  </CodeGroup>
</Expandable>

### Delete a Guardrail Rule

Permanently deletes a guardrail rule.

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  from orq_ai_sdk import Orq
  import os

  with Orq(
      api_key=os.getenv("ORQ_API_KEY", ""),
  ) as orq:

      res = orq.guardrail_rules.delete(guardrail_rule_id="<id>")

      # Handle response
      print(res)

  ```

  ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import { Orq } from "@orq-ai/node";

  const orq = new Orq({
    apiKey: process.env["ORQ_API_KEY"] ?? "",
  });

  async function run() {
    const result = await orq.guardrailRules.delete({
      guardrailRuleId: "<id>",
    });

    console.log(result);
  }

  run();
  ```
</CodeGroup>

<Expandable title="Parameters">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "guardrail_rule_id": str,  # required
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      guardrailRuleId: string;  // required
    }
    ```
  </CodeGroup>
</Expandable>

### Update a Guardrail Rule

Partially updates guardrail-rule metadata or configuration. Project scope is immutable.

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  from orq_ai_sdk import Orq
  import os

  with Orq(
      api_key=os.getenv("ORQ_API_KEY", ""),
  ) as orq:

      res = orq.guardrail_rules.update(guardrail_rule_id="<id>")

      # Handle response
      print(res)

  ```

  ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import { Orq } from "@orq-ai/node";

  const orq = new Orq({
    apiKey: process.env["ORQ_API_KEY"] ?? "",
  });

  async function run() {
    const result = await orq.guardrailRules.update({
      guardrailRuleId: "<id>",
      updateGuardrailRuleRequest: {},
    });

    console.log(result);
  }

  run();
  ```
</CodeGroup>

<Expandable title="Parameters">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "guardrail_rule_id": str,  # required
        "display_name": Optional[str],
        "description": Optional[str],
        "enabled": Optional[bool],
        "expression": {  # optional
            "config": Dict[str, Any],  # optional
            "cel": Optional[str],
        },
        "guardrails": [{  # optional
            "id": str,  # required
            "execute_on": str,  # required
            "sample_rate": Optional[float],
            "is_guardrail": Optional[bool],
        }],
        "plugins": [{  # optional
            "id": Optional[str],
            "language": Optional[str],
            "entities": List[str],  # optional
            "on_failure": Optional[str],
            "threshold": Optional[float],
            "regions": List[str],  # optional
            "entity_thresholds": Dict[str, float],  # optional
        }],
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      guardrailRuleId: string;  // required
      updateGuardrailRuleRequest: {  // required
        displayName?: string;
        description?: string;
        enabled?: boolean;
        expression?: {
          config?: Record<string, unknown>;
          cel?: string;
        };
        guardrails?: {
          id: string;  // required
          executeOn: string;  // required
          sampleRate?: number;
          isGuardrail?: boolean;
        }[];
        plugins?: {
          id?: string;
          language?: string;
          entities?: string[];
          onFailure?: string;
          threshold?: number;
          regions?: string[];
          entityThresholds?: Record<string, number>;
        }[];
      };
    }
    ```
  </CodeGroup>
</Expandable>

<Expandable title="Response">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "guardrail_rule": {
            "id": str,
            "created_at": str,
            "updated_at": str,
            "created_by_id": str,
            "updated_by_id": str,
            "project_id": str,
            "display_name": str,
            "description": str,
            "enabled": bool,
            "expression": {  # optional
                "config": Dict[str, Any],  # optional
                "cel": Optional[str],
            },
            "guardrails": [{
                "id": str,
                "execute_on": str,
                "sample_rate": Optional[float],
                "is_guardrail": Optional[bool],
            }],
            "plugins": [{
                "id": Optional[str],
                "language": Optional[str],
                "entities": List[str],  # optional
                "on_failure": Optional[str],
                "threshold": Optional[float],
                "regions": List[str],  # optional
                "entity_thresholds": Dict[str, float],  # optional
            }],
        },
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      guardrailRule: {
        id: string;
        createdAt: Date;
        updatedAt: Date;
        createdById: string;
        updatedById: string;
        projectId: string;
        displayName: string;
        description: string;
        enabled: boolean;
        expression?: {
          config?: Record<string, unknown>;
          cel?: string;
        };
        guardrails: {
          id: string;
          executeOn: string;
          sampleRate?: number;
          isGuardrail?: boolean;
        }[];
        plugins: {
          id?: string;
          language?: string;
          entities?: string[];
          onFailure?: string;
          threshold?: number;
          regions?: string[];
          entityThresholds?: Record<string, number>;
        }[];
      };
    }
    ```
  </CodeGroup>
</Expandable>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.