Skip to content

Commit cff4a1e

Browse files
rhbelsonrbelson@amazon.com
andauthored
docs(policy): fix guardrails docstring drift and temporal test-table row (#1986)
* docs(policy): fix guardrails docstring drift and temporal test-table row - 02-guardrails-in-policy/deploy.py: the ApplicationTool free-text field is 'message' in the actual tool schema and all four guardrail policies scan context.input.message, but the module docstring, tool description, and a comment referred to a nonexistent 'customer_notes' field. Also the SSN policy is named 'block_ssn' in code but the docstring listed 'block_pii'. Aligned the docs with the code (no runtime change). - 03-temporal-policies/bankingassistant/README.md: Policy 1 test-table row 3 was self-contradictory (prompt said 'to ACC-2003', the to_account column said 'ACC-9999', and the looked-up account was ACC-2002). Made the prompt and column agree on ACC-9999 and named the looked-up account in the DENY reason so the walkthrough is coherent. * style(policy): fix pre-existing ruff findings in guardrails deploy.py The python-lint CI gate runs ruff on the full changed file, so editing deploy.py surfaced 4 pre-existing findings unrelated to the docstring fix: - RUF013 implicit Optional on get_aws_context(region, profile) -> str | None - S110/BLE001 blind except Exception: pass in add_lambda_gateway_permission -> narrowed to except ClientError with an explanatory comment (idempotent permission removal; the statement legitimately may not exist on first run). No behavior change. --------- Co-authored-by: rbelson@amazon.com <rbelson@amazon.com>
1 parent 4c4e2da commit cff4a1e

2 files changed

Lines changed: 11 additions & 10 deletions

File tree

  • 01-features/07-centralize-and-govern-your-ai-infrastructure/02-policy

01-features/07-centralize-and-govern-your-ai-infrastructure/02-policy/02-guardrails-in-policy/deploy.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
44
Creates an insurance underwriting environment with content safety guardrails:
55
6-
1. Lambda tools — ApplicationTool (with customer_notes), RiskModelTool, ApprovalTool
6+
1. Lambda tools — ApplicationTool (with message), RiskModelTool, ApprovalTool
77
2. IAM role — Lambda execution role
88
3. Gateway — AgentCore MCP Gateway (IAM auth)
99
4. Targets — Three Lambda targets with tool schemas
1010
5. Policy Engine — Cedar policy engine
1111
6. Base permit — Cedar PERMIT allowing all traffic (guardrail FORBIDs override)
1212
7. Guardrail policies:
13-
- block_violence : content filter on customer_notes (VIOLENCE >= 0.5)
14-
- block_jailbreak : prompt attack on customer_notes (JAILBREAK >= 0.7)
15-
- block_pii : sensitive info on customer_notes (SSN >= 0.5)
16-
- block_credit_cards : sensitive info on customer_notes (CREDIT_CARD >= 0.5)
13+
- block_violence : content filter on message (VIOLENCE >= 0.5)
14+
- block_jailbreak : prompt attack on message (JAILBREAK >= 0.7)
15+
- block_ssn : sensitive info on message (SSN >= 0.5)
16+
- block_credit_cards : sensitive info on message (CREDIT_CARD >= 0.5)
1717
8. Attach engine — ENFORCE mode on the gateway
1818
1919
All output is written to guardrail_config.json.
@@ -46,7 +46,7 @@
4646
"schema": [
4747
{
4848
"name": "create_application",
49-
"description": "Create an insurance application with geographic validation. Use customer_notes for any free-text notes about the applicant.",
49+
"description": "Create an insurance application with geographic validation. Use message for any free-text notes about the applicant.",
5050
"inputSchema": {
5151
"type": "object",
5252
"properties": {
@@ -120,7 +120,7 @@
120120
# ── AWS Session Setup ─────────────────────────────────────────────────────────
121121

122122

123-
def get_aws_context(region: str = None, profile: str = None) -> tuple:
123+
def get_aws_context(region: str | None = None, profile: str | None = None) -> tuple:
124124
"""Return (session, REGION, ACCOUNT_ID)."""
125125
session = boto3.Session(profile_name=profile)
126126
resolved_region = region or session.region_name or os.environ.get("AWS_DEFAULT_REGION")
@@ -196,7 +196,8 @@ def add_lambda_gateway_permission(lambda_client, function_name: str, gateway_arn
196196
statement_id = "AllowAgentCoreGateway"
197197
try:
198198
lambda_client.remove_permission(FunctionName=function_name, StatementId=statement_id)
199-
except Exception:
199+
except ClientError:
200+
# Statement does not exist yet on first run — safe to ignore and re-add below.
200201
pass
201202
lambda_client.add_permission(
202203
FunctionName=function_name,
@@ -469,7 +470,7 @@ def create_all_guardrail_policies(ctrl, engine_id: str, gateway_arn: str) -> dic
469470
print("\n[Step 5] Creating guardrail policies...")
470471

471472
resource = f'AgentCore::Gateway::"{gateway_arn}"'
472-
# Action that carries the customer_notes free-text field.
473+
# Action that carries the message free-text field.
473474
# Format: <TargetName>___<toolMethodName>
474475
action = 'AgentCore::Action::"ApplicationToolTarget___create_application"'
475476
scope = f"principal, action == {action}, resource == {resource}"

01-features/07-centralize-and-govern-your-ai-infrastructure/02-policy/03-temporal-policies/bankingassistant/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ when { context.input.amount <= 10000 };
277277
| :--- | :--- | :--- | :--- |
278278
| 1 | Check the balance of ACC-2002 | - | ALLOW |
279279
| 2 | , then transfer $500 from ACC-1001 to ACC-2002 | ACC-2002 | ALLOW |
280-
| 3 | Transfer $500 from ACC-1001 to ACC-2003 | ACC-9999 | DENY (destination does not match the looked-up account) |
280+
| 3 | Transfer $500 from ACC-1001 to ACC-9999 | ACC-9999 | DENY (destination does not match the looked-up account ACC-2002) |
281281

282282
</details>
283283

0 commit comments

Comments
 (0)