Setting up OpenAI Guardrails

OpenAI Guardrails

Use Portkey to enforce structured inputs, safe outputs, and usage policies across all OpenAI requests.  Configure verdict actions like async checks, request denial, and feedback logging, according to your enforcement needs.

OpenAI Guardrails

OpenAI powers some of the most advanced language models in the world, including GPT-4, o3, Whisper, and DALL·E. These models are widely used for building applications across chat, summarization, code generation, document understanding, transcription, and multimodal tasks. But running them in production requires model performance, safety, compliance, and control.

Portkey acts as a powerful gateway layer for OpenAI, allowing you to apply customizable guardrails to every request without changing your application code. Whether you're concerned about prompt injection, data redaction, output filtering, or governance, Portkey provides a seamless way to manage and secure AI usage at scale.

With Portkey, you can:

Portkey supports all OpenAI models out of the box and can be deployed in hours, not weeks, making it the easiest way to bring enterprise-grade control to your AI stack.

World-Class Guardrail Partners

Integrate top guardrail platforms with Portkey to run your custom policies seamlessly — from content filtering and PII detection to moderation and compliance. Ensure every AI request is safe, auditable, and aligned with your enterprise standards.

Guardrail checks you can apply to OpenAI

Portkey offers both deterministic and LLM-powered guardrails that work seamlessly with OpenAI’s APIs. You can apply these checks to inputs, outputs, or both.

Input guardrails
Regex Match

Basic

Enforce patterns on input prompts

Sentence / Word / Character Count

Basic

Control verbosity

Lowercase Detection

Basic

Control verbosity

Ends With

Basic

Validate specific prompt endings

Webhook

Basic

Enforce custom business logic

JWT Token Validator

Basic

Verify token authenticity

Model Whitelist

Basic

Allow only approved models per route

Moderate Content

Pro

Block unsafe or harmful prompts

Check Language

Pro

Enforce language constraints

Detect PII

Pro

Prevent sensitive info in prompts

Detect Gibberish

Pro

Block incoherent or low-quality input

Output guardrails
Regex / Sentence / Word / Character Count

Basic

Ensure required words or phrases

JSON Schema / JSON Keys

Basic

Ensure required words or phrases

Contains

Basic

Ensure required words or phrases

Valid URLs

Basic

Validate links in responses

Contains Code

Basic

Detect code in specific formats

Lowercase Detection / Ends With

Basic

Need content here

Webhook

Basic

Post-process or validate output

Detect PII / Detect Gibberish

Basic

Need content here

How to add guardrails to OpenAI with Portkey

Adding Portkey Guardrails in production is just a 4-step process:

1

Create Guardrail Checks

2

Create Guardrail Actions

3

Enable Guardrail through Configs

4

Attach the Config to a Request

Guardrail action settings

Async (TRUE)

Run guardrails in parallel to the request.

→ No added latency. Best for logging-only scenarios.

Async (FALSE)

Run guardrails before request or response.

→ Adds latency. Use when the guardrail result should influence the flow.

Deny Request (TRUE)

Block the request or response if any guardrail fails.

→ Use when violations must stop execution.

Deny Request (FALSE)

Allow the request even if the guardrail fails (returns 246 status).

→ Good for observing without blocking.

Send Feedback on Success/Failure

Attach metadata based on guardrail results.

→ Recommended for tracking and evaluation.

Frequently Asked Questions

Do guardrails add latency to requests?
Can I block a request if a guardrail fails?
What happens if I don’t want to block, just observe?
Are OpenAI Guardrails only for inputs?
What’s the difference between basic and pro guardrails?

Safeguard your OpenAI requests now.

Whether you're building with GPT-4o, running production workloads, or scaling across teams, Portkey’s guardrails give you control without compromise.