feat: add configurable request and response guardrails - #2696
Open
fernandoescolar wants to merge 10 commits into
Open
fernandoescolar wants to merge 10 commits into
fernandoescolar wants to merge 10 commits into
Conversation
✅ Deploy Preview for theagentrouter canceled.
|
Contributor
|
I haven't checked, as there are many PRs open at the moment, but have you submitted a design doc PR for this? Would be helpful! https://builtonenvoy.io/extensions/bedrock-guardrails/ |
fernandoescolar
force-pushed
the
feat/guardrails
branch
from
September 16, 2026 17:39
825835e to
474d823
Compare
fernandoescolar
marked this pull request as draft
September 16, 2026 18:19
fernandoescolar
force-pushed
the
feat/guardrails
branch
2 times, most recently
from
September 16, 2026 21:19
ee3754a to
6f33ff0
Compare
added 8 commits
September 16, 2026 23:24
- add GuardrailPolicy CRD in v1alpha1 and v1beta1 - support dual-version schema and runtime config wiring - compile regex-based guardrails into runtime matcher state - enforce request/response guardrails in extproc before upstream or client response - add guardrail regression tests for runtime evaluation Signed-off-by: Fernando Escolar <fernando.escolar@digits.schwarz>
Signed-off-by: Fernando Escolar <fernando.escolar@digits.schwarz>
Signed-off-by: Fernando Escolar <fernando.escolar@digits.schwarz>
- Implemented support for regex guardrails and external providers including Presidio, AWS Bedrock, and Azure AI Content Safety. - Added failure behavior configuration for external providers. - Enhanced observability with structured logging for guardrail evaluations. - Created test cases for various guardrail policy scenarios including validation of rules and provider configurations. - Added documentation for content guardrails and examples for usage. Signed-off-by: Fernando Escolar <fernando.escolar@digits.schwarz>
…ed documentation Signed-off-by: Fernando Escolar <fernando.escolar@digits.schwarz>
- Introduced maxRequestBodyBytes and maxResponseBodyBytes to limit payload sizes. - Updated GuardrailEvaluator interface to return GuardrailEvaluationResult. - Enhanced Presidio and Bedrock evaluators to support masking functionality. Signed-off-by: Fernando Escolar <fernando.escolar@digits.schwarz>
Signed-off-by: Fernando Escolar <fernando.escolar@digits.schwarz>
Signed-off-by: Fernando Escolar <fernando.escolar@digits.schwarz>
fernandoescolar
force-pushed
the
feat/guardrails
branch
from
September 16, 2026 21:25
eea5b29 to
837affe
Compare
Author
|
I’ve added a proposal/technical design document ( I’m sorry I did not follow the project’s contribution and review protocol correctly from the beginning. I’ve reviewed the guidelines and updated the PR to align with them. |
fernandoescolar
marked this pull request as ready for review
September 16, 2026 21:30
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This change adds native content guardrails to Envoy AI Gateway through a new
GuardrailPolicyresource and request/response enforcement in the external processor.The design proposal is included at
docs/proposals/013-guardrails/proposal.md. It compares the ext-proc architecture with the Built on Envoy Bedrock Guardrails and Azure Content Safety dynamic-module extensions and records the adopted decisions, current scope, follow-up work, and open questions.The API is available in both
v1alpha1andv1beta1and targetsAIServiceBackendresources. Rules support request or response evaluation, deterministic multi-policy composition, configurable payload limits and timeouts, and explicit fail-open or fail-closed behavior. Actions can block, monitor, or mask matching content. CRD admission validates provider configuration, actions, endpoints, targets, and unique rule names.The runtime supports:
Provider credentials are resolved from Kubernetes Secrets or, for Bedrock, from the standard AWS credential chain. Secret changes and policy deletion trigger reconciliation of affected routes. Missing or revoked provider configuration follows the rule's failure mode and does not leave stale gateway configuration active.
External providers receive schema-extracted text instead of serialized request envelopes. Mask actions write transformed text back to its original JSON field. Response guardrails keep streaming responses buffered until evaluation completes, preventing unsafe content from being partially delivered. Violations return HTTP 403 with the
GuardrailViolationerror type.The implementation adds structured logs without payload content, an OpenTelemetry evaluation counter, and guardrail span events. It also includes example manifests and task-oriented documentation.
Validation includes unit tests, CRD admission tests, controller lifecycle and Secret rotation tests, HTTP-stub integration tests, Envoy dataplane tests for request and response blocking, and a Testcontainers test against the pinned official Presidio analyzer image. Live Azure AI Content Safety and AWS Bedrock Guardrails tests passed against real provider resources. Credential-gated live tests remain skipped by default.
GitHub Copilot was used to assist with implementation, tests, documentation, and review. The contributor has reviewed and takes responsibility for the resulting changes.
Related Issues/PRs (if applicable)
fixes: #1409 (Prompt guard moderation)
fixes: #1415 (pii detection)
fixes: #1919 (external security provider)
related: #2128 (content governance)
Special notes for reviewers (if applicable)
The main review areas are the dual-version CRD contract, Secret lifecycle behavior, backend scoping, fail-open/fail-closed semantics, response buffering, and external provider request formats.
Live provider validation requires local credentials and is intentionally not part of default CI. Presidio requires Docker but no credentials.