Skip to main content

qadiya (قضية) — Classify + Dispatch under Constraint-Driven Cases

Part of the Mizan stack — the Arabic-first reliability scale for AI agents.

License: MIT Python 3.10+ Tests: 15 passing

The third + fourth primitives of the reversible-agent-operations pattern: case classification under a constraint set, and dispatch to registered procedures.


What it does

Given a list of constraints (e.g., "operation type", "target scope", "reversibility"), qadiya enumerates the Cartesian product of constraint values, prunes infeasible combinations, and gives you a registry. You register one procedure per surviving case. dispatch() classifies an incoming input by evaluating constraints, then runs the registered procedure for the matching case. If no case matches, it raises — never silently falls through to a "general" handler.

from qadiya import Constraint, CaseRegistry, Dispatch

c_op = Constraint("op", values=("read", "write"),
                   evaluate=lambda r: r["op"])
c_target = Constraint("target", values=("user_file", "system_file"),
                       evaluate=lambda r: r["target"])
c_in_repo = Constraint("in_repo", values=(True, False),
                        evaluate=lambda r: r["in_repo"])

# Pruning: writes outside the repo are infeasible (escalate path)
def feasible(d):
    return not (d["op"] == "write" and not d["in_repo"])

reg = CaseRegistry(constraints=[c_op, c_target, c_in_repo], feasible=feasible)

# 2 × 2 × 2 = 8 combinations; pruning leaves 6
assert reg.case_count() == 6

# Register a procedure for every surviving case
for case in reg.cases:
    reg.register(case.case_id, make_handler_for(case))
reg.verify_complete()  # raises if any case is unhandled

dispatch = Dispatch(registry=reg)
result = dispatch({"op": "read", "target": "user_file", "in_repo": True})
# DispatchResult(outcome=DISPATCHED, case_id="op=read|target=user_file|in_repo=True", output=...)

Why this is the missing primitive

Agent frameworks have intent routers, skill registries, and tool-call dispatchers. They lack the constraint-driven enumeration step. With qadiya:

  • Cases are generated, not invented. The constraint Cartesian product produces a complete, verifiable enumeration.
  • Infeasible combinations are explicitly pruned, not silently merged with feasible ones.
  • Every case must be registered or escalated — verify_complete() raises if any case is unhandled. There is no implicit "default fallback procedure."
  • Classification is deterministic — same input always maps to the same case_id.

Properties

  1. Determinism — same input → same case_id every time.
  2. Completeness verification — verify_complete() ensures no case is silently dropped.
  3. Explicit escalation — cases that should not run automatically must be marked with .escalate(). Silent fallback is forbidden.
  4. No generation outside procedures — qadiya itself produces no value. It only routes inputs to registered procedures.

Install

pip install -e .

Tests

pytest tests/ -v

15/15 pass on Python 3.10+, including a worked end-to-end example with 4 binary constraints, feasibility pruning, complete coverage verification, and round-trip dispatch.

How it composes with jabr and muqabalah

The three libraries form the four primitives of the pattern:

input
  │
  ▼
jabr.restore()      ← Restore: insert missing terms (al-jabr)
  │
  ▼
muqabalah.balance() ← Balance: cancel duplicates, fail-loud on contradictions
  │
  ▼
qadiya.classify()   ← Classify: which canonical case is this?
  │
  ▼
qadiya.dispatch()   ← Dispatch: run the registered procedure for that case
  │
  ▼
output

Each stage is reversible (where applicable), audited, and independently testable. Together they implement the discipline: every transformation an agent performs is a Restore, a Balance, or a Dispatch; every Restore and Balance preserves the original meaning recoverably; every Dispatch is the only place new value is created.

Failure modes

See FAILURES.md.

License

MIT.

Metadata

Release files for qadiya 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for qadiya 0.1.0
File Size Uploaded Provenance Actions
qadiya-0.1.0.tar.gz 9.8 kB With provenance Details for qadiya-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for qadiya 0.1.0
File Interpreter ABI Platform Actions
qadiya-0.1.0-py3-none-any.whl Python 3 none any Details for qadiya-0.1.0-py3-none-any.whl

Total release size: 18.3 kB

Release files / qadiya-0.1.0.tar.gz

Download URL qadiya-0.1.0.tar.gz
Size 9.8 kB
Tags Source
SHA-256 checksum
How to use checksums
e68942207ab2bedcf2a54572d2705241b1515721451d9997e55f4e2697c82394
BLAKE2b-256 checksum
How to use checksums
8aca6484e1034d3fef854c4da07ba4dccacfe70072a17030e85e9a39c3042a94
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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 Jun 1, 2026.

Transparency log

Release files / qadiya-0.1.0-py3-none-any.whl

Download URL qadiya-0.1.0-py3-none-any.whl
Size 8.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4b1c411c451a93ccb84f681bcc03cc6ec5a737c1e5b6a9622545105fef92834e
BLAKE2b-256 checksum
How to use checksums
fa3a516cccf99e8dc1f1306cff0d5df836892831116fb8cf7f5c06b892e257e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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 Jun 1, 2026.

Transparency log

Security for qadiya 0.1.0

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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for qadiya-0.1.0.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 Jun 1, 2026.

Transparency log

A 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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page