1. Home
  2. Documentation
  3. AI Gateway
  4. Policies

Policies

Apply guardrails, prompt enrichment, and rate limiting to a route.

The Policies module defines what AI Gateway does with each request that reaches a route before forwarding it to the LLM Provider, and what it does with the returned response. Each policy is linked to a single route and combines three optional blocks: Prompt Guard (filtering by moderation or regex), Prompt Enrichment (messages injected before the prompt), and Rate Limit (quotas by requests or tokens).

IMPORTANT

You must configure at least one section to save the policy. The form lets you combine Prompt Guard (Request), Prompt Guard (Response), Prompt Enrichment, and Rate Limit in any arrangement, but at least one must be filled in.

Learn how to:

Listing

The Policies page lists registered policies with pagination. You can filter by:

  • Route (optional): route associated with the policy.

Use Search to apply the filter and Clear to reset it.

Columns shown in the table:

  • Route: associated route.
  • Configured sections: indicates which sections are configured (Prompt Guard / Prompt Enrichment / Rate Limit).
  • Created At: creation date and time.
  • Actions: View and Delete icons for each row.

View Policy

In the Actions column of the row you want, click the View icon. The Policy details screen opens in read-only mode, showing:

  • Route, Configured sections, and Created At at the top of the card, before the sections.
  • Below that, only the sections actually configured on that policy โ€” Prompt Guard (Request), Prompt Guard (Response), Prompt Enrichment, and Rate Limit โ€” each with the same labels used in the form. A section that is not configured does not appear on the screen.

No field is editable on this screen. To change the policy, click the Edit button in the card header โ€” see Edit Policy.

Create Policy

Step 1

On the Policies page, click Create Policy.

Step 2

Select the target Route. This field is a searchable select. Type part of the endpoint to filter.

Step 3

Fill in at least one of the four optional sections: Prompt Guard (Request), Prompt Guard (Response), Prompt Enrichment, or Rate Limit. Each section has its own required-field rules. See the subsections below.

Step 4

Click Save to confirm the registration. To discard the operation, click Cancel.

Edit Policy

Open the policy you want (see View Policy) and, on the Policy details screen, click the Edit button in the card header. The Update Policy form opens with the current data. Change the required fields and click Save.

Delete Policy

In the Actions column of the row you want, click the Delete icon. Confirm the operation in the "Do you want to delete policy [policyId]?" dialog.

IMPORTANT

Deletion is permanent and cannot be undone. Deleting a policy makes the associated route accept requests without guardrails, prompt enrichment, or rate limiting.

Required field

Field
Type
Required
Rules
RouteSearchable selectYesLists registered routes.

Prompt Guard (Request)

This optional block validates the request before it reaches the LLM provider. It combines three subfeatures: moderation, regex, and custom response.

MODERATION AND REGEX CAN BE COMBINED

Moderation and regex can be used together in the same Prompt Guard Request. Filling in one does not disable the other: when both are configured, the request must pass both checks, and the same custom response applies to whichever one blocks it.

Fields: Moderation subblock

Field
Type
Required
Rules
Moderation modelSelectConditional: required when Moderation API Key is providedOnly value currently available: omni-moderation-latest (OpenAI moderation model).
Moderation API KeySelectConditional: required when Moderation model is providedLists registered API Keys, displayed by the key's Description followed by the provider in parentheses. A key with no Description is displayed by its identifier.

Fields: Regex subblock

Field
Type
Required
Rules
Regex actionSelectConditional: required when Regex patterns have at least one patternValues: Reject, Mask.
Regex patternsList of tagsConditional: required when Regex action is providedList of regular expressions.

Fields: Custom response subblock

Custom response returned when the request is rejected by moderation or regex.

Field
Type
Required
Rules
Custom response messageTextConditional: see the rules belowMinimum 1 character.
Custom response status codeIntegerConditional: see the rules belowBetween 200 and 599.

The two fields are always filled in together: providing one makes the other required. In addition, the whole Custom response pair becomes required when:

  • the Moderation subblock is configured; or
  • the Regex action is Reject.
WHEN THE CUSTOM RESPONSE IS OPTIONAL

The Custom response pair is optional only when the Prompt Guard Request is limited to a regex with Regex action = Mask, without moderation. In that case the content is masked and the request continues to the provider, so there is no blocking response to return.

Prompt Guard (Response)

This optional block validates the response returned by the provider before returning it to the requester. There is no moderation here, only regex and custom response, with the same pairing logic as the request.

STREAMING RESPONSES

For now, only responses returned without streaming are masked by the expressions configured in this section.

Fields: Regex subblock (response)

Field
Type
Required
Rules
Response regex actionSelectConditional: required when Response regex patterns has at least one patternValues: Reject, Mask.
Response regex patternsList of tagsConditional: required when Response regex action is providedList of regular expressions applied to the returned content.

Fields: Custom response subblock (response)

Field
Type
Required
Rules
Response custom messageTextConditional: required when Response custom status code is provided or when Response regex action = RejectMinimum 1 character.
Response custom status codeIntegerConditional: required when Response custom message is provided or when Response regex action = RejectBetween 200 and 599.

Prompt Enrichment

This block is optional as a section, but has required internal rules when enabled. When you add at least one message, you must provide at least one complete entry (role + content). Messages are prepended to the original prompt in the order they appear in the list.

Use Add message to add a new Message entry and the delete icon to remove entries.

Fields by message

Field
Type
Required
Rules
RoleSelectYes (per message)Available values: system and developer.
ContentLong text (textarea)Yes (per message)Minimum 1 character.
AVAILABLE ROLES

system and developer are the only selectable roles. They are the ones that make sense for instructions prepended to the prompt. If a policy shows a different role when opened for editing, the form flags it with the message This role is no longer supported. Select "system" or "developer". and requires the change before saving.

Rate Limit

This optional block limits consumption by time window. When enabled, it requires you to choose exactly one limit type: requests or tokens.

MUTUAL EXCLUSION

The policy cannot include requestCount and tokenCount at the same time. Choose one of them.

The screen shows a Rate limit type selector with Tokens and Requests buttons that determine which format is used.

Fields

Field
Type
Required
Rules
Rate limit typeToggle (Tokens / Requests buttons)Conditional: required when Rate Limit is enabledChoose Tokens or Requests. Mutually exclusive.
Rate limit valueIntegerConditional: required when a Rate limit type is selectedPositive integer.
Time unitSelectConditional: required when Rate Limit is enabledValues: Seconds, Minutes, Hours.

Permissions

Access to each action in the Policies journey depends on its own permission. Without the corresponding permission, the screen element does not appear โ€” the interface never shows an unavailable action as disabled.

Permissions are granted in Access Control, on the Roles screen, under the AI Gateway product. The table below lists each one exactly as Access Control displays it.

Permission
Group in AC
Description in AC
Identifier
List PoliciespoliciesAllows listing Policiesai-gateway.policies.list
View PolicypoliciesAllows viewing a Policyai-gateway.policies.view
Create and Update PoliciespoliciesAllows creating and editing Policiesai-gateway.policies.create-update
Delete PoliciespoliciesAllows deleting Policiesai-gateway.policies.delete
List RoutesroutesAllows listing Routesai-gateway.routes.list
View API Keyapi-keysAllows viewing an API Keyai-gateway.api-keys.view

The last two belong to other journeys and are required by specific Policies actions, shown in the next table.

Action
What it unlocks
Required permissions
ListPolicies item in the sidebar menu; listing with table and paginationList Policies
Filter by RouteRoute filter field on the listing (the screen's only filter)List Policies + List Routes
ViewView icon on the row and the Policy details screenList Policies + View Policy
CreateCreate Policy buttonList Policies + Create and Update Policies + List Routes
EditEdit button inside Policy detailsList Policies + View Policy + Create and Update Policies + List Routes
DeleteDelete icon on the rowList Policies + Delete Policies

View: the Moderation API Key's (provider) suffix additionally requires View API Key. Without it, the field shows only the bare id.

Create and Edit: List Routes is what feeds the form's Route field with the available routes.

EDITING REQUIRES VIEWING

The Edit button only exists inside the Policy details screen. Because of that, a user holding Create and Update Policies but not View Policy has no path to edit an existing policy. This is expected platform behavior, not a bug.

How happy are you with this page?

We use cookies to enhance your experience on our site. By continuing to browse, you agree to our use of cookies.Learn more