Repository navigation
Description
Summary
Add a BedrockRuntimePlugin stub covering ApplyGuardrail. This is used by the quick-suite-model-router project — three external-provider Lambdas (Anthropic, OpenAI, Gemini) call apply_guardrail() which hits bedrock-runtime to screen prompts and completions before returning to the caller. Integration tests need to exercise the full guardrail code path without a real Bedrock account.
Operations required
| Operation | HTTP | Used by |
|---|---|---|
ApplyGuardrail |
POST /guardrail/{guardrailIdentifier}/version/{guardrailVersion}/apply |
All three external-provider Lambdas |
The ApplyGuardrail endpoint lives on the bedrock-runtime host (bedrock-runtime.<region>.amazonaws.com), not the bedrock control-plane host. The service name in SigV4 scope is bedrock. The plugin Name() should return "bedrock-runtime" (or the server's routing key for this host — whichever ParseAWSRequest extracts from the Host header).
Request shape
{
"source": "INPUT" | "OUTPUT",
"content": [{"text": {"text": "..."}}]
}Expected behaviour
The stub should support two modes, controlled by state set via a test-only endpoint (or reset via /v1/state/reset):
Default (pass-through): All content passes. Return 200:
{
"action": "NONE",
"outputs": [{"text": "..."}],
"assessments": [],
"usage": {"topicPolicyUnitsProcessed": 0, "contentPolicyUnitsProcessed": 1,
"wordPolicyUnitsProcessed": 0, "sensitiveInformationPolicyUnitsProcessed": 0,
"sensitiveInformationPolicyFreeUnitsProcessed": 0, "contextualGroundingPolicyUnitsProcessed": 0}
}The outputs[0].text should echo the input text unchanged.
Block mode: Configurable blocklist of substrings stored in state. If any substring appears in the content text, return 200 with:
{
"action": "GUARDRAIL_INTERVENED",
"outputs": [{"text": "Sorry, I can't help with that."}],
"assessments": [{"topicPolicy": {"topics": [{"name": "blocked-topic", "type": "DENY", "action": "BLOCKED"}]}}],
"usage": {...}
}Non-existent guardrail: If guardrailIdentifier is not found in state, return 400:
{
"__type": "ResourceNotFoundException",
"message": "Guardrail <id> not found"
}Guardrail provisioning
Tests need a way to create a guardrail so DescribeGuardrail / ApplyGuardrail can find it. Two options (either works):
- Auto-create on first
ApplyGuardrailcall if the ID is not found (simpler for tests). - Support
CreateGuardrailon thebedrockcontrol-plane plugin (separate frombedrock-runtime).
Option 1 is preferred to keep scope minimal — the router tests only call apply_guardrail(), never CreateGuardrail.
Blocklist configuration
Store blocklist per guardrail under state key bedrock:guardrail:{accountId}/{guardrailId}/blocklist as a JSON array of strings. Tests can seed this via the state manager directly in Go tests, or via a future /v1/config endpoint.
File layout
bedrock_runtime_plugin.go # ApplyGuardrail implementation
bedrock_runtime_plugin_test.go # Unit tests
Register in RegisterDefaultPlugins in plugins.go after existing plugins.
Test cases needed
- ApplyGuardrail with empty blocklist → action NONE, output text echoed
- ApplyGuardrail with matching blocklist term → action GUARDRAIL_INTERVENED
- ApplyGuardrail with non-matching blocklist term → action NONE
- ApplyGuardrail source=INPUT and source=OUTPUT both work
- Unknown guardrail ID → 400 ResourceNotFoundException
Context
The quick-suite-model-router provider tests currently mock apply_guardrail at the Python module level. With this stub, integration tests can instead set GUARDRAIL_ID and BEDROCK_ENDPOINT_URL=http://localhost:4566 and exercise the real boto3 → HTTP → guardrail decision path. This is particularly valuable for verifying that a blocked input short-circuits the provider call and that the guardrail_blocked flag propagates correctly through the router response.
Out of scope for this issue
InvokeModel/InvokeModelWithResponseStream— the router uses Bedrock's Converse API natively; those calls go to real Bedrock and are not stubbed.CreateGuardrail/ListGuardrailscontrol-plane operations.
Activity
Release v0.45.1: QuickSight + Bedrock Runtime plugins (#247, #248)