Skip to main content

Cogniform

Learn how an expert decides, not just what they answer.

Cogniform is a zero-dependency Python SDK for learning portable, inspectable decision policies from structured expert demonstrations. It learns a decision tree by information gain, exposes the conditions behind each prediction, and abstains when it encounters uncertainty or out-of-domain values. Optional LLM adapters convert natural-language situations into structured facts before the policy runs.

Version 0.1.0 is an alpha release candidate. It is not a foundation model, cognitive emulator, or guarantee of expert judgment. It has not been validated on real-world expert datasets. The name and public registry availability must be confirmed at publication.

Install

After the package is published to PyPI:

pip install cogniform

Until then, install from the source directory:

git clone https://github.com/AMallur/Cogniform.git
cd Cogniform
python -m pip install .

Python 3.10+; no required runtime dependencies.

60-second quickstart

from cogniform import Judgment

examples = [
    {"facts": {"risk": "low", "missed_deadlines": 0}, "decision": "continue"},
    {"facts": {"risk": "low", "missed_deadlines": 1}, "decision": "continue"},
    {"facts": {"risk": "high", "missed_deadlines": 0}, "decision": "escalate"},
    {"facts": {"risk": "high", "missed_deadlines": 1}, "decision": "escalate"},
]

expert = Judgment.learn(examples)
result = expert.apply({"risk": "high", "missed_deadlines": 1})
print(result.decision)      # escalate
print(result.evidence)      # observed facts and learned branch conditions
print(result.uncertainty)   # 1 - observed leaf class proportion, not calibrated risk
expert.save("supplier.json")

Each example is an expert's observed situation and selected action. Facts are finite JSON scalars (strings, numbers, booleans, null). Optional rationale text is accepted as a note in demonstrations; v0.1 does not learn from rationale text. Use domain-specific features and obtain consent to collect expert data.

How the engine works

  1. Learn candidate conditions on observed categories and numeric values.
  2. Rank splits by information gain and fit a bounded-depth decision tree.
  3. Follow the learned policy for a new situation, returning evidence and empirical class proportions.
  4. Abstain on ties, low support, low confidence, incompatible required facts or unseen observed values in strict mode. Missing values may follow a branch explicitly learned from missing examples.
  5. Export the profile as versioned JSON; share it across applications and model providers without retraining.

Numeric split thresholds use the lower observed value, not an inferred exact expert threshold. Strict mode (default) rejects supplied in-schema feature values outside the observed numeric range or categorical vocabulary. It does not detect every out-of-distribution combination. Unknown feature keys supplied directly are ignored by the policy. Use strict=False to permit extrapolation deliberately. Uncertainty is an empirical impurity measure, not calibrated probability. Human review is needed for high-impact decisions.

Natural language input

from cogniform import Judgment, OpenAIModel
from openai import OpenAI

expert = Judgment.load("supplier.json")
model = OpenAIModel(OpenAI(), model="YOUR_MODEL_ID")
result = expert.apply("Risk is high; the supplier missed one deadline.", model=model)
print(result.decision)

Install openai or anthropic yourself if using their client. AnthropicModel(client, model=...) and CallableModel(fn) are also available. A callable takes (system_prompt, user_prompt) and returns JSON text. Models are only used for fact extraction; they do not choose the decision. Extracted JSON is type-checked, but a model can still omit or hallucinate facts despite the prompt. Review extracted evidence when accuracy matters. Text and schema are sent to your configured model provider; direct structured prediction is entirely local. No telemetry is included.

Evaluation and audit

from cogniform import evaluate, split_demonstrations, Judgment
import json

rows = json.load(open("examples/demonstrations.json"))
train, test = split_demonstrations(rows, seed=42)
profile = Judgment.learn(train)
report = evaluate(profile, test)
print(report.accuracy, report.coverage, report.selective_accuracy)
print(report.baseline_accuracy)
print(profile.rules())

Accuracy counts abstentions as unsuccessful cases; coverage is the fraction answered; selective accuracy is accuracy among answered cases, or None if none are answered. The baseline is the training set majority class. Duplicate fact vectors are grouped together for the split; correlated or near-duplicate observations can still leak, so use external validation when possible. Avoid tuning against the final held-out set.

Run the included synthetic supplier benchmark:

python examples/demo.py

It contains 28 training cases and 12 disjoint held-out cases generated from a known simple policy. It is a functionality demonstration, not evidence of performance on human experts or production data.

CLI

cogniform learn examples/demonstrations.json -o supplier.json
cogniform rules supplier.json
cogniform apply supplier.json examples/situation.json
cogniform evaluate supplier.json examples/heldout.json

Use --max-depth, --min-leaf, --min-confidence, and --min-support with learn. Use --allow-extrapolation with apply or evaluate to disable observed-domain checks. Each command outputs JSON. A profile ID is derived from its serialized contents for version tracking. Profiles contain derived training statistics and category values; review them before sharing.

Development

python -m pip install -e . pytest
python -m pytest -q
python examples/demo.py

CI tests the supported Python versions and builds distributions. The release workflow runs tests, builds distributions, validates metadata, and publishes via PyPI Trusted Publishing only when manually triggered and authorized. See PUBLISHING.md.

Metadata

Release files for cogniform 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 cogniform 0.1.0
File Size Uploaded Provenance Actions
cogniform-0.1.0.tar.gz 16.0 kB With provenance Details for cogniform-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 28.4 kB

Release files / cogniform-0.1.0.tar.gz

Download URL cogniform-0.1.0.tar.gz
Size 16.0 kB
Tags Source
SHA-256 checksum
How to use checksums
77def03e68410202e144e3f106afc1ccbf7a7618ace62570ecae8520aa7d31f8
BLAKE2b-256 checksum
How to use checksums
96f5578fe21d774b1b6c7211d200cf8708a2562d74fe219712d98e4098ac44e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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

Transparency log

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

Download URL cogniform-0.1.0-py3-none-any.whl
Size 12.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a0352e1db86498a74b208475f453b36caf7c6a697a9699daa498f716cd90d643
BLAKE2b-256 checksum
How to use checksums
5460ec3491befe7df93b56457255c2db1cc136bd46ec156892c0879e2019c5b2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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

Transparency log

Security for cogniform 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 cogniform-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 Dec 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