Skip to content

Add BedrockCreateGuardrailOperator - #66035

Merged
vincbeck merged 2 commits into
apache:mainfrom
john-jac:add-bedrock-guardrail-create
Apr 29, 2026
Merged

Add BedrockCreateGuardrailOperator#66035
vincbeck merged 2 commits into
apache:mainfrom
john-jac:add-bedrock-guardrail-create

Conversation

@john-jac

Copy link
Copy Markdown
Contributor

What

Add an operator to create Amazon Bedrock guardrails for implementing safety controls in generative AI applications.

Use Case

Teams deploying LLM-powered applications need to enforce content safety policies (block hate speech, filter PII, deny off-topic discussions) as part of their deployment pipeline. A guardrail is created with content filters and topic policies, then associated with the Bedrock model. Having this in a DAG makes safety policy changes versioned, auditable, and promotable through dev/staging/prod:

create_guardrail >> configure_model_endpoint >> run_eval_tests >> notify_team

The create_guardrail API creates a DRAFT version that is immediately usable — no separate version step needed for dev/test workflows.

How

  • New BedrockCreateGuardrailOperator using AwsBaseOperator[BedrockHook] pattern
  • Supports content filters, denied topics, word filters, PII masking, and contextual grounding
  • Idempotent: if_exists="skip" handles ConflictException
  • Uses prune_dict for clean kwargs building
  • Returns the guardrail ID

Files

  • operators/bedrock_guardrail.py — operator
  • test_bedrock_guardrail.py — unit tests (4 tests)
  • example_bedrock_guardrail.py — system test with teardown
  • bedrock_guardrail.rst — docs
  • provider.yaml + get_provider_info.py — updated

Testing

  • Unit tests: 4 passed
  • mypy: no issues
  • Static checks: 43 passed, 0 PR-related failures

Comment thread providers/amazon/src/airflow/providers/amazon/aws/operators/bedrock_guardrail.py Outdated
@john-jac
john-jac force-pushed the add-bedrock-guardrail-create branch from 80c4d32 to d41ea24 Compare April 28, 2026 18:48

@SameerMesiah97 SameerMesiah97 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.

I see that you are actively pushing changes but I have left a few comments for guidance.

The direction is fine but the logic is a bit too messy at the moment. Also, I think you could cover more scenarios in the tests. Also, I know that you have just moved the operator code into the existing file but you should move the tests to test_bedrock.py as well.

Comment thread providers/amazon/tests/unit/amazon/aws/operators/test_bedrock_guardrail.py Outdated
@john-jac
john-jac force-pushed the add-bedrock-guardrail-create branch 5 times, most recently from ca20a81 to 8ec0d3d Compare April 29, 2026 00:34
@john-jac

Copy link
Copy Markdown
Contributor Author

Closing to resubmit with clean branch. Too many accumulated fixes.

@john-jac john-jac closed this Apr 29, 2026
@john-jac john-jac reopened this Apr 29, 2026
@john-jac
john-jac force-pushed the add-bedrock-guardrail-create branch 2 times, most recently from 3fb2797 to 6e2a815 Compare April 29, 2026 04:39
Comment thread providers/amazon/src/airflow/providers/amazon/aws/hooks/bedrock.py
@john-jac
john-jac force-pushed the add-bedrock-guardrail-create branch from 6e2a815 to b5226f5 Compare April 29, 2026 13:43
@john-jac
john-jac force-pushed the add-bedrock-guardrail-create branch from b5226f5 to 7c063b5 Compare April 29, 2026 14:17
@john-jac

Copy link
Copy Markdown
Contributor Author

Thanks @SameerMesiah97 and @vincbeck for the review! Addressed all feedback:

  1. Moved guardrail tests into test_bedrock.py (no separate file)
  2. Added hook unit tests for get_guardrail_id_by_name (test_found + test_not_found)
  3. Unhappy path tests already added: test_execute_fail_on_conflict and test_execute_skip_existing_not_found
  4. Operator uses hook.get_guardrail_id_by_name() instead of inline paginator

@vincbeck

Copy link
Copy Markdown
Contributor

CI is failing

@john-jac

Copy link
Copy Markdown
Contributor Author

CI is failing

Should be good now. I'm still playing with my pre-submit CI process but it keeps missing things. It's a process.

@vincbeck
vincbeck merged commit 0217a7b into apache:main Apr 29, 2026
93 checks passed
seruman pushed a commit to seruman/airflow that referenced this pull request Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants