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
- Go to Context management > Filters and select Add filter.
- In Filter type, select Guardrail.
- To check the LLM response instead of the request, select Is this a Response Filter?.
- Select a Provider and an On detection action.
- Select one or more Detectors.
- Set the other fields. The table below describes them.
- Use the Test panel to check the guardrail. Refer to Test a Guardrail.
- Save the filter. Then attach it to an LLM, a chat room, or a tool.

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.
$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.

Provider Credentials
For a connection field that holds a credential, such as an API key, use a reference instead of the value:$SECRET/namerefers to a secret.$ENV/NAMErefers to an environment variable. From 2.3.0, AI Studio resolves it only when AI_STUDIO_ENV_REF_ALLOWLIST lists the variable name.
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.