Skip to main content

Availability

For how response filters run, refer to Response Filters. Write a script that blocks an LLM response with forbidden content. Then attach it to an LLM or a chat room.

Create a Response Filter

  1. Create a script filter, and select Is this a Response Filter?.
  2. In the script, read the response text. For streaming, use input.current_buffer, the accumulated text. Otherwise, use input.raw_input. For all fields, refer to Response Filter Input.
  3. For streaming, evaluate only when len(input.current_buffer) reaches enough context. The script runs on every chunk, so keep its logic lightweight.
  4. Set output.block and output.message. The user sees the message, so make it clear. A response filter cannot change the response, so AI Studio ignores payload and messages.
  5. Attach the filter to an LLM or a chat room.

Example Scripts

Block Refund Promises

Block Harmful Content

To check the response with a second LLM, start from the Response Guardrails (LLM Check) template. It blocks the response when the check fails.