Skip to content

fix(policy): correct INSULTS content-filter enum and validate --form-filters#1576

Merged
jesseturner21 merged 2 commits into
mainfrom
fix/content-filter-insults-enum-1571
Jun 18, 2026
Merged

fix(policy): correct INSULTS content-filter enum and validate --form-filters#1576
jesseturner21 merged 2 commits into
mainfrom
fix/content-filter-insults-enum-1571

Conversation

@jesseturner21

Copy link
Copy Markdown
Contributor

Description

agentcore add policy --form-category contentFilter --form-filters INSULT succeeded locally but agentcore deploy failed at the CFN service with an opaque ValidationException (Valid categories: VIOLENCE, HATE, SEXUAL, MISCONDUCT, INSULTS).

Two root causes, both fixed here:

  1. Enum typo. CONTENT_FILTER_FILTERS listed 'INSULT' (singular); the service enum is 'INSULTS' (plural). The TUI offered the bad value because its options derive from this constant. Fixed in src/cli/tui/screens/policy/types.ts — one-word change that also fixes the TUI.
  2. No client-side validation of --form-filters. The non-interactive path split the flag and passed raw values straight to synthesizeCedar, so any string (e.g. NOTAREAL) was accepted and only failed at deploy. Added FILTERS_BY_CATEGORY + invalidFiltersForCategory() helpers in types.ts (reusing the per-category enums already defined there as the single source of truth) and wired validation into PolicyPrimitive, throwing a ValidationError with a clear message listing the invalid filter(s) and the allowed set.

Per maintainer guidance on the issue, validation is scoped to the form-filter enums the TUI/CLI already offers — not a blanket validation of every flag.

Related Issue

Closes #1571

Type of Change

  • Bug fix

Testing

  • I ran npm run test:unit (24 policy tests pass, incl. new regression coverage)
  • I ran npm run typecheck (zero errors)
  • I ran npm run lint (passes via pre-commit hooks)

New tests:

  • types.test.ts — valid filters per category pass; unknown filter rejected; cross-category filter rejected; regression guard that INSULTS is accepted while INSULT is rejected.
  • synthesize-cedar.test.ts — added an INSULTS case to lock in the canonical name.

Checklist

  • I have added any necessary tests that prove my fix is effective
  • My changes generate no new warnings
  • Docs update — N/A (no user-facing doc changes; valid filter list unchanged in count)

…filters

CONTENT_FILTER_FILTERS listed 'INSULT' (singular); the service enum is
'INSULTS' (plural). The TUI offered the bad value and the non-interactive
CLI accepted any string for --form-filters, so both only failed at
`agentcore deploy` with an opaque CFN ValidationException.

Fix the enum (also fixes the TUI, which derives its options from it) and
add client-side validation of --form-filters against the per-category
enums already defined in types.ts, turning a deploy-time failure into an
immediate, clear error.

Closes #1571

Constraint: Validation scoped to form-filter enums the TUI/CLI already offers, per maintainer guidance — not blanket validation of every flag
Rejected: New per-category filter constants in PolicyPrimitive | duplicates the source of truth already in types.ts
Confidence: high
Scope-risk: narrow
@jesseturner21 jesseturner21 requested a review from a team June 18, 2026 15:34
@github-actions github-actions Bot added the size/s PR size: S label Jun 18, 2026
@github-actions github-actions Bot added the agentcore-harness-reviewing AgentCore Harness review in progress label Jun 18, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added the claude-security-reviewing Claude Code /security-review in progress label Jun 18, 2026
@agentcore-devx-automation

Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

@agentcore-devx-automation agentcore-devx-automation Bot removed the claude-security-reviewing Claude Code /security-review in progress label Jun 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Package Tarball

aws-agentcore-0.20.1.tgz

How to install

gh release download pr-1576-tarball --repo aws/agentcore-cli --pattern "*.tgz" --dir /tmp/pr-tarball
npm install -g /tmp/pr-tarball/aws-agentcore-0.20.1.tgz

@agentcore-cli-automation agentcore-cli-automation left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Clean, focused bug fix.

Verified:

  • Typo fix INSULTINSULTS in CONTENT_FILTER_FILTERS flows through to the TUI automatically since GUARDRAIL_CATEGORY_OPTIONS references the constant (AddPolicyScreen.tsx consumes it).
  • No other source/test/doc references to the legacy singular INSULT remain (grep -rn INSULT src/ test/ is clean apart from the regression test).
  • FILTERS_BY_CATEGORY reuses the per-category enums as the single source of truth — no duplication.
  • New validation in PolicyPrimitive runs inside the existing runCliCommand('add.policy', ...) block, so the ValidationError is captured by telemetry without extra instrumentation.
  • The category cast on line 418 is safe because allowedCategories is checked at lines 405–410 just above.
  • Tests are pure-function tests with no mocking — exactly the right level for what's being validated. The #1571 regression guard for INSULT is a nice touch.

@github-actions github-actions Bot removed the agentcore-harness-reviewing AgentCore Harness review in progress label Jun 18, 2026
@github-actions

github-actions Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 36.92% 13502 / 36562
🔵 Statements 36.21% 14357 / 39642
🔵 Functions 31.47% 2306 / 7327
🔵 Branches 30.69% 8915 / 29044
Generated in workflow #3698 for commit a4dd5ba by the Vitest Coverage Report Action

Drop three tests that padded coverage without exercising distinct
behavior: the constant-literal INSULTS assertion (already covered by the
regression guard through the helper), the cross-category case (same code
path as the unknown-filter test), and the FILTERS_BY_CATEGORY wiring
assertion (structure, not behavior). Keep happy-path, unknown-filter,
and the #1571 regression guard.

Confidence: high
Scope-risk: narrow
@github-actions github-actions Bot added size/s PR size: S and removed size/s PR size: S labels Jun 18, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added the claude-security-reviewing Claude Code /security-review in progress label Jun 18, 2026
@agentcore-devx-automation

Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

@agentcore-devx-automation agentcore-devx-automation Bot removed the claude-security-reviewing Claude Code /security-review in progress label Jun 18, 2026

@notgitika notgitika left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just a question for follow up


export type GuardrailCategoryType = 'contentFilter' | 'promptAttack' | 'sensitiveInformation';

export const CONTENT_FILTER_FILTERS = ['VIOLENCE', 'HATE', 'SEXUAL', 'MISCONDUCT', 'INSULT'] as const;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe as a future follow up, can we inherit these types from the sdk?

@jesseturner21 jesseturner21 merged commit 5fe72af into main Jun 18, 2026
33 checks passed
@jesseturner21 jesseturner21 deleted the fix/content-filter-insults-enum-1571 branch June 18, 2026 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/s PR size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TUI/CLI accepts INSULT as a contentFilter value, fails CFN deploy with ValidationException

3 participants