Policy Foundry
AI-powered firewall policy analysis and recommendation engine. Feed it traffic data and get back validated, risk-assessed firewall rule proposals with change request exports.
Input: Excel traffic exports or VPC Flow Logs (local/S3) Output: Terminal display, JSON, or change request forms (xlsx/pdf)
Traffic Data ──▶ AI Analysis Pipeline ──▶ Change Request
(Excel/Logs) Analyze → Assess → (xlsx / pdf /
Generate → Validate → terminal / JSON)
Decide
Installation
Option 1: Install from PyPI (recommended)
pip install policy-foundry
Option 2: Install with pipx (isolated environment)
pipx install policy-foundry
Option 3: Install with uv
uv tool install policy-foundry
Verify installation
policyfoundry --help
Setup
PolicyFoundry uses an LLM to analyze traffic. You need one of these providers configured:
Using Ollama (free, local, default)
- Install Ollama
- Pull a model:
ollama pull llama3.2
- That's it — PolicyFoundry uses Ollama by default.
Using OpenAI
Set your API key as an environment variable:
export POLICYFOUNDRY_LLM__PROVIDER=openai
export POLICYFOUNDRY_LLM__MODEL=gpt-4o
export POLICYFOUNDRY_LLM__API_KEY=sk-your-key-here
Using AWS Bedrock
export POLICYFOUNDRY_LLM__PROVIDER=bedrock
export POLICYFOUNDRY_LLM__MODEL=anthropic.claude-3-sonnet-20240229-v1:0
Requires AWS credentials configured via aws configure or environment variables.
Using a config file
Create .policyfoundry.yaml in your working directory:
llm:
provider: ollama
model: llama3.2
temperature: 0.1
max_tokens: 4096
timeout: 120
Usage
Analyze an Excel traffic export
policyfoundry analyze --source excel --file traffic.xlsx
Export a change request form
# Excel change request
policyfoundry analyze --source excel --file traffic.xlsx --export xlsx
# PDF change request
policyfoundry analyze --source excel --file traffic.xlsx --export pdf
# Both
policyfoundry analyze --source excel --file traffic.xlsx --export xlsx,pdf
Use a custom change request template
policyfoundry analyze --source excel --file traffic.xlsx \
--export xlsx --template my-template.xlsx
A sample template is included in the repo.
Analyze VPC Flow Logs
# From local files
policyfoundry analyze --source local --sg-ids sg-0123456789abcdef0
# From S3
policyfoundry analyze --source s3 --sg-ids sg-0123456789abcdef0
Get JSON output
policyfoundry analyze --source excel --file traffic.xlsx --format json
View current firewall rules
policyfoundry rules --sg-id sg-0123456789abcdef0
Show resolved configuration
policyfoundry config
CLI Reference
policyfoundry analyze
| Option | Description | Default |
|---|---|---|
--source |
Data source: local, s3, or excel |
local |
--format |
Output format: rich or json |
rich |
--file |
Path to input file (required for excel) |
-- |
--export |
Export: xlsx, pdf, or xlsx,pdf |
-- |
--template |
Custom Excel template for export | -- |
--sg-ids |
Security group IDs to analyze | -- |
--config |
Path to YAML config file | -- |
--debug |
Enable debug output | false |
policyfoundry rules
| Option | Description | Default |
|---|---|---|
--adapter |
Adapter name | aws_sg |
--sg-id |
Security group ID to query | -- |
--format |
Output format: rich or json |
rich |
policyfoundry config
| Option | Description | Default |
|---|---|---|
--format |
Output format: rich or json |
rich |
Configuration
PolicyFoundry merges configuration from multiple sources (highest priority wins):
- CLI flags
- Environment variables (
POLICYFOUNDRY_prefix,__for nesting) - Local YAML (
.policyfoundry.yamlin current directory) - Global YAML (
~/.policyfoundry/config.yaml)
Full config example
llm:
provider: ollama # ollama | openai | bedrock
model: llama3.2
temperature: 0.1
max_tokens: 4096
timeout: 120
sources:
log_paths:
- /var/log/vpc-flow/*.log
# s3_bucket: my-vpc-logs-bucket
# s3_prefix: vpc-flow-logs/
targets:
security_group_ids:
- sg-0123456789abcdef0
excel:
# sheet_name: null
# header_row: 1
output:
format: rich
data_dir: ~/.policyfoundry/data
Environment variable examples
export POLICYFOUNDRY_LLM__PROVIDER=openai
export POLICYFOUNDRY_LLM__MODEL=gpt-4o
export POLICYFOUNDRY_LLM__API_KEY=sk-...
export POLICYFOUNDRY_SOURCES__S3_BUCKET=my-vpc-logs
export POLICYFOUNDRY_TARGETS__SECURITY_GROUP_IDS=sg-abc123,sg-def456
Docker
Run PolicyFoundry with an Ollama sidecar:
docker compose up -d
docker compose exec ollama ollama pull llama3.2
docker compose run policyfoundry analyze --source excel --file /path/to/traffic.xlsx
Contributing
Build from source
git clone https://github.com/vahagn-madatyan/PolicyFoundry.git
cd PolicyFoundry
# Install uv if you don't have it
curl -LsSf https://astral.sh/uv/install.sh | sh
# Install with dev dependencies
uv sync --group dev
# Run from source
uv run policyfoundry --help
Run tests
uv run pytest
uv run pytest --cov=policyfoundry
uv run pytest -k "test_analyze"
Project structure
src/policyfoundry/
├── main.py # CLI app (analyze, rules, config)
├── adapters/ # Firewall vendor adapters (AWS SG, etc.)
├── analysis/ # Traffic analysis & aggregation
├── config/ # Configuration management
├── ingestion/ # Data ingestion (local, S3, Excel)
├── pipeline/ # AI analysis pipeline (LangGraph)
├── storage/ # Parquet persistence + DuckDB queries
├── output/ # Terminal & JSON formatters
└── export/ # Change request export (xlsx/pdf)
Architecture
PolicyFoundry runs a 5-stage AI pipeline built on LangGraph:
| Stage | Purpose |
|---|---|
| Analyze | Examine traffic patterns, identify flows, detect anomalies |
| Assess | Evaluate risk levels, flag high-risk flows |
| Generate | Produce concrete firewall rule proposals |
| Validate | Check proposals against adapter constraints (e.g., AWS SG limits) |
| Decide | Final accept/modify/reject decisions with justifications |
LLM calls use Instructor + LiteLLM for structured output — every call returns a validated Pydantic model, not free-form text.
Adapter system
Firewall adapters are loaded via Python entry points. The included AWS Security Group adapter validates against AWS-specific constraints (allow-only rules, 60-rule limit, CIDR validation). All adapters are wrapped in a read-only safety layer — PolicyFoundry never modifies live firewall rules.
Infrastructure (optional)
The infra/terraform/ directory contains Terraform for a test environment (VPC, security groups, S3 bucket, flow logs):
cd infra/terraform
terraform init
terraform plan -var="name_prefix=policyfoundry-dev"
terraform apply
License
Metadata
Release files for policy-foundry 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| policy_foundry-0.2.2.tar.gz | 3.1 MB | With provenance | Details for policy_foundry-0.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| policy_foundry-0.2.2-py3-none-any.whl | Python 3 | none | any | Details for policy_foundry-0.2.2-py3-none-any.whl |
Total release size: 3.2 MB
Release files / policy_foundry-0.2.2.tar.gz
| Download URL | policy_foundry-0.2.2.tar.gz |
|---|---|
| Size | 3.1 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5520c376c12da63779795646741d4bfa368518b0964a77991fa93be6933a8efb
|
|
BLAKE2b-256 checksum How to use checksums |
0e93531201332aa2abb391c127644a4c27f6e2fb029dce9a397d3f0d01f39428
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Mar 27, 2026.
Transparency logRelease files / policy_foundry-0.2.2-py3-none-any.whl
| Download URL | policy_foundry-0.2.2-py3-none-any.whl |
|---|---|
| Size | 110.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
65e1ce956673938a360ab8d3a7a24d972029da3bf78530c564486dfd0c69fd8a
|
|
BLAKE2b-256 checksum How to use checksums |
661134042cb6048382a8a021244bf1f6496556fe34f0685d8954efcddec38f2a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Mar 27, 2026.
Transparency logSecurity for policy-foundry 0.2.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
All 2 files in this release have been uploaded with provenance metadata.
Attestation for policy_foundry-0.2.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 Mar 27, 2026.
Transparency logA 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.