Skip to content

feat(01-learn): add 18-input-output-guardrails tutorial - #267

Open
SyedAn-Git wants to merge 5 commits into
strands-agents:mainfrom
SyedAn-Git:feat/18-input-output-guardrails
Open

feat(01-learn): add 18-input-output-guardrails tutorial#267
SyedAn-Git wants to merge 5 commits into
strands-agents:mainfrom
SyedAn-Git:feat/18-input-output-guardrails

Conversation

@SyedAn-Git

Copy link
Copy Markdown

Adds Input/Output Guardrails tutorial to python/01-learn/

Covers:

  • Input guardrails (BeforeInvocationEvent)
  • Output guardrails (AfterInvocationEvent) with BLOCK/REDACT
  • Custom content filters (regex, keyword, format compliance)
  • GuardrailPlugin (HookProvider pattern)
  • Tool call validation (BeforeToolCallEvent)
  • Error handling (fail-open vs fail-closed)

Tested on SageMaker Studio with strands-agents 1.40.0

@SyedAn-Git

Copy link
Copy Markdown
Author

@manoj-selvakumar5 Ready for review. This is the Input/Output Guardrails tutorial.

@SyedAn-Git

Copy link
Copy Markdown
Author

Pushed a fix commit (476e346) — inlined content filter classes directly into notebooks and added logger definitions so each notebook runs independently without cross-file dependencies. All 6 notebooks tested clean on SageMaker Studio.

@manoj-selvakumar5

Copy link
Copy Markdown
Collaborator

Hi @SyedAn-Git - There's some overlap with 01-learn/16-hooks-lifecycle and 03-integrate/guardrails/ so I'd suggest moving this to 05-technical-use-cases/guardrails/ treating hooks as a prerequisite instead of re-teaching them.

Syed Sultan Beevi added 2 commits August 23, 2026 10:42
…hooks as prerequisite

Addresses review feedback on PR strands-agents#267:
- Move 01-learn/18-input-output-guardrails -> 05-technical-use-cases/guardrails/custom-python-guardrails
- Reframe README and notebook markdown to treat 16-hooks-lifecycle as a
  prerequisite instead of re-teaching hook mechanics
- Fix broken link to guardrail integrations (now 03-integrate/guardrails)
- Remove stale references to the old inlined content_filters.py module

Notebook code cells are unchanged.
… samples

Distinguish the three guardrail approaches in the README: this hooks-based
sample, the managed Amazon Bedrock Guardrails sample (01-learn/05-guardrails),
and the third-party integrations (03-integrate/guardrails).
@SyedAn-Git

Copy link
Copy Markdown
Author

Thanks for the review, @manoj-selvakumar5! I've addressed the overlap feedback:

Moved the tutorial from 01-learn/18-input-output-guardrails/ → 05-technical-use-cases/guardrails/custom-python-guardrails/ (via git mv, so history is preserved).

Reframed hooks as a prerequisite instead of re-teaching them:

  1. Added an explicit Prerequisites section in the README pointing to 01-learn/16-hooks-lifecycle for the hook mechanics (HookProvider, register_hooks, writable event fields).
  2. Updated the notebook intro cells to reference 16-hooks-lifecycle and stopped re-explaining the hook lifecycle, each step now applies hooks to guardrails rather than teaching them.

Clarified how this relates to the other guardrail samples, the README now distinguishes the three approaches: this pure-Python/hooks sample, the managed 01-learn/05-guardrails (Amazon Bedrock Guardrails), and the third-party 03-integrate/guardrails integrations.

Re-tested: all 6 notebooks execute end-to-end with zero cell errors on strands-agents 1.53.0. The guardrail-specific code cells are unchanged from the original.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants