Skip to main content

Availability

For how guardrails work, refer to Guardrails. Create a guardrail filter, test it, and then attach it to an LLM, a chat room, or a tool.

Create a Guardrail

  1. Go to Context management > Filters and select Add filter.
  2. In Filter type, select Guardrail.
  3. To check the LLM response instead of the request, select Is this a Response Filter?.
  4. Select a Provider and an On detection action.
  5. Select one or more Detectors.
  6. Set the other fields. The table below describes them.
  7. Use the Test panel to check the guardrail. Refer to Test a Guardrail.
  8. Save the filter. Then attach it to an LLM, a chat room, or a tool.
Guardrail form with the agent traffic, prompt template, and second opinion sections AI Studio validates the configuration when you save it. For example, it rejects an unknown detector, a Redact action on a provider that cannot redact, or a missing required connection field. The error message gives the cause. The form saves only the settings that you change. A filter that you do not change keeps the defaults of the AI Studio version that runs it.

Test a Guardrail

The Test panel on the filter form runs the guardrail against sample text before you save it. The result shows the compliance events and the output. In this example, the built-in pattern library finds a payment card, an email address, and a phone number. It masks all three. Test panel result with three guardrail compliance events for a payment card, an email address, and a phone number For an external provider, the test sends a real call with the connection settings. Use it to check the credentials. If a connection field uses a $SECRET/ or $ENV/ reference, save the filter first. AI Studio resolves references in a test only when the provider and the connection settings are the same as the saved filter. To test a request filter on agent traffic, set Request body format to a vendor format, such as OpenAI chat completions or Anthropic messages. AI Studio then reads the sample as a request body. Select Insert a tool-result sample to add a request with an injection in a tool result. The result shows the source of each event, and the body that AI Studio sends on to the vendor. Test panel with OpenAI chat completions format and a tool-result sample that the guardrail quarantines

Provider Credentials

For a connection field that holds a credential, such as an API key, use a reference instead of the value:
  • $SECRET/name refers to a secret.
  • $ENV/NAME refers to an environment variable. From 2.3.0, AI Studio resolves it only when AI_STUDIO_ENV_REF_ALLOWLIST lists the variable name.
AI Studio resolves the reference when the guardrail runs. Edge Gateways do not have access to the secret store, so AI Studio resolves the references before it pushes the configuration to them. This is the same as for LLM API keys. From 2.3.0, guardrail credentials reach Edge Gateways encrypted. AI Studio keeps a resolved configuration for 30 seconds. A rotated secret takes effect within 30 seconds. A change to the filter takes effect immediately. From 2.3.0, the API does not return a literal credential, such as an api_key or a Bedrock secret_access_key. It returns [redacted] for all roles. When you save the form with [redacted], AI Studio keeps the stored key. References and endpoints show as written.
A user who can edit filters can put any $SECRET/ reference in a connection field and set the endpoint. The gateway then sends the secret value to that endpoint.Give write access to filters and LLMs only to users that you trust with your stored secrets. From 2.3.0, a user must also have permission to read secrets to add a reference to a filter.