Configure guardrails before and after a model call
Bind an external policy service to a Group, Provider, or Model and verify both lifecycle stages.
Purpose
Call an external or locally hosted HTTP policy service before provider dispatch, after a non-streaming response, or at both stages.
Relay applies the action that you configure. The policy service supplies the verdict. Relay does not include a built-in moderation classifier.
Prerequisites
Collect the policy service URL, authentication method, request template, verdict mapping, timeout, and failure policy. Decide whether the Guardrail binds to one Group, Provider, or Model.
Create the Guardrail
- Open Guardrails.
- Add a Guardrail.
- Select an editable preset or a custom HTTP service.
- Enter the service URL and authentication settings.
- Select Pre-dispatch, Post-response, or both.
- Map the service response to allowed and blocked verdicts.
- Select the action for a matched rule.
- Select
fail_open,fail_closed, orreturn_errorfor service failures. - Bind the Guardrail to exactly one Group, Provider, or Model.
- Save and enable the Guardrail.
Test before provider dispatch
- Use the explicit Guardrail test action with representative bounded input.
- Send a non-streaming request that matches the configured block rule.
- Open Logs.
A pre-dispatch block must show that the Provider was not called. No provider usage or cost occurs.
Test after the model response
- Enable a post-response rule.
- Send a non-streaming request that produces a matching response.
- Open Logs.
A post-response block withholds or replaces the response. Provider usage and cost remain because the Provider already completed the request.
Streaming boundary
If an effective Guardrail applies, Relay rejects streaming before provider dispatch. The response uses guardrails_require_non_streaming.
Expected result
Relay applies the configured service verdict at the selected stage. A pre-dispatch block prevents provider use. A post-response block retains provider use.
Verification
Confirm the stage, service result, action, failure policy, binding, and final request status in Logs. Guardrail results must not mark the Provider unhealthy or trigger model fallback.
Recovery
If the service fails, inspect its URL, timeout, authentication, template, and verdict mapping. Confirm that the chosen failure policy matches the intended security posture.