> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://www.comet.com/docs/opik/llms.txt.

# Find guardrail policies

GET http://localhost:5173/api/v1/private/guardrails/policies

Find guardrail policies in a workspace

Reference: https://www.comet.com/docs/opik/reference/rest-api/guardrail-policies/find-guardrail-policies

## Servers

- `http://localhost:5173/api` (Local server, default)
- `https://www.comet.com/opik/api` (Opik Cloud)

## Request

### Query parameters

- `page` (integer, optional, default: 1)
- `size` (integer, optional, default: 10)
- `name` (string, optional) — Filter policies by name (partial match, case insensitive)
- `names` (string, optional) — Filter policies by exact names, ignoring case, as a JSON array of names
- `execution_scope` (enum, optional) — Filter policies by execution scope
  - Allowed values: `on_request`, `global`
- `sorting` (string, optional)

## Response

### 200

Guardrail policy page

- `content` (list of GuardrailPolicy_Public, optional)
- `page` (integer, optional)
- `size` (integer, optional)
- `total` (long, optional)
- `sortable_by` (list of string, optional)

## Errors

### 400 Bad Request Error

Bad Request: names is not a JSON array of strings

- `code` (integer, optional)
- `message` (string, optional)
- `details` (string, optional)

### 403 Forbidden Error

Guardrails are not enabled for this deployment, or not enabled for the workspace's organization

- `code` (integer, optional)
- `message` (string, optional)
- `details` (string, optional)

### 503 Service Unavailable Error

Could not verify with the platform that guardrails are enabled for the workspace's organization; retry later

- `code` (integer, optional)
- `message` (string, optional)
- `details` (string, optional)

## Types

### GuardrailPolicy_Public

- `name` (string, required) — The SDK names policies by name, so it is unique in the workspace, ignoring case
- `rules` (list of GuardrailPolicyRule_Public, required) — At most one rule per type
- `id` (string, optional) — Optional on create, generated when missing, as for prompts and datasets. Ignored on update, where the path names the policy
- `description` (string, optional)
- `execution_scope` (enum, optional, default: on_request) — on_request applies the policy when the SDK names it, global applies it to every guardrail built from stored policies in the workspace. Missing or null means on_request
  - Allowed values: `on_request`, `global`
- `created_at` (datetime, optional)
- `created_by` (string, optional)
- `last_updated_at` (datetime, optional)
- `last_updated_by` (string, optional)

### GuardrailPolicyRule_Public

At most one rule per type

- `type` (enum, required)
  - Allowed values: `TOPIC`, `PII`, `LLM_JUDGE`, `PROMPT_INJECTION`, `CUSTOM_CLASSIFIER`
- `config` (JsonNode, required)

### JsonNode

## Examples

**Response**

```json
{
  "content": [
    {
      "name": "string",
      "rules": [
        {
          "type": "TOPIC",
          "config": {}
        }
      ],
      "id": "string",
      "description": "string",
      "execution_scope": "on_request",
      "created_at": "2024-01-15T09:30:00Z",
      "created_by": "string",
      "last_updated_at": "2024-01-15T09:30:00Z",
      "last_updated_by": "string"
    }
  ],
  "page": 1,
  "size": 1,
  "total": 1,
  "sortable_by": [
    "string"
  ]
}
```

**SDK Code**

```python
import requests

url = "http://localhost:5173/api/v1/private/guardrails/policies"

response = requests.get(url)

print(response.json())
```

```javascript
const url = 'http://localhost:5173/api/v1/private/guardrails/policies';
const options = {method: 'GET'};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "http://localhost:5173/api/v1/private/guardrails/policies"

	req, _ := http.NewRequest("GET", url, nil)

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("http://localhost:5173/api/v1/private/guardrails/policies")

http = Net::HTTP.new(url.host, url.port)

request = Net::HTTP::Get.new(url)

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.get("http://localhost:5173/api/v1/private/guardrails/policies")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('GET', 'http://localhost:5173/api/v1/private/guardrails/policies');

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("http://localhost:5173/api/v1/private/guardrails/policies");
var request = new RestRequest(Method.GET);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let request = NSMutableURLRequest(url: NSURL(string: "http://localhost:5173/api/v1/private/guardrails/policies")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "GET"

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```