> ## 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.

# GuardrailRules SDK Reference

> SDK reference for the GuardrailRules API, available in Node.js and Python.

## GuardrailRules

### List GuardrailRules

Returns a paginated list of guardrail rules for the current project.

<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({});

    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[Literal["created_at", "updated_at", "display_name"]],
        "enabled": OptionalNullable[bool],
        "guardrail_id": List[str],
    }
    ```

    ```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"}}
    {
        "data": {
            "id": str,
            "created_at": date,
            "created_by_id": str,
            "description": Optional[str],
            "display_name": str,
            "enabled": bool,
            "expression": {  # optional
                "cel": str,
                "config": Dict[str, Any],
            },
            "guardrails": {  # optional
                "execute_on": Literal["input", "output", "both"],
                "id": str,
                "is_guardrail": Optional[bool],
                "sample_rate": Optional[float],
            },
            "plugins": {  # optional
                "of_pii_redaction": {
                    "entities": List[str],
                    "id": str,
                    "language": Optional[str],
                    "on_failure": Optional[str],
                    "threshold": Optional[float],
                },
            },
            "project_id": str,
            "timeout": int,
            "updated_at": date,
            "updated_by_id": str,
        },
        "has_more": bool,
        "object": str,
    }
    ```

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

### Create a GuardrailRule

Creates a new guardrail rule with expression, guardrails configuration, and timeout settings.

<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="Rosemarie_Wisoky")

      # 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: "Rosemarie_Wisoky",
    });

    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],
        "enabled": Optional[bool],
        "expression": {  # optional
            "cel": str,  # required
        },
        "guardrails": {  # optional
            "execute_on": Literal["input", "output", "both"],  # required
            "id": str,  # required
            "is_guardrail": Optional[bool],
            "sample_rate": Optional[float],
        },
        "project_id": Optional[str],
        "timeout": Optional[int],
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      description?: string;
      displayName: string;  // required
      enabled?: boolean;
      expression?: {
        cel: string;  // required
      };
      guardrails?: {
        executeOn: string;  // required
        id: string;  // required
        isGuardrail?: boolean;
        sampleRate?: number;
      };
      projectId?: string;
      timeout?: number;
    }
    ```
  </CodeGroup>
</Expandable>

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

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

### List Used Guardrails

Returns the distinct guardrail ids referenced across all guardrail rules in 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="Response">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "guardrail_ids": List[str],
        "object": str,
    }
    ```

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

### Delete a GuardrailRule

Deletes an existing guardrail rule by ID.

<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:

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

      # Use the SDK ...

  ```

  ```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() {
    await orq.guardrailRules.delete({
      guardrailRuleId: "<id>",
    });

  }

  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>

### Retrieve a GuardrailRule

Retrieves the details of an existing guardrail rule by ID.

<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"}}
    {
        "id": str,
        "created_at": date,
        "created_by_id": str,
        "description": Optional[str],
        "display_name": str,
        "enabled": bool,
        "expression": {  # optional
            "cel": str,
            "config": Dict[str, Any],
        },
        "guardrails": {  # optional
            "execute_on": Literal["input", "output", "both"],
            "id": str,
            "is_guardrail": Optional[bool],
            "sample_rate": Optional[float],
        },
        "plugins": {  # optional
            "of_pii_redaction": {
                "entities": List[str],
                "id": str,
                "language": Optional[str],
                "on_failure": Optional[str],
                "threshold": Optional[float],
            },
        },
        "project_id": str,
        "timeout": int,
        "updated_at": date,
        "updated_by_id": str,
    }
    ```

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

### Update a GuardrailRule

Partially updates an existing guardrail rule. Only provided fields are updated.

<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>",
      requestBody: {},
    });

    console.log(result);
  }

  run();
  ```
</CodeGroup>

<Expandable title="Parameters">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "guardrail_rule_id": str,  # required
        "description": Optional[str],
        "display_name": Optional[str],
        "enabled": Optional[bool],
        "expression": {  # optional
            "cel": str,  # required
        },
        "guardrails": {  # optional
            "execute_on": Literal["input", "output", "both"],  # required
            "id": str,  # required
            "is_guardrail": Optional[bool],
            "sample_rate": Optional[float],
        },
        "timeout": Optional[int],
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      guardrailRuleId: string;  // required
      requestBody: {  // required
        description?: string;
        displayName?: string;
        enabled?: boolean;
        expression?: {
          cel: string;  // required
        };
        guardrails?: {
          executeOn: string;  // required
          id: string;  // required
          isGuardrail?: boolean;
          sampleRate?: number;
        };
        timeout?: number;
      };
    }
    ```
  </CodeGroup>
</Expandable>

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

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