Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions core/schemas/bifrost.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ const (
BifrostContextKeyURLPath BifrostContextKey = "bifrost-extra-url-path" // string
BifrostContextKeyUseRawRequestBody BifrostContextKey = "bifrost-use-raw-request-body"
BifrostContextKeyRawRequestBodyTextRewriter BifrostContextKey = "bifrost-raw-request-body-text-rewriter" // RawRequestBodyTextRewriter (set by native integrations because raw passthrough bypasses normalized runtime redaction)
BifrostContextKeyRawRequestBodyTextTransformer BifrostContextKey = "bifrost-raw-request-body-text-transformer" // RawRequestBodyTextTransformer (set by native integrations for exact provider-managed transformations)
BifrostContextKeyRawResponseTextTransformer BifrostContextKey = "bifrost-raw-response-text-transformer" // RawResponseTextTransformer (set by native integrations that forward a native non-stream response)
BifrostContextKeyRawStreamTextCodec BifrostContextKey = "bifrost-raw-stream-text-codec" // RawStreamTextCodec (set by native integrations whose client response forwards provider-native stream events)
BifrostContextKeyChangeRequestType BifrostContextKey = "bifrost-change-request-type" // RequestType (set by plugins to trigger request type conversion in core, e.g. text->chat or chat->responses)
BifrostContextKeySendBackRawRequest BifrostContextKey = "bifrost-send-back-raw-request" // bool (per-request override — read by bifrost.go, never overwritten)
Expand Down
31 changes: 31 additions & 0 deletions core/schemas/redaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package schemas
import (
"maps"
"sort"
"strconv"
"strings"
)

Expand All @@ -12,6 +13,36 @@ import (
// slice because implementations may mutate the input in place; any rewrite error is unsafe to forward.
type RawRequestBodyTextRewriter func(rawBody []byte, replacements map[string]string) ([]byte, error)

// TextTargetID identifies one integration-owned text field that mirrors normalized guardrail content.
// It is opaque outside the integration/guardrail boundary so callers cannot infer native JSON paths
// or replace a similarly-valued field by accident.
type TextTargetID string

// TextTargetIDForIndex returns the stable identifier for one guardrail-visible text row.
// Native integrations and guardrail extraction use the same row order only within one request or response phase.
func TextTargetIDForIndex(index int) TextTargetID {
return TextTargetID(strconv.Itoa(index))
}

// TextRewrite replaces one exact guardrail-visible text field after its original value is verified.
// Unlike literal redaction maps, repeated originals may have distinct replacements because TargetID
// identifies the field rather than its content.
type TextRewrite struct {
TargetID TextTargetID
Original string
Replacement string
}

// RawRequestBodyTextTransformer synchronizes exact provider-managed transformations into provider-native JSON.
// Integrations must verify TargetID ownership and Original before returning a body; a rewrite error is unsafe to
// forward because raw passthrough would otherwise retain the untransformed value.
type RawRequestBodyTextTransformer func(rawBody []byte, rewrites []TextRewrite) ([]byte, error)

// RawResponseTextTransformer synchronizes exact provider-managed transformations into a native client response.
// Integrations preserve the concrete raw response type and may rewrite only fields they own; errors must prevent
// forwarding the original native response when its normalized counterpart has changed.
type RawResponseTextTransformer func(rawResponse any, rewrites []TextRewrite) (any, error)

// RawStreamTextEvent identifies guardrail-visible text carried by one provider-native stream event.
type RawStreamTextEvent struct {
TargetID string
Expand Down
3 changes: 3 additions & 0 deletions core/schemas/responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -3831,6 +3831,8 @@ type BifrostResponsesStreamResponse struct {
Refusal *string `json:"refusal,omitempty"`

Arguments *string `json:"arguments,omitempty"`
// Input carries the full custom-tool payload on custom_tool_call_input.done.
Input *string `json:"input,omitempty"`

PartialImageB64 *string `json:"partial_image_b64,omitempty"`
PartialImageIndex *int `json:"partial_image_index,omitempty"`
Expand Down Expand Up @@ -3914,6 +3916,7 @@ func (resp *BifrostResponsesStreamResponse) WithDefaults() *BifrostResponsesStre
result.Text = resp.Text
result.Refusal = resp.Refusal
result.Arguments = resp.Arguments
result.Input = resp.Input
result.PartialImageB64 = resp.PartialImageB64
result.PartialImageIndex = resp.PartialImageIndex
result.Annotation = resp.Annotation
Expand Down
46 changes: 46 additions & 0 deletions core/schemas/responses_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -856,3 +856,49 @@ func TestStreamWithDefaultsStripsCodeExecutionCarry(t *testing.T) {
}
}
}

// TestCustomToolInputDoneRoundTrip preserves the terminal input clients compare with streamed custom-tool deltas.
func TestCustomToolInputDoneRoundTrip(t *testing.T) {
raw := []byte(`{"type":"response.custom_tool_call_input.done","item_id":"tool1","output_index":0,"input":"grep alice@example.com"}`)
var response BifrostResponsesStreamResponse
if err := Unmarshal(raw, &response); err != nil {
t.Fatal(err)
}
output, err := json.Marshal(response.WithDefaults())
if err != nil {
t.Fatal(err)
}
var fields map[string]any
if err := json.Unmarshal(output, &fields); err != nil {
t.Fatal(err)
}
if fields["input"] != "grep alice@example.com" {
t.Fatalf("terminal input lost: %s", output)
}
}

// TestDeepCopyResponsesMessageCustomInput preserves custom input without sharing mutable tool state.
func TestDeepCopyResponsesMessageCustomInput(t *testing.T) {
for _, input := range []string{"", "grep alice@example.com"} {
t.Run(input, func(t *testing.T) {
original := ResponsesMessage{
Type: Ptr(ResponsesMessageTypeCustomToolCall),
ResponsesToolMessage: &ResponsesToolMessage{
Name: Ptr("bash"),
ResponsesCustomToolCall: &ResponsesCustomToolCall{Input: input},
},
}
copied := DeepCopyResponsesMessage(original)
if copied.ResponsesToolMessage == nil || copied.ResponsesCustomToolCall == nil {
t.Fatal("copy lost custom tool input")
}
if copied.ResponsesCustomToolCall.Input != input {
t.Fatalf("input = %q, want %q", copied.ResponsesCustomToolCall.Input, input)
}
copied.ResponsesCustomToolCall.Input = "redacted"
if original.ResponsesCustomToolCall.Input != input {
t.Fatal("changing copied input mutated the original")
}
})
}
}
5 changes: 5 additions & 0 deletions core/schemas/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -1373,6 +1373,11 @@ func DeepCopyResponsesMessage(original ResponsesMessage) ResponsesMessage {
copy.ResponsesToolMessage.Arguments = &copyArguments
}

if original.ResponsesToolMessage.ResponsesCustomToolCall != nil {
copyCustomToolCall := *original.ResponsesToolMessage.ResponsesCustomToolCall
copy.ResponsesToolMessage.ResponsesCustomToolCall = &copyCustomToolCall
}

if original.ResponsesToolMessage.Namespace != nil {
copyNamespace := *original.ResponsesToolMessage.Namespace
copy.ResponsesToolMessage.Namespace = &copyNamespace
Expand Down
41 changes: 40 additions & 1 deletion docs/deployment-guides/config-json/guardrails.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,35 @@ Calls Repello Argus prompt and response analysis endpoints. The configured Argus

`base_url` is optional and defaults to `https://argusapi.repello.ai/sdk/v1`. Repello `blocked` verdicts intervene, while `flagged` verdicts are recorded and allowed. See [Repello Argus](/integrations/guardrails/repello-argus) for setup, streaming behavior, and supported content.

</Tab>
<Tab title="Singulr AI">

Calls Singulr AI's Bifrost guardrail endpoint. The Singulr policy decides whether content is allowed, blocked, or redacted. For a `redact` decision, Bifrost validates Singulr's spans and applies fixed runtime replacement.

```json
{
"guardrails_config": {
"guardrail_providers": [
{
"id": 9,
"provider_name": "singulr-ai",
"policy_name": "singulr-ai-production",
"enabled": true,
"timeout": 30,
"config": {
"api_key": "env.SINGULR_API_KEY",
"application_id": "[APPLICATION_ID]",
"guardrail_id": "guardrail-1234567890",
"base_url": "env.SINGULR_BASE_URL"
}
}
]
}
}
```

`base_url` is optional and defaults to `https://dev-app6.ai-platform.singulr.ai`. Bifrost appends `/api/v1/ai-gateway/bifrost`; set `base_url` only when Singulr provides a different API root. See [Singulr AI](/integrations/guardrails/singulr-ai) for setup, streaming behavior, and supported content.

</Tab>
</Tabs>

Expand All @@ -493,7 +522,7 @@ Calls Repello Argus prompt and response analysis endpoints. The configured Argus
| Field | Required | Description |
|-------|----------|-------------|
| `id` | Yes | Unique integer ID - referenced by rules via `provider_config_ids` |
| `provider_name` | Yes | Backend: `"regex"`, `"secrets"`, `"prompt-guardrail"`, `"presidio"`, `"azure-pii"`, `"bedrock"`, `"azure"`, `"model-armor"`, `"crowdstrike-aidr"`, `"patronus-ai"`, `"grayswan"`, `"lakera"`, `"repelloai-argus"` |
| `provider_name` | Yes | Backend: `"regex"`, `"secrets"`, `"prompt-guardrail"`, `"presidio"`, `"azure-pii"`, `"bedrock"`, `"azure"`, `"model-armor"`, `"crowdstrike-aidr"`, `"patronus-ai"`, `"grayswan"`, `"lakera"`, `"repelloai-argus"`, `"singulr-ai"` |
| `policy_name` | Yes | Human-readable policy label |
| `enabled` | Yes | `true` to activate |
| `timeout` | No | Execution timeout in seconds |
Expand Down Expand Up @@ -648,6 +677,16 @@ Any field marked **env.\* supported** accepts a bare `"env.VAR_NAME"` string in
| `base_url` | No | Yes | Argus SDK API base URL. Defaults to `https://argusapi.repello.ai/sdk/v1` |
| `timeout` | No | **Plain only** | Provider execution timeout in seconds |

### Singulr AI

| Field | Required | env.* supported | Notes |
|-------|----------|-----------------|-------|
| `api_key` | Yes | Yes | Singulr API key |
| `application_id` | Yes | **Plain only** | Complete Application ID supplied by Singulr |
| `guardrail_id` | Yes | **Plain only** | Singulr guardrail configuration ID |
| `base_url` | No | Yes | Singulr API root. Defaults to `https://dev-app6.ai-platform.singulr.ai` |
| `timeout` | No | **Plain only** | Provider execution timeout in seconds |

### Regex

| Field | Required | env.\* supported | Notes |
Expand Down
33 changes: 33 additions & 0 deletions docs/deployment-guides/helm/guardrails.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,29 @@ bifrost:

`base_url` is optional and defaults to `https://argusapi.repello.ai/sdk/v1`. Repello `blocked` verdicts intervene, while `flagged` verdicts are recorded and allowed. See [Repello Argus](/integrations/guardrails/repello-argus) for setup, streaming behavior, and supported content.

</Tab>
<Tab title="Singulr AI">

Calls Singulr AI's Bifrost guardrail endpoint. The Singulr policy decides whether content is allowed, blocked, or redacted. For a `redact` decision, Bifrost validates Singulr's spans and applies fixed runtime replacement.

```yaml
bifrost:
guardrails:
providers:
- id: 9
provider_name: "singulr-ai"
policy_name: "singulr-ai-production"
enabled: true
timeout: 30
config:
api_key: "env.SINGULR_API_KEY"
application_id: "[APPLICATION_ID]"
guardrail_id: "guardrail-1234567890"
base_url: "env.SINGULR_BASE_URL"
```

`base_url` is optional and defaults to `https://dev-app6.ai-platform.singulr.ai`. Bifrost appends `/api/v1/ai-gateway/bifrost`; set `base_url` only when Singulr provides a different API root. See [Singulr AI](/integrations/guardrails/singulr-ai) for setup, streaming behavior, and supported content.

</Tab>
</Tabs>

Expand Down Expand Up @@ -547,6 +570,16 @@ Any field marked **env.\* supported** below accepts a bare `"env.VAR_NAME"` stri
| `base_url` | No | Yes | Argus SDK API base URL. Defaults to `https://argusapi.repello.ai/sdk/v1` |
| `timeout` | No | **Plain only** | Provider execution timeout in seconds |

### Singulr AI

| Field | Required | env.* supported | Notes |
|-------|----------|-----------------|-------|
| `api_key` | Yes | Yes | Singulr API key |
| `application_id` | Yes | **Plain only** | Complete Application ID supplied by Singulr |
| `guardrail_id` | Yes | **Plain only** | Singulr guardrail configuration ID |
| `base_url` | No | Yes | Singulr API root. Defaults to `https://dev-app6.ai-platform.singulr.ai` |
| `timeout` | No | **Plain only** | Provider execution timeout in seconds |

### Regex

| Field | Required | env.\* supported | Notes |
Expand Down
6 changes: 4 additions & 2 deletions docs/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,8 @@
"integrations/guardrails/grayswan",
"integrations/guardrails/patronus-ai",
"integrations/guardrails/checkpoint",
"integrations/guardrails/repello-argus"
"integrations/guardrails/repello-argus",
"integrations/guardrails/singulr-ai"
]
}
]
Expand Down Expand Up @@ -603,7 +604,8 @@
"integrations/guardrails/grayswan",
"integrations/guardrails/patronus-ai",
"integrations/guardrails/checkpoint",
"integrations/guardrails/repello-argus"
"integrations/guardrails/repello-argus",
"integrations/guardrails/singulr-ai"
]
},
{
Expand Down
13 changes: 8 additions & 5 deletions docs/enterprise/guardrails.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: "Overview"
description: "Enterprise-grade content safety and security validation with Prompt Guardrails, native regex, secrets detection, Presidio, Azure AI Language PII, AWS Bedrock Guardrails, Azure Content Safety, Google Model Armor, CrowdStrike AIDR, Gray Swan Cygnal, Patronus AI, Check Point's AI Agent Security, and Repello Argus."
description: "Enterprise-grade content safety and security validation with Prompt Guardrails, native regex, secrets detection, Presidio, Azure AI Language PII, AWS Bedrock Guardrails, Azure Content Safety, Google Model Armor, CrowdStrike AIDR, Gray Swan Cygnal, Patronus AI, Check Point's AI Agent Security, Repello Argus, and Singulr AI."
icon: "road-barrier"
---

Expand Down Expand Up @@ -54,6 +54,9 @@ icon: "road-barrier"
<Card title="Repello Argus" icon="/media/repello-argus-logo-card.svg" href="/integrations/guardrails/repello-argus">
Asset-defined AI security policies for prompt injection, sensitive data, unsafe content, and policy violations.
</Card>
<Card title="Singulr AI" icon="/media/singulr-logo-card.svg" href="/integrations/guardrails/singulr-ai">
Policy-driven prompt-injection, PII, and PHI enforcement with allow, block, and span-based redaction decisions.
</Card>
</CardGroup>

### Core Concepts
Expand All @@ -63,7 +66,7 @@ Bifrost Guardrails are built around two core concepts that work together to prov
| Concept | Description |
|---------|-------------|
| **Rules** | Custom policies defined using CEL (Common Expression Language) that determine which LLM requests or MCP tool executions to validate and when. Rules can apply to inputs, outputs, or both, and can be linked to one or more profiles for evaluation. |
| **Profiles** | Configurations for guardrail providers, including Bifrost-managed providers (Prompt Guardrails, Custom Regex, Secrets Detection) and external providers (Presidio, Azure AI Language PII, AWS Bedrock, Azure Content Safety, Google Model Armor, CrowdStrike AIDR, Gray Swan, Patronus AI, Check Point's AI Agent Security, and Repello Argus). Profiles are reusable and can be shared across multiple rules. |
| **Profiles** | Configurations for guardrail providers, including Bifrost-managed providers (Prompt Guardrails, Custom Regex, Secrets Detection) and external providers (Presidio, Azure AI Language PII, AWS Bedrock, Azure Content Safety, Google Model Armor, CrowdStrike AIDR, Gray Swan, Patronus AI, Check Point's AI Agent Security, Repello Argus, and Singulr AI). Profiles are reusable and can be shared across multiple rules. |

**How They Work Together:**
- **Profiles** define *how* content is evaluated using native Bifrost checks or external provider capabilities
Expand All @@ -75,7 +78,7 @@ Bifrost Guardrails are built around two core concepts that work together to prov

| Feature | Description |
|---------|-------------|
| **Multi-Provider Support** | Bifrost-managed Prompt Guardrails, Custom Regex, and Secrets Detection, plus Presidio, Azure AI Language PII, AWS Bedrock, Azure Content Safety, Google Model Armor, CrowdStrike AIDR, Gray Swan, Patronus AI, Check Point's AI Agent Security, and Repello Argus integrations |
| **Multi-Provider Support** | Bifrost-managed Prompt Guardrails, Custom Regex, and Secrets Detection, plus Presidio, Azure AI Language PII, AWS Bedrock, Azure Content Safety, Google Model Armor, CrowdStrike AIDR, Gray Swan, Patronus AI, Check Point's AI Agent Security, Repello Argus, and Singulr AI integrations |
| **Dual-Stage Validation** | Guard LLM prompts and responses or MCP tool arguments and results |
| **Real-Time Processing** | Synchronous and asynchronous validation modes |
| **CEL-Based Rules** | Define custom policies using Common Expression Language |
Expand Down Expand Up @@ -534,7 +537,7 @@ Profiles are reusable configurations for guardrail providers. External providers
| Property | Type | Required | Description |
|----------|------|----------|-------------|
| `id` | integer | Yes | Unique identifier for the profile |
| `provider_name` | string | Yes | Provider type: `regex`, `secrets`, `prompt-guardrail`, `presidio`, `azure-pii`, `bedrock`, `azure`, `model-armor`, `crowdstrike-aidr`, `grayswan`, `patronus-ai`, `lakera`, or `repelloai-argus` |
| `provider_name` | string | Yes | Provider type: `regex`, `secrets`, `prompt-guardrail`, `presidio`, `azure-pii`, `bedrock`, `azure`, `model-armor`, `crowdstrike-aidr`, `grayswan`, `patronus-ai`, `lakera`, `repelloai-argus`, or `singulr-ai` |
| `policy_name` | string | Yes | Descriptive name for the policy |
| `enabled` | boolean | Yes | Whether the profile is active |
| `config` | object | No | Provider-specific configuration |
Expand Down Expand Up @@ -567,7 +570,7 @@ Profiles are reusable configurations for guardrail providers. External providers
</Tab>
<Tab title="API">

Profiles are managed per provider type at `/api/guardrails/{provider}`, where `{provider}` is one of `secrets`, `regex`, `prompt-guardrail`, `presidio`, `azure-pii`, `bedrock`, `azure`, `model-armor`, `crowdstrike-aidr`, `grayswan`, `patronus-ai`, `lakera`, or `repelloai-argus`. The API assigns the configuration ID after creation.
Profiles are managed per provider type at `/api/guardrails/{provider}`, where `{provider}` is one of `secrets`, `regex`, `prompt-guardrail`, `presidio`, `azure-pii`, `bedrock`, `azure`, `model-armor`, `crowdstrike-aidr`, `grayswan`, `patronus-ai`, `lakera`, `repelloai-argus`, or `singulr-ai`. The API assigns the configuration ID after creation.

**Create a Profile:**
```bash
Expand Down
Loading
Loading