Skip to main content

ManifoldGuard reference-bounded output regulator utilities

Project description

ManifoldGuard

ManifoldGuard banner

Rebrand note: ManifoldGuard is the public package/product name for the project previously published as mbt-ai-tools. The mbt_ai_tools import path and mbt-check / mbt-eval CLI aliases remain available for compatibility.

Offline regression tests Docs and manifest quality Package build

ManifoldGuard tests whether AI candidate outputs remain inside a supplied semantic and relational reference manifold.

It runs at inference time:

  • no training
  • no fine-tuning
  • no model-weight inspection
  • no hidden classifier

The regulator checks candidate outputs and either emits the safest supported candidate or blocks when every candidate is unsafe.

Core Claim

ManifoldGuard treats hallucination as semantic or relational drift from supplied reference structure. It is not a fact oracle and does not claim direct access to external truth.

Universe does facts.
Humans describe the universe.
AI describes human descriptions.
ManifoldGuard regulates AI descriptions against supplied human reference structure.

Supported public claim:

ManifoldGuard v11 blocked hallucinated AI outputs against supplied reference manifolds
and relation constraints. In the frozen EXP20 ledger, it achieved confusion
[[97, 0], [0, 160]] over 257 labelled candidates across 53 cases.

Claims and Scope

See CLAIMS.md for the claim register. The short version: ManifoldGuard regulates outputs against supplied references and the public offline corpus; it is not claimed to be a universal fact checker.

Continuous integration for the offline corpus lives in .github/workflows/tests.yml.

Current Locked Result

Frozen ledger:

MBT5_EXP20_combined_guarded_master_ledger_v11

Candidates: 257
Cases:      53

Candidate-level confusion:
[[TN, FP], [FN, TP]]
[[97, 0], [0, 160]]

Accuracy:   1.0000
Precision:  1.0000
Recall:     1.0000
F1:         1.0000

Case-level:
Correct: 53 / 53
Emitted: 28
Blocked: 25

The current public claim is limited to the supplied test suites and reference manifolds included in the project.

What ManifoldGuard Checks

ManifoldGuard combines:

  • semantic geometry
  • internal consistency scoring
  • token-level shock analysis
  • literal drift guards
  • entity, number, and unit protection
  • overclaim detection
  • copular relation checks
  • non-copular relation checks
  • relation polarity checks
  • unsupported negation clamps
  • abstention when every candidate is unsafe

Examples of blocked drift:

The capital of France is London.
The Sun is a planet.
Earth is flat.
Water boils at 90 degrees Celsius at sea level.
Gravity is fully solved by modern physics.
Scientific descriptions do not use measurements.
DNA contains the nucleus.
The Sun orbits Earth.

Core Mechanisms

Semantic Shock

Candidate outputs are embedded into semantic space. ManifoldGuard measures distance from the reference manifold:

shock = Gamma * ||candidate_embedding - reference_center||^2

Higher shock means stronger semantic drift.

Literal Drift Guards

Geometry alone can miss small but important substitutions. ManifoldGuard protects numbers, units, named entities, and key content tokens.

Relation Clamps

ManifoldGuard checks relation structure, not just semantic similarity.

Copular examples:

The Sun is a planet.
A dog is a bird.
Rome is the capital city of France.

Non-copular examples:

Earth orbits the Moon.
The Sun orbits Earth.
DNA contains the nucleus.
Heat produces friction.
Photosynthesis converts oxygen into carbon dioxide and water.

Negation Clamp

ManifoldGuard blocks unsupported negations of positive reference support.

Water is not liquid at room temperature.
Sound does not need a material medium to travel.
Scientific descriptions do not use measurements or predictions.
General relativity proves gravity has no connection to mass or energy.

Abstention

When every candidate is unsafe, ManifoldGuard blocks instead of emitting the least-bad candidate.

Installation

Install modes:

  • Offline baseline (default): python -m pip install -e . --no-deps
  • Optional semantic mode: python -m pip install -e .[embeddings]

If you need a plain editable install for local experimentation, use pip install -e . or python -m pip install -e .; both remain supported for compatibility.

The optional extra currently installs sentence-transformers>=2.6.0,<6 for model-backed operation.

If sentence-transformers is unavailable, use offline literal/relation-only regulation with --no-embeddings / use_embeddings=False.

from mbt_ai_tools import evaluate_candidate

evaluate_candidate(
    "Paris is the capital city of France.",
    ["The capital of France is Paris."],
    use_embeddings=False,
)

When embedding-backed operation is requested without sentence-transformers, you'll now get a direct error directing to install the dependency or use offline mode.

Python Usage

from mbt_ai_tools import regulate_candidates

references = [
    "The capital of France is Paris.",
    "Paris is the capital city of France.",
]
candidates = [
    "The capital of France is London.",
    "The capital of France is Paris.",
]

result = regulate_candidates(candidates, references, use_embeddings=False)
print(result.action)        # emit
print(result.emitted_text)  # The capital of France is Paris.

CLI Usage

Check the installed CLI version:

manifold-check --version
manifold-check \
  --reference "The capital of France is Paris." \
  --candidate "The capital of France is London." \
  --candidate "The capital of France is Paris." \
  --no-embeddings

Expected output:

EMIT | The capital of France is Paris. | score=0.0000
[0] blocked | ...
[1] safe | ...

JSON report output:

manifold-check \
  --reference "The capital of France is Paris." \
  --candidate "The capital of France is London." \
  --candidate "The capital of France is Paris." \
  --no-embeddings \
  --format json

See examples/cli_json_report.md for a complete offline JSON report demo.

Optional token-level shock details can be included in regulation reports when embedding dependencies are installed:

manifold-check \
  --reference "The capital of France is Paris." \
  --candidate "The capital of France is London." \
  --format json \
  --token-shock \
  --token-shock-top-k 5

Token-level shock is embedding-backed, so keep --no-embeddings off when using --token-shock.

Batch JSONL evaluation:

manifold-check \
  --input-jsonl examples/batch_input.jsonl \
  --no-embeddings \
  --output batch-report.jsonl

CI guard mode:

manifold-check \
  --input-jsonl examples/batch_input.jsonl \
  --no-embeddings \
  --summary \
  --fail-on-block

--fail-on-block exits with status 2 when a single regulation run blocks or any batch row blocks. --summary appends a final batch summary JSON object.

Markdown audit report:

manifold-check \
  --input-jsonl examples/batch_input.jsonl \
  --no-embeddings \
  --format markdown \
  --output audit.md

See examples/markdown_audit_report.md for a complete Markdown audit demo.

CSV audit export:

manifold-check \
  --input-jsonl examples/batch_input.jsonl \
  --no-embeddings \
  --format csv \
  --output audit.csv

See examples/csv_audit_report.csv for a spreadsheet-friendly batch audit demo.

The JSON/Markdown/CSV report schema is documented in docs/report_schema.md. The release support contract is captured in docs/product_readiness_manifest.json. Release quality expectations are captured in docs/quality_gates.md and docs/release_checklist.md. The maintainer release flow is documented in RELEASE_PROCESS.md.

Local Validation

For schema-driven sanity checks before publishing docs or changing report contracts:

python -m pip install jsonschema
python scripts/validate_reports.py \
  --schema docs/report_schema.json \
  examples/single_report_example.json \
  examples/batch_report_example.jsonl

Run the full local docs-quality check (includes manifest and example consistency):

python scripts/docs_quality.py

Run the full preflight (docs-quality + pytest) before review:

python scripts/preflight.py

Run only docs checks:

python scripts/preflight.py --docs-only

Run only tests:

python scripts/preflight.py --tests-only

Run the frozen offline regression corpus evaluation:

manifold-eval
manifold-eval --output regulator-evaluation.json
python scripts/evaluate_regulator.py
python scripts/evaluate_regulator.py --output regulator-evaluation.json
python scripts/build_eval_report.py --input regulator-evaluation.json --output docs/evaluation_report.md

manifold-eval uses the packaged regression corpus by default and accepts --corpus path/to/corpus.jsonl for custom offline checks. The generated benchmark report lives at docs/evaluation_report.md.

Package Build and Publish

Package distribution artifacts are built by .github/workflows/package-publish.yml on version tags and manual runs. Publishing is manual-only: run the workflow with publish=true and choose testpypi or pypi after configuring PyPI Trusted Publishing environments named testpypi and pypi.

The exact Trusted Publishing setup values are documented in docs/package_publishing.md. Package-index install commands and smoke checks are documented in docs/package_installation.md.

Recommended release order:

python -m build
python -m twine check dist/*

Use TestPyPI first for release-candidate publishing. Do not publish to PyPI until tag CI, release evidence, and the regulator evaluation report are green.

Run the canonical release check sequence:

python scripts/release_check.py --output release-evidence.json

Release Evidence Snapshot

Use this command block before release candidates or public claims:

python -m pytest -q
python scripts/docs_quality.py
python scripts/evaluate_regulator.py
python scripts/preflight.py
python scripts/preflight.py --docs-only
python scripts/release_check.py --output release-evidence.json
python -m pytest -q tests/test_docs_quality.py

Expected evidence in a healthy release path:

  • A full pytest success summary (all tests passed, no failures).
  • docs-quality validator exits successfully.
  • regulator evaluation reports all frozen corpus cases passing, with taxonomy metrics in JSON output.
  • preflight prints Preflight completed successfully. for both full and docs-only modes.
  • no schema or URL drift errors.

Regression Corpus

The lightweight public regression corpus lives in examples/regression_corpus.jsonl. It currently contains 220 offline cases covering entity swaps, multi-word capital handling, all-bad abstention, numeric drift, unit drift, role swaps, shared-subject relation repair, unsupported negation, historical-date drift, supported paraphrase, and overclaim blocking.

Regenerate the corpus:

uv run python examples/build_regression_corpus.py

Run the tests:

uv run --with pytest python -m pytest -q

Experiment Lineage

The full EXP01-EXP20 record is in MBT5_EXP01_EXP20_TECHNICAL_LEDGER.md. The expanded CSV experiment exports live in data/csv_exports/.

Key frozen output artifacts:

data/csv_exports/mbt5_exp20_master_candidate_ledger.csv
data/csv_exports/mbt5_exp20_master_case_ledger.csv
data/csv_exports/mbt5_exp20_summary_metrics.csv
data/csv_exports/mbt5_exp20_case_summary.csv
data/csv_exports/mbt5_exp20_clamp_counts.csv
data/csv_exports/mbt5_exp20_failure_table.csv
data/csv_exports/mbt5_exp20_patch_lineage.csv

A docs-quality workflow also validates manifest JSON and referenced docs/examples so support artifacts stay consistent.

Project Layout

mbt_ai_tools/
  mbt/
    embeddings.py      SentenceTransformer loader
    geometry.py        geometric median, shock, distance
    stability.py       self-consistency / entropy scoring
    tokens.py          leave-one-out token shock
    consensus.py       multi-agent / council logic
    regulator.py       v11 candidate regulator
  data/
    regression_corpus.jsonl
  cli.py               manifold-check command
  eval.py              manifold-eval offline frozen corpus evaluator
.github/workflows/
  tests.yml            GitHub Actions offline regression test workflow
  docs-quality.yml     docs and manifest quality workflow
  package-publish.yml  package build and manual publish workflow
CHANGELOG.md          release notes
CLAIMS.md             scoped public claims register
RELEASE_PROCESS.md    maintainer release flow
data/csv_exports/     expanded EXP01-EXP20 CSV exports
scripts/
  docs_quality.py
  build_eval_report.py
  evaluate_regulator.py
  release_evidence.py
  release_readiness.py
  release_check.py
  preflight.py
  validate_reports.py
docs/
  product_readiness_manifest.json
  report_schema.json
  quality_gates.md
  release_checklist.md
  report_schema.md
examples/
  batch_input.jsonl
  build_regression_corpus.py
  cli_json_report.md
  csv_audit_report.csv
  markdown_audit_report.md
  batch_report_example.jsonl
  single_report_example.json
  regression_corpus.jsonl
tests/
  test_regulator.py
  test_regression_corpus.py
REPLICATION.md        local/GitHub/Colab replication instructions
pyproject.toml
README.md
LICENSE

License

See LICENSE.

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

manifold_guard-0.1.0.tar.gz (49.7 kB view details)

Uploaded Source

Built Distribution

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

manifold_guard-0.1.0-py3-none-any.whl (36.7 kB view details)

Uploaded Python 3

File details

Details for the file manifold_guard-0.1.0.tar.gz.

File metadata

  • Download URL: manifold_guard-0.1.0.tar.gz
  • Upload date:
  • Size: 49.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for manifold_guard-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1b2febb249a2f65ec3c2d61c8a233cd9a7ad649fc55145faf5a2c54af46662d9
MD5 4295327cdfae52710af26859525a03d5
BLAKE2b-256 7cac0ac1b07507919df7cc1441fbb7a30386c65b776e16cd6f619bd918411387

See more details on using hashes here.

Provenance

The following attestation bundles were made for manifold_guard-0.1.0.tar.gz:

Publisher: package-publish.yml on Martin123132/ManifoldGuard

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: manifold_guard-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 36.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for manifold_guard-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 70e3b270ab56d43762bff1bec4ce6528fcf03347ce0b48149938e491bf16fe0d
MD5 262dfc1ee6a37b9fb1f51c2856c24481
BLAKE2b-256 d7a694edd71f3baa1ba3afc720d14bf26125d27dfdb3243c8beafc688b4cbbe5

See more details on using hashes here.

Provenance

The following attestation bundles were made for manifold_guard-0.1.0-py3-none-any.whl:

Publisher: package-publish.yml on Martin123132/ManifoldGuard

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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