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.1.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.1-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file dbl_policy_gates-0.1.1.tar.gz.

File metadata

  • Download URL: dbl_policy_gates-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 a8ecca030368295297e09aebe216402339b99f00c505e4d3225a3a432cb5c215
MD5 e765be0a6e51c082132b93ed789922ce
BLAKE2b-256 0ce2aee885eedb70f796a4026ac29a49a7c209f9297cc39252dae8aba87f8f13

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for dbl_policy_gates-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9d1377fa91724d6b404b43c0f3fb560628305c2ed5ea9dece10355405f49b322
MD5 069669fcc708126dc04037c28837aa48
BLAKE2b-256 1d40f2be1052bc5aa6eb35ddeabee39abe178d03a136cb41c6eb2b1ba716dac6

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