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
Test scope
Section titled “Test scope”| Type | Coverage |
|---|---|
| Unit | An input intervention returns HTTP 400 with {"error": "content_policy_violation", "message": <configured message>}; the body is built from the documented InterventionResponse model |
| Unit | An output intervention returns HTTP 200 with the configured message as answer, empty citations, and reason: content_policy_violation |
| Unit | With GUARDRAIL_INTERVENTION_MESSAGE set, the message appears in the 400 body and in the 200 answer; without it, the default message does |
| Contract | openapi.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 unit | A 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 unit | The 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 |
Entry criteria
Section titled “Entry criteria”- 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
Exit criteria
Section titled “Exit criteria”- 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.jsondocuments 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
Environments
Section titled “Environments”Unit and contract: CI and local. UI and integration: manual against QA with the guardrail enabled.
Tooling
Section titled “Tooling”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.
How tests are written
Section titled “How tests are written”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 overrideit('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
reasonon 200 responses. - The 200 intervention carries the message in
answer, so a client that rendersanswerneeds no change, and a client that parsesreasoncan distinguish it from a generated answer. - An empty
GUARDRAIL_INTERVENTION_MESSAGEmakes the UI fall back to the raw 400 text. The default message applies whenever the variable is unset.
Capability acceptance criteria link
Section titled “Capability acceptance criteria link”Safety (#44): an intervention is a distinct, observable outcome with a documented, non-leaky response (RAG013).
© 2026 Benjamin Arunski