QA plan: Output guard on /query (#72)
Story: Output guard: ApplyGuardrail on generated answer before return (#72)
Feature: Safety Gate via Bedrock Guardrails (#69)
Capability: Safety (#44)
ADRs: RAG013 — Safety gate via Bedrock Guardrails
Test scope
Section titled “Test scope”| Type | Coverage |
|---|---|
| Unit | A generated answer the guardrail blocks returns HTTP 200 whose answer is the configured intervention message, whose citations are empty, and whose reason is content_policy_violation; the generated text is absent from the response |
| Unit | A generated answer the guardrail allows is returned unmodified with its citations |
| Unit | With no guardrail ARN configured, the generated answer is returned unchanged |
| Unit | An empty generated answer is not sent to ApplyGuardrail and the response is the normal one |
| Unit | A guardrail call that raises returns 503 and does not return the generated answer (fails closed) |
| Unit | The guard call uses source OUTPUT, and the generated answer is the text evaluated |
| Logging | Each call logs guard_source=output and guard_action at INFO with the request id; a blocked answer is logged at DEBUG only, and no INFO record contains answer text |
| Policy (manual, QA) | aws bedrock-runtime apply-guardrail --source OUTPUT with the guardrail ARN and version, on a sample of harmful text, returns action GUARDRAIL_INTERVENED; on a neutral sentence it returns NONE |
| Integration (manual, QA) | With the guardrail enabled, an ordinary question returns 200 with an answer and citations, and the log shows guard_source=output with guard_action=NONE |
Entry criteria
Section titled “Entry criteria”- Story #70 (guardrail in Terraform) merged, and the guardrail enabled and applied in the QA environment for the manual rows
- Story #71 (input guard) merged: the guardrail provider and its settings exist
- Story #13 (
/queryendpoint) merged
Exit criteria
Section titled “Exit criteria”- A blocked answer is replaced by the configured message in a 200 response with empty citations and
reason: content_policy_violation - A clean answer passes through unmodified
- With the guardrail unset, the generated answer is returned unchanged
- A guardrail failure returns 503 and never returns the generated answer
- The blocked answer text appears only at DEBUG
- Unit tests use Given / When / Then comment leads, and coverage meets the RAG006 floors
- In QA, the policy blocks a harmful sample and passes a neutral one
Environments
Section titled “Environments”Unit: CI and local. Policy and integration: manual against QA with the guardrail enabled. DEBUG logging is off in deployed environments.
Tooling
Section titled “Tooling”pytest with httpx.AsyncClient, AWS CLI (aws bedrock-runtime apply-guardrail, aws logs filter-log-events), curl.
How tests are written
Section titled “How tests are written”async def test_intervened_answer_is_replaced_by_the_message_with_a_200(): # Given a guardrail that blocks the generated answer # When a clean question is posted # Then the answer is the configured message, citations are empty, and reason is content_policy_violation# Given the QA guardrail ARN and version# When harmful sample text is evaluated as OUTPUTaws bedrock-runtime apply-guardrail --guardrail-identifier $GUARDRAIL_ARN --guardrail-version $GUARDRAIL_VERSION --source OUTPUT --content '[{"text":{"text":"<harmful sample>"}}]'# Then the response action is GUARDRAIL_INTERVENED- A model answer rarely trips the filters on demand, so the app-level blocked path is verified with a stubbed guardrail in unit tests, and the policy itself is verified through
apply-guardraildirectly. The two together stand in for an end-to-end blocked answer. - The blocked answer is logged at DEBUG so an operator can investigate. If DEBUG is enabled in a deployed environment, harmful text persists in logs; the exit criteria require it off.
- The guard adds one Bedrock call after generation. Its latency is read from the structured log timestamps.
Capability acceptance criteria link
Section titled “Capability acceptance criteria link”Safety (#44): a model response that drifts into a filtered category is caught before it crosses the API boundary (RAG013).
© 2026 Benjamin Arunski