Skip to main content

Bedrock Guardrail Firewall

Bedrock Guardrail Firewall: Redact. Defend. Verify.

Turn every generative AI request and response into an enforceable security decision with PII redaction, prompt-injection defense, grounding checks, authorization controls, tamper-evident auditing, and optional Amazon Bedrock Guardrails.

One file. Multiple control planes. Zero implicit cloud calls.

Python AWS Presidio License CI CodeQL Security Scanners

Bedrock Guardrail Firewall is a privacy-first enforcement layer for generative AI systems. It combines deterministic local controls, optional Microsoft Presidio analysis, and the Amazon Bedrock ApplyGuardrail API without invoking a foundation model.

The production runtime remains a single Python file: orchestrator.py. Policy, documentation, tests, and repository automation are kept separate so the runtime stays portable and auditable.

Bedrock Guardrail Firewall local-first decision flow

Try it offline in 60 seconds

Prerequisite: Python 3.12 or newer. These commands install the standard-library-only core, create no AWS client, and require no credentials.

Windows PowerShell:

py -3 -m venv .venv
.\.venv\Scripts\python.exe -m pip install bedrock-guardrail-firewall
.\.venv\Scripts\bedrock-guardrail-firewall.exe --presidio-mode disabled doctor
.\.venv\Scripts\bedrock-guardrail-firewall.exe --presidio-mode disabled evaluate --input "Contact analyst@example.invalid for the approved report." --no-record

Linux or macOS:

python3 -m venv .venv
.venv/bin/python -m pip install bedrock-guardrail-firewall
.venv/bin/bedrock-guardrail-firewall --presidio-mode disabled doctor
.venv/bin/bedrock-guardrail-firewall --presidio-mode disabled evaluate --input "Contact analyst@example.invalid for the approved report." --no-record

The evaluation returns a machine-readable decision and only releasable content:

{
  "action": "sanitize",
  "content_released": true,
  "recommended_action": "sanitize",
  "sanitized_input": "Contact [EMAIL_ADDRESS_REDACTED] for the approved report."
}

The real response also includes risk, triggered control categories, capability restrictions, diagnostics, and the active policy digest. It excludes blocked content, credentials, local paths, queue URLs, bucket names, and keys.

Version 4.1.2 is the current release version of this source tree. The core evaluates entirely offline. Optional Presidio and AWS controls have separate readiness checks and are never represented as active unless the selected policy profile verifies them.

Put it in a request path

The standard-library request gate converts firewall decisions into framework-neutral HTTP-style status and body pairs. It releases only allowed or irreversibly sanitized content, maps review, escalation, and block decisions to a contained response, and makes no cloud call in its runnable demonstration.

git clone https://github.com/fusiontechstrategies/Bedrock-Guardrail-Firewall.git
cd Bedrock-Guardrail-Firewall
python examples/stdlib_request_gate.py

Use gate_request at the boundary before an application sends content to a model or returns candidate output to a caller. The request body accepts only prompt and candidate_output; identity, tenant, role, clearance, and authorization values must come from the host's authenticated server-side context through the separate trusted_context argument. Evidence recording is always enabled. The runnable demonstration writes only metadata evidence to a private temporary directory and removes that directory on exit. Regression tests cover sanitization, containment, malformed input, and attempted caller-supplied authorization context.

For a walkthrough of the local privacy checks, optional Bedrock Guardrails call, and fail-closed boundaries, read the AWS Builder Center article.

Why it is different

  • Safe offline default. AWS clients are not created unless live mode is explicitly configured and authorized.
  • Bidirectional inspection. User input, candidate output, and retrieval context are evaluated.
  • Privacy before cloud. Detected sensitive data is sanitized before optional Bedrock Guardrails calls.
  • Local containment before cloud. A local review, escalation, or block decision prevents live content transmission.
  • Post-cloud verification. Bedrock-transformed content is size-checked and re-evaluated by local privacy, policy, and grounding controls.
  • Strongest control wins. A permissive component cannot override a stricter finding.
  • Trusted configuration boundary. Requests cannot select a relaxed policy profile or disable enforcement.
  • Fail-safe production profile. Required security integrations block when disabled or unavailable.
  • Metadata-only evidence. Audit, review, incident, behavior, and metrics stores exclude raw prompt and response text.
  • Tamper evidence. Local audit events form a SHA-256 hash chain with optional AWS KMS signatures.
  • Enterprise review routing. Optional Amazon SQS queues support tiered review workflows.
  • Immutable remote audit support. Optional Amazon S3 Object Lock and KMS encryption protect evidence.
  • Cross-platform operation. The core supports Windows and Linux with Python 3.12 through 3.14. The pinned Presidio stack supports Python 3.12 through 3.13.
  • Built-in validation. Doctor, policy validation, self-test, red-team, chaos, audit verification, and request-preview commands are included.

Control flow

flowchart LR
    A["Input, output, and trusted context"] --> B["Schema and size validation"]
    B --> C["Local privacy detection and redaction"]
    C --> D["Local policy and prompt-attack controls"]
    D --> E["Authorization and grounding checks"]
    E --> F["Optional Bedrock ApplyGuardrail"]
    F --> G["Risk and strongest-action decision"]
    G --> H["Safe response"]
    G --> I["Metadata-only audit, review, incident, and metrics"]

Reproducible sanitized demo

The six-case fixture is a source-checkout walkthrough, independent of the package-only quick start above.

Windows PowerShell:

git clone https://github.com/fusiontechstrategies/Bedrock-Guardrail-Firewall.git
Set-Location Bedrock-Guardrail-Firewall
py -3 -m venv .venv
$env:TMPDIR = $env:LOCALAPPDATA
.\.venv\Scripts\python.exe -m pip install .
.\.venv\Scripts\python.exe examples\run_sanitized_demo.py

On Linux or macOS, use python3 -m venv .venv, then run .venv/bin/python -m pip install . and .venv/bin/python examples/run_sanitized_demo.py from the cloned repository.

The fixture uses disabled cloud integrations, emits no raw high-risk fixture values, and exits nonzero if a decision regresses. Its current deterministic baseline is:

  • 6 of 6 expected decisions matched
  • 4 of 4 high-risk cases contained
  • 0 evaluation-time Python socket attempts

The runner denies Python socket creation, connection helpers, and name-resolution APIs during evaluation. Runtime imports occur before that guard, and the process-level guard does not replace host, container, or virtual-machine network isolation.

The cases cover an ordinary request, redaction, a synthetic identifier, instruction manipulation, prohibited harm, and an unsupported grounded response. Review the fixture and runner before adapting them to a deployment.

Optional integrations

Install only what the deployment requires. A package installation can add the AWS integration without a source checkout:

python -m pip install "bedrock-guardrail-firewall[aws]"

For the complete pinned Presidio path, clone the repository into a separate source environment and use its reviewed requirements file:

git clone https://github.com/fusiontechstrategies/Bedrock-Guardrail-Firewall.git
cd Bedrock-Guardrail-Firewall
python -m venv .venv
python -m pip install -r requirements-presidio.txt
python -m pip install .

The aws and presidio package extras install their Python libraries. Presidio is supported on Python 3.12 through 3.13. Its English model is intentionally kept in the pinned requirements-presidio.txt source-install path because public package indexes should not accept direct URL dependencies in published project metadata. The runtime never downloads a missing spaCy model. Run doctor after installation; readiness fails when the selected mode or profile requires Presidio and its model is unavailable.

The dependency groups are deliberately separated:

File Purpose
requirements.txt Standard-library core, no runtime packages
requirements-aws.txt Amazon Bedrock, KMS, S3, and SQS integration
requirements-presidio.txt Microsoft Presidio and the pinned English NLP model
requirements-dev.txt Testing, linting, static analysis, and dependency auditing
requirements-build.txt Pinned distribution build and validation tools

Published distributions are listed in the PyPI release history. For a version-pinned installation, use python -m pip install bedrock-guardrail-firewall==4.1.2 once that version is listed. For a first offline check, run bedrock-guardrail-firewall --presidio-mode disabled doctor. GitHub releases provide the matching SHA-256 checksums, SPDX 2.3 SBOM, and release evidence.

Release candidates use exact version, archive, metadata, SPDX 2.3 dependency SBOM, SHA-256, provenance, and trusted-publisher gates documented in RELEASING.md. Manual candidate runs cannot publish. Publishing requires an approved GitHub release and approval through the protected pypi environment.

AWS safety modes

Mode Network behavior Intended use
disabled No AWS calls and no AWS client creation Local development, tests, and isolated environments
preview Produces redacted request shapes with no AWS calls Integration review and change approval
live Calls configured AWS services Authorized deployments only

The CLI requires both --aws-mode live and --enable-live-aws. This two-part gate helps prevent an accidental cloud call. Automated tests use mocks and never require AWS credentials.

Decision actions

The runtime returns one of five actions:

Action Meaning
allow No configured control produced a finding
sanitize Sensitive or policy-controlled content was irreversibly redacted
queue_for_review A human decision is required before higher-risk use
escalate Urgent review is required and capabilities are disabled
block Processing must stop

In monitor mode, action remains allow for observation, while recommended_action and capabilities still reflect the security decision.

Sanitized content is released only for allow and sanitize recommendations. Review, escalation, and block recommendations return empty content fields with content_released: false, including in monitor mode.

Library example

from bedrock_guardrail_firewall import BedrockGuardrailSystem, RuntimeConfig

config = RuntimeConfig.from_env(presidio_mode="disabled", aws_mode="disabled")
firewall = BedrockGuardrailSystem(config)
decision = firewall.process(
    "Summarize the approved release checklist.",
    {},
    record=False,
)
print(decision["recommended_action"])

Direct one-file execution keeps relative policy, profile, and state paths anchored to the source file directory, preserving the portable source behavior. Installed-package execution resolves explicitly supplied relative paths from the process working directory. The installed defaults use policy documents inside the package and .guardrail-data in the working directory.

Policy profiles

  • balanced provides strong local controls with optional Presidio and AWS integration.
  • production requires both Presidio and live Bedrock Guardrails, and fails closed when either control is unavailable.
  • offline_test is reserved for deterministic test execution.

Profiles are selected by trusted deployment configuration. A caller cannot choose a profile in request content.

Where it fits and where it does not

Use this project as a policy enforcement point around application traffic. It is not a network firewall, web application firewall, IAM system, malware scanner, factuality oracle, or replacement for human approval. A caller must honor the returned action, content-release flag, and capability restrictions.

The offline regex controls are deliberately deterministic and narrower than contextual PII analysis. The optional Presidio stack improves entity recognition but must be installed and verified separately. Local grounding is a lexical support signal, not proof that an answer is true. Live AWS mode can transmit locally sanitized content to the configured Amazon Bedrock Guardrail and must be approved for the workload's data-handling requirements.

Read the threat model and deployment guide before production use.

Tested baseline

  • 218 automated tests across the core, AWS SDK contract, Presidio integration, release validation, and sanitized demo
  • 85 percent branch-aware line coverage
  • 100 percent containment in the built-in 10-case adversarial suite
  • 100-round deterministic mutation test completed
  • Current Windows remediation run: 216 tests passed, with two optional integrations skipped. Dedicated CI jobs separately validate pinned AWS and Presidio integrations
  • Wheel and source-distribution build, metadata, clean-environment install, console entry point, packaged policy resources, and library import checks
  • Six-case sanitized adoption fixture with 100 percent expected decisions and high-risk containment
  • Native Windows validation for the 4.1.0 candidate completed on Python 3.10 through 3.14; the exact release-readiness tree also passed the complete hosted Windows and Linux matrix
  • Mocked Bedrock INPUT and OUTPUT calls, grounding qualifiers, anonymization, interventions, and failure paths
  • Audit-chain verification and tamper detection
  • Ruff formatting and lint checks
  • Bandit static-security scan with no medium or high findings
  • Point-in-time audits reported no known advisories for the pinned, resolvable dependency sets at validation time; vulnerability data and audit coverage can change
  • Gitleaks secret scanning

See Testing for the complete verification model.

Documentation

Security notes

This project is a defense-in-depth control, not a replacement for IAM, network isolation, data classification, secure model selection, human oversight, or an organizational authorization process. Local grounding is a deterministic lexical signal, not a proof of truth. Review the threat model and tune policy to the deployment.

Live AWS mode can transmit sanitized content to the configured Amazon Bedrock Guardrail. Review applicable data-handling requirements before enabling it.

License

Licensed under the Apache License 2.0. See LICENSE.

Amazon Web Services, AWS, Amazon Bedrock, and related marks are trademarks of Amazon.com, Inc. or its affiliates. Microsoft and Presidio are trademarks or projects of Microsoft. This independent project is not endorsed by or affiliated with Amazon or Microsoft.

Metadata

Release files for bedrock-guardrail-firewall 4.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bedrock-guardrail-firewall 4.1.2
File Size Uploaded Provenance Actions
bedrock_guardrail_firewall-4.1.2.tar.gz 227.8 kB With provenance Details for bedrock_guardrail_firewall-4.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for bedrock-guardrail-firewall 4.1.2
File Interpreter ABI Platform Actions
bedrock_guardrail_firewall-4.1.2-py3-none-any.whl Python 3 none any Details for bedrock_guardrail_firewall-4.1.2-py3-none-any.whl

Total release size: 298.7 kB

Release files / bedrock_guardrail_firewall-4.1.2.tar.gz

Download URL bedrock_guardrail_firewall-4.1.2.tar.gz
Size 227.8 kB
Tags Source
SHA-256 checksum
How to use checksums
63b1f3eac9c93be723610bb1cbc0d6cfaea55a977adec478b787b7211e062c85
BLAKE2b-256 checksum
How to use checksums
23f52f93cae24bbe93c906996f5aaa60974b477461f5d1b294b0f06e9cefcdbb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

Release files / bedrock_guardrail_firewall-4.1.2-py3-none-any.whl

Download URL bedrock_guardrail_firewall-4.1.2-py3-none-any.whl
Size 70.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
61a073a4041206ef5facfee7ed23fbc5e74928e27d5c9995b4a0fefd076d82b8
BLAKE2b-256 checksum
How to use checksums
caf657dd6ab9e89aa11ee6bddab8988a1b46436127514d9a7b62c6562d933e29
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

Security for bedrock-guardrail-firewall 4.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for bedrock_guardrail_firewall-4.1.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page