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.
Position in the Stack
execution-without-normativity
-> dbl-core
-> dbl-policy
-> dbl-policy-gates
-> domain policies
dbl-policy defines the contract for policy decisions.
dbl-policy-gates defines the algebra used to assemble them.
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.
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
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)
Included Gates
RequireMatchOneOfBoundTenantAllowDenyChainAnyOfInvert
Chain and AnyOf require at least one child gate. Empty combinators are
rejected at construction time.
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.
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.0.tar.gz.
File metadata
- Download URL: dbl_policy_gates-0.1.0.tar.gz
- Upload date:
- Size: 9.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2cec21b8b4ae56c6c61ae3f9d334c01234567c0adeae85d34ceb5ce6427c8271
|
|
| MD5 |
69294204d1b492d25a293b89f6e5a3db
|
|
| BLAKE2b-256 |
31101764596c2fc9b038f6b13ae02f5530c8ebdfcb097537eab4a0a4de2bd970
|
File details
Details for the file dbl_policy_gates-0.1.0-py3-none-any.whl.
File metadata
- Download URL: dbl_policy_gates-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.1 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 |
5d94e4cb37a5034c23f5d94d37e1f8348a0c9423d1eea11be439b90b6dd7540f
|
|
| MD5 |
a6e321d0af6840c590e95b5618fb749c
|
|
| BLAKE2b-256 |
c519573eff44384cc60beefaf94923ef8b443ca13287a45a6c2f2973348924a9
|