Deterministic gate algebra for dbl-policy
Project description
dbl-policy-gates
Deterministic gate algebra for dbl-policy.
This package provides the primitive gate operations used to build governance functions. It does not execute tasks, emit events, or observe runtime artifacts.
Why this exists
If dbl-policy defines the contract for a decision, dbl-policy-gates
defines the algebra used to build one.
That is the whole split:
dbl-policyanswers: what is a policy decision?dbl-policy-gatesanswers: how is governance logic assembled?
This package models governance as a deterministic function over authoritative inputs:
decision = f(inputs)
The result is replayable, comparable, and structurally describable.
execution-without-normativity shows that execution can exist without governance.
dbl-policy-gates shows how governance can be made composable, replayable, and structurally comparable.
Position in the Stack
execution mechanics
-> dbl-core
policy contract
-> dbl-policy
policy algebra
-> dbl-policy-gates
domain policies
dbl-policy defines the contract for policy decisions.
dbl-policy-gates defines the algebra used to assemble them.
Execution happens first. Policies are assembled here.
Model
There are two layers in this package:
Gate: deterministic structure that evaluates to a gate-local decisionRootPolicy: wrapper that stamps a gate decision into adbl_policy.model.PolicyDecision
This split is intentional. Gates remain anonymous structure; only the root
policy carries policy_id and policy_version.
This is not a rule engine. It is a deterministic decision structure composed from small primitives.
Install
pip install dbl-policy-gates
Requires Python 3.11+ and dbl-policy>=0.3,<0.4.
Quickstart
from dbl_policy.model import PolicyId, PolicyVersion, PolicyContext, TenantId
from dbl_policy_gates import Bound, Match, RootPolicy, chain, tree_payload
root = RootPolicy(
policy_id=PolicyId("chat.guardrails"),
policy_version=PolicyVersion("1.0.0"),
root=chain(
Match("capability", "chat", label="chat_capability"),
Bound("max_output_tokens", 1, 4096, label="output_token_limit"),
),
)
ctx = PolicyContext(
tenant_id=TenantId("tenant-1"),
inputs={"capability": "chat", "max_output_tokens": 512},
)
decision = root.evaluate(ctx)
viewer = tree_payload(root)
viewer is a deterministic tree payload derived from describe(). It is
intended for policy viewers and inspector UIs, not for evaluation.
Included Gates
RequireMatchOneOfBoundTenantAllowDenyChainAnyOfInvert
Chain and AnyOf require at least one child gate. Empty combinators are
rejected at construction time.
Example building blocks:
Match("capability", "chat")Bound("max_output_tokens", 1, 4096)Tenant({"tenant-1", "tenant-2"})
These can be combined into larger governance functions with chain(...),
any_of(...), and invert(...).
Describe and Drift
Every gate implements describe().
Use describe_digest(gate) to get a stable SHA-256 digest of the canonical gate
description. This is intended for drift detection and replay tooling.
This makes governance comparable as structure, not just as runtime behavior.
Viewer Payload
Use tree_payload(root_policy) to project a policy tree into a viewer-friendly
payload with:
digest- structural
path - gate
kind - optional
label - gate
meta - ordered
children
See docs/POLICY_VIEWER.md for the architecture and payload contract.
Structured Reason Detail
Gates produce structural reason_code values such as:
gate.bound.above:max_output_tokens
When a RootPolicy converts a gate denial into PolicyDecision, the gate
detail dict is serialized into canonical JSON for reason_message.
Example:
{"actual":5000,"hi":4096,"key":"max_output_tokens","label":"output_token_limit"}
Development
python -m venv .venv
.venv\Scripts\Activate.ps1
python -m pip install -e ".[dev]"
pytest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dbl_policy_gates-0.1.2.tar.gz.
File metadata
- Download URL: dbl_policy_gates-0.1.2.tar.gz
- Upload date:
- Size: 11.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cd48d98598efafb8beaee3381fedb37777c53f273ccec0e59c00dc158a31bfc0
|
|
| MD5 |
f89898ac3ec8c409e6639e193573f8b8
|
|
| BLAKE2b-256 |
45329f0f1c0cdfaf865539bb156216f5d66bdaa1a2916480a82001002b9b7112
|
File details
Details for the file dbl_policy_gates-0.1.2-py3-none-any.whl.
File metadata
- Download URL: dbl_policy_gates-0.1.2-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a69b6cf796e7d38d520e4bae3889bfb16df56b6265aa42bd8a92537c798a432
|
|
| MD5 |
2ad73af2e153815a17b371089ddf9d29
|
|
| BLAKE2b-256 |
9af94b0499bee4ed6a9dbd045fb00651670569960f6f3a5d381089a61cbd79ec
|