> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.lakera.ai/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.lakera.ai/_mcp/server.

# Get policy

GET https://platform.lakera.ai/api/v1/policies/{policyId}

Retrieve a single policy, including the projects currently using it

Reference: https://docs.lakera.ai/api-reference/platform-api/policies/get-policy

## Authentication

- `Authorization` header (bearer token, required) — Bearer authentication using API key. Generate an API key from the AI Guardrails Dashboard. Example: Bearer sk_123... Keys carry one of two access scopes, chosen when the key is created: - **Read and write** — may call every endpoint. This is the default, and the scope of every key created before scopes were introduced. - **Read only** — may call read endpoints such as `/v1-beta/logs`, `/v1-beta/analytics` and the `GET` endpoints. Write endpoints return `403`. Issue a read-only key to anything that only needs to retrieve data, such as a log-shipping job or a dashboard, so that it cannot modify your policies or projects.

## Request

### Path parameters

- `policyId` (string, required)

## Response

### 200

Policy details

- `policy` (CustomPolicy, required) — A policy as returned by the API

## Errors

### 403 Forbidden Error

Your API key is read-only and this endpoint writes, Policies V2 is not enabled for your organization, or your organization has reached its maximum number of policies.

- `status` (enum, optional) — Response status
  - Allowed values: `error`
- `error` (string, optional) — Short machine-readable error identifier
- `message` (string, optional) — Human-readable error message
- `code` (integer, optional) — HTTP status code
- `request_id` (string, optional) — Unique identifier for the request

### 404 Not Found Error

No policy with this ID exists in your organization

- `status` (enum, optional) — Response status
  - Allowed values: `error`
- `error` (string, optional) — Short machine-readable error identifier
- `message` (string, optional) — Human-readable error message
- `code` (integer, optional) — HTTP status code
- `request_id` (string, optional) — Unique identifier for the request

## Types

### CustomPolicy

A policy as returned by the API

- `policy_id` (string, required) — The ID of the policy
- `version_id` (integer, required) — The policy's version number. Incremented each time the policy is updated.
- `name` (string, required) — A descriptive name for the policy
- `default_threshold` (enum, required) — The confidence level at or above which the policy's detectors flag content.
  - Allowed values: `l1_confident`, `l2_very_likely`, `l3_likely`, `l4_less_likely`
- `detectors` (list of DetectorConfig, required) — The detectors configured on this policy
- `custom_guardrails` (list of CustomGuardrailEntry, optional) — The custom guardrails attached to this policy. Note the asymmetry with `PolicyRequest`, which takes bare IDs in `custom_guardrail_ids`.
- `updated_at` (string, optional, nullable) — When this version of the policy was created
- `projects` (list of PolicyProjectBrief, optional) — The projects currently using this policy

### DetectorConfig

A single detector, screening one location. To run the same detector on more than one location, add one entry per location.

- `type` (enum, required) — The detector type
  - Allowed values: `prompt_attack`, `moderated_content/hate`, `moderated_content/sexual`, `moderated_content/profanity`, `moderated_content/violence`, `moderated_content/weapons`, `moderated_content/crime`, `moderated_content/self_harm`, `pii/address`, `pii/credit_card`, `pii/email`, `pii/ip_address`, `pii/name`, `pii/phone_number`, `pii/us_social_security_number`, `pii/iban_code`, `unknown_links`, `override_allow`, `override_deny`, `tool_risk/payload`, `tool_risk/create`, `tool_risk/read`, `tool_risk/update`, `tool_risk/delete`, `tool_risk/untrusted_destination`, `tool_risk/untrusted_source`, `dangerous_deviation`, `tool_access_control`
- `location` (enum, required) — Where in the conversation a detector screens. - `user::content` — content of user messages (model input). - `assistant::content` — content of model responses (model output). - `assistant::tool_call` — the arguments an agent passes into a tool. - `tool::content` — the content a tool returns to the agent. - `tool_definition::content` — the tool definitions you expose to the model. Only valid for the `prompt_attack` detector.
  - Allowed values: `user::content`, `assistant::content`, `assistant::tool_call`, `tool::content`, `tool_definition::content`
- `allowed_domains` (list of string, optional, nullable) — A list of trusted domains that should not be flagged by the `unknown_links` detector. Only applicable when `type` is `unknown_links`. Include only the domain name and top-level domain (e.g. "example.com"). Do not include prefixes like "http://" or "www.", or subdomains like "platform.example.com".
- `override_list` (list of string, optional, nullable) — A list of strings to allow or deny, used to override model flagging decisions. Required when `type` is `override_allow` or `override_deny`, and not applicable to other types. `override_allow` prevents matching content from being flagged; `override_deny` forces matching content to be flagged.
- `tool_access_action` (enum, optional, nullable) — Whether `tool_access_list` is an allow list or a deny list. Required when `type` is `tool_access_control`, and not applicable to other types.
  - Allowed values: `allow`, `deny`
- `tool_access_list` (list of string, optional, nullable) — The tool names to allow or deny, per `tool_access_action`. Required when `type` is `tool_access_control`, and not applicable to other types.
- `allowed_tools` (list of DetectorConfigAllowedToolsItems, optional, nullable) — Tool definitions that the `prompt_attack` detector should not flag when screening `tool_definition::content`. Only applicable when `type` is `prompt_attack`. Each entry must be unique on (`tool_name`, `tool_matcher`).

### CustomGuardrailEntry

A custom guardrail attached to a policy

- `id` (string, required) — The ID of the custom guardrail
- `locations` (list of enum, optional) — The conversation locations this guardrail screens. Defaults to `user::content` and `assistant::content`.
  - Allowed values: `user::content`, `assistant::content`, `assistant::tool_call`, `tool::content`, `tool_definition::content`

### PolicyProjectBrief

A lightweight reference to a project that uses a policy

- `id` (string, optional) — The ID of the project
- `name` (string, optional) — The name of the project
- `action` (enum, optional) — The project's mode. See [Project Mode](/docs/projects#project-mode).
  - Allowed values: `detect`, `enforce`

### DetectorConfigAllowedToolsItems

- `tool_name` (string, required) — The name of the tool.
- `tool_matcher` (string, required) — The tool definition this entry allows. An entry matches only when both the name and the definition match.

## Examples

**Response**

```json
{
  "policy": {
    "policy_id": "policy-123456-random-g74j7",
    "version_id": 3,
    "name": "string",
    "default_threshold": "l1_confident",
    "detectors": [
      {
        "type": "prompt_attack",
        "location": "user::content",
        "allowed_domains": [
          "my-trusted-domain.com",
          "another-safe-domain.com"
        ],
        "override_list": [
          "deny_list_item1",
          "deny_list_item2"
        ],
        "tool_access_action": "allow",
        "tool_access_list": [
          "get_weather"
        ],
        "allowed_tools": [
          {
            "tool_name": "string",
            "tool_matcher": "string"
          }
        ]
      }
    ],
    "custom_guardrails": [
      {
        "id": "custom-guardrail-123456-random-g74j7",
        "locations": [
          "user::content"
        ]
      }
    ],
    "updated_at": "2024-01-15T09:30:00Z",
    "projects": [
      {
        "id": "string",
        "name": "string",
        "action": "detect"
      }
    ]
  }
}
```

**SDK Code**

```python
import requests

url = "https://platform.lakera.ai/api/v1/policies/policy-123456-random-g74j7"

headers = {"Authorization": "Bearer <token>"}

response = requests.get(url, headers=headers)

print(response.json())
```

```javascript
const url = 'https://platform.lakera.ai/api/v1/policies/policy-123456-random-g74j7';
const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};

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 := "https://platform.lakera.ai/api/v1/policies/policy-123456-random-g74j7"

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

	req.Header.Add("Authorization", "Bearer <token>")

	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("https://platform.lakera.ai/api/v1/policies/policy-123456-random-g74j7")

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

request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'

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("https://platform.lakera.ai/api/v1/policies/policy-123456-random-g74j7")
  .header("Authorization", "Bearer <token>")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('GET', 'https://platform.lakera.ai/api/v1/policies/policy-123456-random-g74j7', [
  'headers' => [
    'Authorization' => 'Bearer <token>',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://platform.lakera.ai/api/v1/policies/policy-123456-random-g74j7");
var request = new RestRequest(Method.GET);
request.AddHeader("Authorization", "Bearer <token>");
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["Authorization": "Bearer <token>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://platform.lakera.ai/api/v1/policies/policy-123456-random-g74j7")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "GET"
request.allHTTPHeaderFields = headers

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