kbound
Inductive rule recovery toolkit. Give it K observations, get back the rule plus a sample-complexity certificate.
pip install kbound
from kbound import recover_rule
# Five observations from a deterministic system
observations = [(1, 15), (2, 18), (3, 12), (4, 16), (5, 11)]
r = recover_rule(observations)
r.rule # 'decision(x) = (5·x² + 7·x + 3) mod 19'
r.confidence # 1.0
r.verified # True
r.predict(42) # 16 (extrapolates over the recovered rule)
r.certificate # {'k_used': 5, 'k_lower_bound': 4, 'margin': 1.25, ...}
That is the whole API for the common case. No prompt tuning, no training, no LLM call.
What it does
Given K ≥ 4 input/output pairs from any deterministic system — an AI agent, a smart contract, a legacy decision rule, a math problem — kbound:
- Classifies the geometric structure of the rule (spatial-separable vs. algebraically-coupled).
- Detects which family it belongs to from a 16-operator catalog (linear residual, polynomial threshold, modular exponentiation, Boolean gate, k-bit parity, linear recurrence, …).
- Recovers the parameters via the matching solver — Boyar's attack for LCGs, Vandermonde solve over
F_pfor polynomials, GF(2) elimination for additive-feedback generators, and so on. - Verifies the recovered rule reproduces every observation, then emits a certificate with
K_used, the family-specificK_lower_bound, and the safety margin.
If nothing in the catalog matches, it returns RecoveryResult(no_recovery, …) — honest failure, no hallucination.
How it compares
| What it does | When kbound wins | |
|---|---|---|
| SymPy | Manipulates a formula you give it (solve, simplify, integrate). | When you do not have the formula yet — only observations. |
| DreamCoder / general program synthesis | Open-ended program search via library learning. | When the rule fits a known algebraic family — kbound is O(K) to seconds, DreamCoder is minutes to hours. |
| Z3 / SMT | Constraint satisfaction over a manually-encoded theory. | When you want push-button recovery without writing the encoding. (kbound uses Z3 internally for the bitwise non-linear class.) |
| LLM K-shot induction | Few-shot prompt: "given these examples, what's f(x)?" |
When the rule is algebraically coupled: frontier LLMs hit ~0.02 accuracy on lcg_mod50 at K=16 in-context (Dovzak 2026). kbound hits 1.00. |
Use cases
- Build deterministic copilots for AI agents: drop
kbound-mcpin as an MCP server; agents (Claude Desktop, Cursor, Cline, …) now answer K-shot induction questions correctly instead of hallucinating. See the MCP integration section below. - Audit deployed AI agents: recover the rule the agent is actually following from a trace log; compare against the vendor-declared specification (
kbound.check_compliance); emit auditor-ready Markdown + CSV + remediation SLA. - Cryptanalysis & security research: recover LCG / glibc / Java / MT19937 / TGFSR-additive-feedback / 2-LCG-XOR-composition state from observed outputs, with a sample-complexity bound on the recovery.
- Behavioral diff between system versions:
kbound.diff_traces(v1, v2)surfaces silent rule changes between deployments. - Reverse-engineer legacy decision systems: feed (input, output) pairs from production logs, get back the executable rule.
Operator catalog (16 families, today)
Linear Residual Policy y = (a·x + c) mod m small modulus
Linear Residual (Large-Modulus) y = (a·x + c) mod m unknown m, Boyar 1989
Linear Residual w/ Truncation java.util.Random — top-32 bits of m=2⁴⁸ state
Polynomial Threshold Rule y = (a·x² + b·x + c) mod p small modulus
Polynomial Threshold (Large-Mod) y = polynomial mod arbitrary m, deg 2-3
Cubic Threshold Rule y = (a·x³ + b·x² + c·x + d) mod p
Scaling Residual Rule y = (a·x) mod p
Inverse Residual Rule y = x⁻¹ mod p
Exponential Pattern Rule y = a^x mod p
Additive Composition Rule y = (x₁ + x₂) mod p
Linear Recurrence Policy y_n = (a·y_{n-1} + b·y_{n-2}) mod m
Linear Recurrence (Large-Modulus) order-2 / order-3, arbitrary m
Binary Decision Gate 2-input boolean truth table
k-Bit Parity Rule XOR over a subset of bits
Stateful Pattern (Large State) MT19937 — recovered from K ≥ 624 outputs
Stateful Pattern (Additive Fbk) glibc TYPE_3 — recovered from K ≥ 100 outputs
Each operator has a typical K_lower_bound. The certificate every recovery emits cites it.
Compliance primitive
When the rule is declared by a vendor and you want to audit how often the agent honors it:
from kbound import check_compliance, ClaimedSpec
claimed = ClaimedSpec(
family="linear_residual",
params={"a": 3, "c": 5, "m": 11},
source="vendor system prompt v7.0",
)
report = check_compliance(observations, claimed)
report.agreement_pct # 0.73 — the agent honors the spec 73% of the time
report.counterexamples # first 10 deviations: input, observed, expected
report.is_compliant() # False at default 95% threshold
Render to Markdown, legal-grade CSV, remediation SLA, or AI Bill-of-Materials section:
from kbound import (
render_compliance_report_md,
render_legal_counterexample_csv,
render_remediation_sla,
render_ai_bom_section,
)
The compliance check is the primitive that converts "no rule recovered" into a positive audit finding when you have a declared spec to test against.
MCP integration (Claude Desktop, Cursor, Cline)
kbound ships an MCP server that lets any MCP-aware AI agent call rule recovery as a tool. This closes the gap reported in Dovzak 2026: frontier LLMs hit ~0.02 in-context accuracy on algebraically-coupled K-shot induction; with the MCP server they delegate to a deterministic solver.
pip install kbound[mcp]
Claude Desktop
Add to ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or %APPDATA%\Claude\claude_desktop_config.json (Windows):
{
"mcpServers": {
"kbound": {
"command": "kbound-mcp"
}
}
}
Restart Claude Desktop. Five tools become available: recover_rule_from_observations, predict_under_recovered_rule, list_supported_rule_families, verify_compliance_against_claimed_rule, classify_observation_geometry.
Cursor / Cline
Add to ~/.cursor/mcp.json (Cursor) or your Cline config:
{
"mcpServers": {
"kbound": {
"command": "kbound-mcp",
"args": []
}
}
}
Manual test
You can run the server directly (it speaks JSON-RPC over stdio):
kbound-mcp
# or:
python -m kbound.mcp
For interactive testing, install the MCP Inspector:
npx @modelcontextprotocol/inspector kbound-mcp
Foundations
kbound is grounded in four papers (Dovzak):
- The Compositional Depth Decay is a Dispatch Tax — exponential-decay law fingerprinting architectures' compositional generalization.
- The Geometric Boundary of Few-Shot Rule Induction in Frontier LLMs — measures where commercial LLMs cross from 0.88 accuracy to chance, depending on rule geometry.
- Geometry of Few-Shot Rule Induction — the spatial-separable vs. algebraically-coupled distinction; defines the Relational Consistency Executor (RCE) that kbound implements for the algebraic side.
- A Universal Sample-Complexity Framework for Black-Box Rule Recovery — the master inequality
K ≥ (dim − log|Sym(r)|)/bthat yields the K-bound certificate every recovery cites.
You do not need to read them to use kbound. They are the answer to "is this principled?" rather than "how do I use it?"
Status
v0.1.0 — alpha. The catalog ships 16 operator families, of which 13 are validated end-to-end against real-world trace batteries; 3 are experimental (scaling_residual_rule, inverse_residual_rule, k_bit_parity_rule — recovery works but customer-fit on real data has not been measured). Each operator's status is exposed at kbound.OPERATORS[<key>].validation_status. The MCP server adapter and the full documentation site are in progress. Public API surface (recover_rule, check_compliance, classify_geometry, diff_traces, the renderers) is stable for v0.x.
Roadmap (short):
kbound/mcp.py— MCP server packaging, registered in the public catalog.kbound diffCLI — behavioral diff between trace versions.- Documentation site at
originalkazdov.github.io/kbound. - Continuous benchmark of frontier LLMs vs. kbound across the operator catalog.
Contributing
Issues and PRs welcome. New operators are first-class: see kbound/solvers/ for the solver template plus the operator metadata pattern in kbound/operators.py.
License
MIT.
Metadata
Release files for kbound 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| kbound-0.2.0.tar.gz | 111.5 kB | Without provenance | Details for kbound-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| kbound-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for kbound-0.2.0-py3-none-any.whl |
Total release size: 236.7 kB
Release files / kbound-0.2.0.tar.gz
| Download URL | kbound-0.2.0.tar.gz |
|---|---|
| Size | 111.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
26ff75bad3277537c5d0de7a1acb2e80ef863310b4e6458c830e7bd14e98348e
|
|
BLAKE2b-256 checksum How to use checksums |
4310d29ff8766f71a33008320ca4edcca7391dca8d03b802c7ed2ee3bebc8f63
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Release files / kbound-0.2.0-py3-none-any.whl
| Download URL | kbound-0.2.0-py3-none-any.whl |
|---|---|
| Size | 125.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e936a3ee51eac45ee8bb6fde3fd3ff64e70454f116037ceb13422bbd2c3790ec
|
|
BLAKE2b-256 checksum How to use checksums |
9db838ed22472795c5392e3012d3166bdc110703d60db3f956aff46509065f6f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Security for kbound 0.2.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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.