Skip to main content

Guardrails

Guardrails are safety layers that inspect and transform LLM requests and responses in real time.

What guardrails do

Depending on the activated guardrail, the LLM API applies it in two stages:

  1. Pre-call — scans and transforms your input before it reaches the model
  2. Post-call — scans and transforms the model's response before it reaches you

Architecture

Guardrails Architecture

Setup

Guardrails are opt-in per request. No upfront configuration is needed — just add the guardrails parameter to any chat completion call. They are composable, you can pass multiple guardrail names in the request to combine them. Your request/response structure stays the same. Guardrails modify content in-place.

1. Choose a guardrail

List available guardrails for your endpoint:

curl -s "https://llm.api.caip.bmw.cloud/guardrails/list" \
-H "Authorization: Bearer $YOUR_API_KEY" | jq .

2. Add it to your request

Pass the guardrail name(s) in the guardrails array:

curl -X POST 'https://llm.api.caip.bmw.cloud/v1/chat/completions' \
-H "Authorization: Bearer $YOUR_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "gpt-4o",
"messages": [{"role": "user", "content": "Hello world"}],
"guardrails": ["pii-data-masking-en"]
}'

3. Use with OpenAI SDK

Python:

from openai import OpenAI

client = OpenAI(
base_url="https://llm.api.caip.bmw.cloud/v1",
api_key="your-api-key"
)

response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Your message here"}],
extra_body={"guardrails": ["pii-data-masking-en"]}
)

Available guardrails

GuardrailDescriptionLanguagesStage
PII Data MaskingDetects and masks general personally identifiable information (names, emails, credit cards, …). Does not mask VINs.English, Germanpre_call masking, post_call unmasking
VIN MaskingDetects and masks Vehicle Identification Numbers (VINs) onlyEnglish, Germanpre_call masking, post_call unmasking
Composable

Guardrails can be combined. To mask general PII and VINs, request both: "guardrails": ["pii-data-masking-en", "vin-masking-en"].

More guardrails coming soon

We are actively developing additional guardrails (content filtering, topic restriction, etc.). Check this page for updates.

Request a new guardrail

Need a guardrail we don't offer yet? Reach out to the CAIP team for Technical Support or Consulting. Describe your use case and what kind of content you want to detect, block, or transform.

Include the following in your request:

  • What content should be detected (e.g., specific entity types, topics, patterns)
  • Whether it should apply to input, output, or both
  • Whether the action should be mask (replace) or block (reject the request)
  • Which languages need to be supported

API reference

EndpointMethodDescription
/guardrails/listGETReturns all available guardrail names
/v1/chat/completionsPOSTAccepts guardrails array in request body