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

# Run guardrail checks on a text

POST http://localhost:5173/api/v1/private/guardrails/validations
Content-Type: application/json

Runs the requested checks on the text through the Opik inference decision service and returns a verdict per check. Writes nothing: the SDK reports the results to the guardrails batch endpoint, as before.

Reference: https://www.comet.com/docs/opik/reference/rest-api/guardrails/validate-guardrails

## Servers

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

## Request

### Body (application/json)

This endpoint expects a GuardrailsValidationRequest.

- `text` (string, required) — The text to check, at most 16384 characters as the decision service counts them: on the text's JSON encoding, so the two quotes count, a quote, backslash or line break counts as 2, and any other control or non-ASCII character as 6 (an emoji as 12). In practice about 16,380 characters of English text fit, about 2,730 of text in Cyrillic, Greek, Hebrew, Arabic, Chinese or Japanese, and about 1,365 emoji. A longer text is rejected rather than cut.
- `validations` (list of ValidationDescriptor, required) — The checks to run. Together they must fit in 64 questions to the decision service, asked in up to two calls of 32: each PII class and each topic list is one question, prompt injection is one

## Response

### 200

A verdict per check

- `validations` (list of ValidationResult, required)
- `validation_passed` (boolean, optional)

## Errors

### 400 Bad Request Error

Bad Request: invalid settings for a check, or checks that need more than 64 questions (each PII class and each topic list is one question)

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

### 401 Unauthorized Error

Missing or unknown credentials

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

### 403 Forbidden Error

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

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

### 422 Unprocessable Entity Error

Unprocessable Content: blank text, text over the decision service's limit, or a validations list outside 1 to 32 entries

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

### 429 Too Many Requests Error

Too many requests

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

### ValidationDescriptor

The checks to run. Together they must fit in 64 questions to the decision service, asked in up to two calls of 32: each PII class and each topic list is one question, prompt injection is one

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

### ValidationResult

- `type` (enum, required)
  - Allowed values: `TOPIC`, `PII`, `LLM_JUDGE`, `PROMPT_INJECTION`, `CUSTOM_CLASSIFIER`
- `validation_config` (JsonNode, required)
- `validation_details` (JsonNode, required)
- `validation_passed` (boolean, optional)
- `error` (string, optional) — Set when the check could not run; the entry then passes

### JsonNode

## Examples

**Request**

```json
{
  "text": "string",
  "validations": [
    {
      "type": "TOPIC",
      "config": {}
    }
  ]
}
```

**Response**

```json
{
  "validations": [
    {
      "type": "TOPIC",
      "validation_config": {},
      "validation_details": {},
      "validation_passed": true,
      "error": "string"
    }
  ],
  "validation_passed": true
}
```

**SDK Code**

```python
import requests

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

payload = {
    "text": "string",
    "validations": [
        {
            "type": "TOPIC",
            "config": {}
        }
    ]
}
headers = {"Content-Type": "application/json"}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'http://localhost:5173/api/v1/private/guardrails/validations';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: '{"text":"string","validations":[{"type":"TOPIC","config":{}}]}'
};

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"
	"strings"
	"net/http"
	"io"
)

func main() {

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

	payload := strings.NewReader("{\n  \"text\": \"string\",\n  \"validations\": [\n    {\n      \"type\": \"TOPIC\",\n      \"config\": {}\n    }\n  ]\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "application/json")

	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/validations")

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

request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n  \"text\": \"string\",\n  \"validations\": [\n    {\n      \"type\": \"TOPIC\",\n      \"config\": {}\n    }\n  ]\n}"

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.post("http://localhost:5173/api/v1/private/guardrails/validations")
  .header("Content-Type", "application/json")
  .body("{\n  \"text\": \"string\",\n  \"validations\": [\n    {\n      \"type\": \"TOPIC\",\n      \"config\": {}\n    }\n  ]\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'http://localhost:5173/api/v1/private/guardrails/validations', [
  'body' => '{
  "text": "string",
  "validations": [
    {
      "type": "TOPIC",
      "config": {}
    }
  ]
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("http://localhost:5173/api/v1/private/guardrails/validations");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"text\": \"string\",\n  \"validations\": [\n    {\n      \"type\": \"TOPIC\",\n      \"config\": {}\n    }\n  ]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["Content-Type": "application/json"]
let parameters = [
  "text": "string",
  "validations": [
    [
      "type": "TOPIC",
      "config": []
    ]
  ]
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "http://localhost:5173/api/v1/private/guardrails/validations")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

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()
```