> This page is for Gateway.

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

# Update Organization PI Settings

PUT https://api-gateway.merge.dev/v1/organization/pi-settings
Content-Type: application/json

Replace the organization's prompt injection policy as a whole: a field
you omit takes its default.

Reference: https://docs.merge.dev/merge-gateway/management-api/security-rules/update-organization-pi-settings

## Authentication

- `Authorization` header (bearer token, required) — A management key (`mgmt_...`), sent as `Authorization: Bearer <key>`. Reading /v1/routing-policies also accepts the organization's gateway API keys; writing there needs a management key.

## Request

### Body (application/json)

This endpoint expects an OrganizationPISettingsV1.

- `pi_allowlist_patterns` (list of string, optional) — Regular expressions whose matching prompt segments skip screening. A project's patterns add to the organization's, never replacing them. A pattern that matches ordinary text, such as `.*`, is ignored.
- `pi_block_threshold` (double, optional, default: 0.57) — Direct injection: a prompt segment is blocked when its score, from 0 to 1, reaches this value. At least the organization's `pi_pass_threshold`.
- `pi_fail_closed` (boolean, optional, default: false) — Reject requests, with `code: "sidecar_error"`, when screening is unavailable. false lets them through unscreened.
- `pi_indirect_mode` (enum, optional, default: off) — Indirect injection, in tool results and documents: `off`, `alert` or `block`. A separate axis from `pi_mode`.
  - Allowed values: `off`, `alert`, `block`
- `pi_input_action` (enum, optional, default: block) — Reserved: requests are screened as `pi_mode` says.
  - Allowed values: `observe`, `redact`, `route`, `block`, `escalate`
- `pi_log_full_text_on_block` (boolean, optional, default: false) — Log the full text of blocked prompts.
- `pi_mode` (enum, optional, default: off) — Direct injection, in the prompt a user sends: `off`, `alert` (score and record, never block) or `block`.
  - Allowed values: `off`, `alert`, `block`
- `pi_output_action` (enum, optional, default: redact) — What the response-side check does with a leaked credential, such as an API key: `redact` replaces it with a placeholder, `observe` only records it. Other values behave like `observe`.
  - Allowed values: `observe`, `redact`, `route`, `block`, `escalate`
- `pi_pass_threshold` (double, optional, default: 0.3) — Reserved: no effect on screening yet. At most `pi_block_threshold`.
- `pi_safer_vendor_route` (string, optional, nullable) — Reserved for a future `route` action.
- `pi_tier2a_block_threshold` (double, optional, default: 0.6) — Indirect injection: the score, from 0 to 1, at which the heuristic signal fires.
- `pi_tier2b_block_threshold` (double, optional, default: 0.45) — Indirect injection: the score, from 0 to 1, at which the similarity-to-known-attacks signal fires.

## Response

### 200

The updated prompt injection settings

- `pi_allowlist_patterns` (list of string, required) — Regular expressions whose matching prompt segments skip screening. A project's patterns add to the organization's, never replacing them. A pattern that matches ordinary text, such as `.*`, is ignored.
- `pi_block_threshold` (double, required, default: 0.57) — Direct injection: a prompt segment is blocked when its score, from 0 to 1, reaches this value. At least the organization's `pi_pass_threshold`.
- `pi_fail_closed` (boolean, required, default: false) — Reject requests, with `code: "sidecar_error"`, when screening is unavailable. false lets them through unscreened.
- `pi_indirect_mode` (enum, required, default: off) — Indirect injection, in tool results and documents: `off`, `alert` or `block`. A separate axis from `pi_mode`.
  - Allowed values: `off`, `alert`, `block`
- `pi_input_action` (enum, required, default: block) — Reserved: requests are screened as `pi_mode` says.
  - Allowed values: `observe`, `redact`, `route`, `block`, `escalate`
- `pi_log_full_text_on_block` (boolean, required, default: false) — Log the full text of blocked prompts.
- `pi_mode` (enum, required, default: off) — Direct injection, in the prompt a user sends: `off`, `alert` (score and record, never block) or `block`.
  - Allowed values: `off`, `alert`, `block`
- `pi_output_action` (enum, required, default: redact) — What the response-side check does with a leaked credential, such as an API key: `redact` replaces it with a placeholder, `observe` only records it. Other values behave like `observe`.
  - Allowed values: `observe`, `redact`, `route`, `block`, `escalate`
- `pi_pass_threshold` (double, required, default: 0.3) — Reserved: no effect on screening yet. At most `pi_block_threshold`.
- `pi_safer_vendor_route` (string, required, nullable) — Reserved for a future `route` action.
- `pi_tier2a_block_threshold` (double, required, default: 0.6) — Indirect injection: the score, from 0 to 1, at which the heuristic signal fires.
- `pi_tier2b_block_threshold` (double, required, default: 0.45) — Indirect injection: the score, from 0 to 1, at which the similarity-to-known-attacks signal fires.

## Errors

### 401 Unauthorized Error

The key is missing or invalid.

- `detail` (ErrorResponseDetail, required) — A message, or an object with a `code` to branch on and a `message`.

### 403 Forbidden Error

The key lacks the scope this route needs, or the change is not allowed.

- `detail` (ErrorResponseDetail, required) — A message, or an object with a `code` to branch on and a `message`.

### 422 Unprocessable Entity Error

Validation Error

- `detail` (list of ValidationError, optional)

## Types

### ErrorResponseDetail

A message, or an object with a `code` to branch on and a `message`.

### ValidationError

- `loc` (list of ValidationErrorLocItems, required)
- `msg` (string, required)
- `type` (string, required)
- `ctx` (ValidationErrorCtx, optional)
- `input` (any, optional)

### ErrorDetail

A structured error. Some carry extra fields, like `count`.

- `code` (string, required) — A stable code to branch on, like `payment_method_required`.
- `message` (string, required) — A human-readable explanation.

### ValidationErrorLocItems

### ValidationErrorCtx

## Examples

**Request**

```json
{
  "pi_allowlist_patterns": [
    "(?i)ignore the previous ticket"
  ],
  "pi_block_threshold": 0.57,
  "pi_fail_closed": false,
  "pi_indirect_mode": "alert",
  "pi_input_action": "block",
  "pi_log_full_text_on_block": false,
  "pi_mode": "block",
  "pi_output_action": "redact",
  "pi_pass_threshold": 0.3,
  "pi_safer_vendor_route": null,
  "pi_tier2a_block_threshold": 0.6,
  "pi_tier2b_block_threshold": 0.45
}
```

**Response**

```json
{
  "pi_allowlist_patterns": [
    "(?i)ignore the previous ticket"
  ],
  "pi_block_threshold": 0.57,
  "pi_fail_closed": false,
  "pi_indirect_mode": "alert",
  "pi_input_action": "block",
  "pi_log_full_text_on_block": false,
  "pi_mode": "block",
  "pi_output_action": "redact",
  "pi_pass_threshold": 0.3,
  "pi_safer_vendor_route": null,
  "pi_tier2a_block_threshold": 0.6,
  "pi_tier2b_block_threshold": 0.45
}
```

**SDK Code**

```python
import requests

url = "https://api-gateway.merge.dev/v1/organization/pi-settings"

payload = {
    "pi_allowlist_patterns": ["(?i)ignore the previous ticket"],
    "pi_block_threshold": 0.57,
    "pi_fail_closed": False,
    "pi_indirect_mode": "alert",
    "pi_input_action": "block",
    "pi_log_full_text_on_block": False,
    "pi_mode": "block",
    "pi_output_action": "redact",
    "pi_pass_threshold": 0.3,
    "pi_safer_vendor_route": None,
    "pi_tier2a_block_threshold": 0.6,
    "pi_tier2b_block_threshold": 0.45
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript
const url = 'https://api-gateway.merge.dev/v1/organization/pi-settings';
const options = {
  method: 'PUT',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"pi_allowlist_patterns":["(?i)ignore the previous ticket"],"pi_block_threshold":0.57,"pi_fail_closed":false,"pi_indirect_mode":"alert","pi_input_action":"block","pi_log_full_text_on_block":false,"pi_mode":"block","pi_output_action":"redact","pi_pass_threshold":0.3,"pi_safer_vendor_route":null,"pi_tier2a_block_threshold":0.6,"pi_tier2b_block_threshold":0.45}'
};

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 := "https://api-gateway.merge.dev/v1/organization/pi-settings"

	payload := strings.NewReader("{\n  \"pi_allowlist_patterns\": [\n    \"(?i)ignore the previous ticket\"\n  ],\n  \"pi_block_threshold\": 0.57,\n  \"pi_fail_closed\": false,\n  \"pi_indirect_mode\": \"alert\",\n  \"pi_input_action\": \"block\",\n  \"pi_log_full_text_on_block\": false,\n  \"pi_mode\": \"block\",\n  \"pi_output_action\": \"redact\",\n  \"pi_pass_threshold\": 0.3,\n  \"pi_safer_vendor_route\": null,\n  \"pi_tier2a_block_threshold\": 0.6,\n  \"pi_tier2b_block_threshold\": 0.45\n}")

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

	req.Header.Add("Authorization", "Bearer <token>")
	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("https://api-gateway.merge.dev/v1/organization/pi-settings")

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

request = Net::HTTP::Put.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"pi_allowlist_patterns\": [\n    \"(?i)ignore the previous ticket\"\n  ],\n  \"pi_block_threshold\": 0.57,\n  \"pi_fail_closed\": false,\n  \"pi_indirect_mode\": \"alert\",\n  \"pi_input_action\": \"block\",\n  \"pi_log_full_text_on_block\": false,\n  \"pi_mode\": \"block\",\n  \"pi_output_action\": \"redact\",\n  \"pi_pass_threshold\": 0.3,\n  \"pi_safer_vendor_route\": null,\n  \"pi_tier2a_block_threshold\": 0.6,\n  \"pi_tier2b_block_threshold\": 0.45\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.put("https://api-gateway.merge.dev/v1/organization/pi-settings")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"pi_allowlist_patterns\": [\n    \"(?i)ignore the previous ticket\"\n  ],\n  \"pi_block_threshold\": 0.57,\n  \"pi_fail_closed\": false,\n  \"pi_indirect_mode\": \"alert\",\n  \"pi_input_action\": \"block\",\n  \"pi_log_full_text_on_block\": false,\n  \"pi_mode\": \"block\",\n  \"pi_output_action\": \"redact\",\n  \"pi_pass_threshold\": 0.3,\n  \"pi_safer_vendor_route\": null,\n  \"pi_tier2a_block_threshold\": 0.6,\n  \"pi_tier2b_block_threshold\": 0.45\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('PUT', 'https://api-gateway.merge.dev/v1/organization/pi-settings', [
  'body' => '{
  "pi_allowlist_patterns": [
    "(?i)ignore the previous ticket"
  ],
  "pi_block_threshold": 0.57,
  "pi_fail_closed": false,
  "pi_indirect_mode": "alert",
  "pi_input_action": "block",
  "pi_log_full_text_on_block": false,
  "pi_mode": "block",
  "pi_output_action": "redact",
  "pi_pass_threshold": 0.3,
  "pi_safer_vendor_route": null,
  "pi_tier2a_block_threshold": 0.6,
  "pi_tier2b_block_threshold": 0.45
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://api-gateway.merge.dev/v1/organization/pi-settings");
var request = new RestRequest(Method.PUT);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"pi_allowlist_patterns\": [\n    \"(?i)ignore the previous ticket\"\n  ],\n  \"pi_block_threshold\": 0.57,\n  \"pi_fail_closed\": false,\n  \"pi_indirect_mode\": \"alert\",\n  \"pi_input_action\": \"block\",\n  \"pi_log_full_text_on_block\": false,\n  \"pi_mode\": \"block\",\n  \"pi_output_action\": \"redact\",\n  \"pi_pass_threshold\": 0.3,\n  \"pi_safer_vendor_route\": null,\n  \"pi_tier2a_block_threshold\": 0.6,\n  \"pi_tier2b_block_threshold\": 0.45\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "pi_allowlist_patterns": ["(?i)ignore the previous ticket"],
  "pi_block_threshold": 0.57,
  "pi_fail_closed": false,
  "pi_indirect_mode": "alert",
  "pi_input_action": "block",
  "pi_log_full_text_on_block": false,
  "pi_mode": "block",
  "pi_output_action": "redact",
  "pi_pass_threshold": 0.3,
  "pi_safer_vendor_route": ,
  "pi_tier2a_block_threshold": 0.6,
  "pi_tier2b_block_threshold": 0.45
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api-gateway.merge.dev/v1/organization/pi-settings")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "PUT"
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()
```