Skip to main content

Deterministic gate algebra for dbl-policy

Project description

dbl-policy-gates

Tests PyPI Python >=3.11 Typing: Typed

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 decision
  • RootPolicy: wrapper that stamps a gate decision into a dbl_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

  • Require
  • Match
  • OneOf
  • Bound
  • Tenant
  • Allow
  • Deny
  • Chain
  • AnyOf
  • Invert

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dbl_policy_gates-0.1.0.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dbl_policy_gates-0.1.0-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

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

Hashes for dbl_policy_gates-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2cec21b8b4ae56c6c61ae3f9d334c01234567c0adeae85d34ceb5ce6427c8271
MD5 69294204d1b492d25a293b89f6e5a3db
BLAKE2b-256 31101764596c2fc9b038f6b13ae02f5530c8ebdfcb097537eab4a0a4de2bd970

See more details on using hashes here.

File details

Details for the file dbl_policy_gates-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for dbl_policy_gates-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5d94e4cb37a5034c23f5d94d37e1f8348a0c9423d1eea11be439b90b6dd7540f
MD5 a6e321d0af6840c590e95b5618fb749c
BLAKE2b-256 c519573eff44384cc60beefaf94923ef8b443ca13287a45a6c2f2973348924a9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page