Skip to content

QA plan: Guardrail intervention response contract (#73)

Story: Guardrail intervention response contract (#73)
Feature: Safety Gate via Bedrock Guardrails (#69)
Capability: Safety (#44)
ADRs: RAG013 — Safety gate via Bedrock Guardrails; RAG005 — OpenAPI spec governance

TypeCoverage
UnitAn input intervention returns HTTP 400 with {"error": "content_policy_violation", "message": <configured message>}; the body is built from the documented InterventionResponse model
UnitAn output intervention returns HTTP 200 with the configured message as answer, empty citations, and reason: content_policy_violation
UnitWith GUARDRAIL_INTERVENTION_MESSAGE set, the message appears in the 400 body and in the 200 answer; without it, the default message does
Contractopenapi.json documents the 400 on POST /query with the InterventionResponse schema (error fixed to content_policy_violation), and documents the reason values of QueryResponse; the committed file matches what the app generates
Frontend unitA 400 carrying content_policy_violation becomes a non-retryable error whose message is the configured text verbatim; any other 400 falls back to the response text
Frontend unitThe answer panel shows an intervention message in a 200 answer as it shows any answer
Logging (unit for the output guard, manual in QA for the input guard)Each intervention logs guard_action=INTERVENED, guard_source (input or output), and the request id; no answer text appears at INFO
Integration (manual, QA)With the guardrail enabled, a blocked question shows the configured message in the UI with no retry button, and the API key badge stays visible
  • Story #71 (input guard) and Story #72 (output guard) merged
  • Story #18 (wire UI to API) merged: the UI error path exists
  • The RAG005 OpenAPI drift check running in CI
  • The input intervention is a 400 and is distinct from 401 (auth) and 422 (validation)
  • The output intervention is a 200 with reason: content_policy_violation, not a 4xx, because the blocked content is the server’s own output
  • openapi.json documents both outcomes, and the CI OpenAPI drift check passes
  • The UI shows the configured message verbatim and does not offer a retry for an input intervention
  • Unit tests use Given / When / Then comment leads, and coverage meets the RAG006 floors
  • In QA, a blocked question shows the message in the UI

Unit and contract: CI and local. UI and integration: manual against QA with the guardrail enabled.

pytest, vitest, make export-openapi, the CI OpenAPI drift check (backend.yml, “Check OpenAPI spec is up to date”), a browser against the QA site.

async def test_env_message_override_reaches_the_400_body(monkeypatch):
# Given GUARDRAIL_INTERVENTION_MESSAGE is set in the environment
# When the input guard intervenes
# Then the 400 body carries the override
it('rejects with the configured message on a guardrail intervention 400, non-retryable', async () => {
// Given: the server returns the guardrail intervention body
// When / Then: the ApiError carries the message verbatim and is not retryable
});
  • The two outcomes use different status codes on purpose: a blocked question is the client’s input (400), and a blocked answer is the server’s output (200). A client that treats only non-2xx as a failure must check reason on 200 responses.
  • The 200 intervention carries the message in answer, so a client that renders answer needs no change, and a client that parses reason can distinguish it from a generated answer.
  • An empty GUARDRAIL_INTERVENTION_MESSAGE makes the UI fall back to the raw 400 text. The default message applies whenever the variable is unset.

Safety (#44): an intervention is a distinct, observable outcome with a documented, non-leaky response (RAG013).