Skip to main content

The honesty.tools client: ground claims (verify) and run honest Photon inference (ask) on one sk-apt- key — free to start, upgrade anytime. Plus an offline calibration-certificate gate for your own model.

Project description

aperture-gate

Deploy a honesty.tools calibration certificate.

You calibrated a model at honesty.tools/calibrate (or with the public aperture_calibrate.py) and got a certificate JSON — aperture.cert.v1 — containing a logistic probe fitted to your model's logprob confidence fingerprint over a Wikipedia-validated battery of real and fabricated entities. This package is the deployment half: it consumes that certificate and gates live answers.

The method, honestly stated. Two instruments, words first:

  1. words — if the answer itself refuses or hedges ("no such company", "I couldn't find any record…"), the verdict is OFF_MAP. The model said so; believe it.
  2. fingerprint — otherwise, the gate scores [mean logprob, min logprob, mean top-5 entropy, max top-5 entropy] through the certificate's probe. Higher score = more likely fabricated. score >= off_map_thrOFF_MAP; >= uncertain_thrUNCERTAIN; else ON_MAP.
  3. With no logprobs and no refusal, the read degrades honestly to ON_MAP (instrument words-only).

The probe is calibrated per model — deploy the certificate for the model you actually serve. It separates grounded answers from confabulated answers about entities; it is not a general lie detector.

Zero runtime dependencies (pure stdlib), Python ≥ 3.9, MIT.

Install

pip install aperture-gate

# optional — verify certificate signatures against the registry key (adds `cryptography`):
pip install 'aperture-gate[verify]'

Certificate trust. Registry certificates are ed25519-signed. With the [verify] extra installed, Gate.from_cert(...) verifies the signature against the registry's pinned public key and rejects a tampered or wrongly-signed certificate (raises ValueError); every verdict carries signature_verified (true/false/null). Without [verify] the gate still works — it just notes that the signature was not verified. Expired certificates always warn.

Quickstart

from aperture_gate import Gate

# a registry id, a local cert path, or the cert dict itself
gate = Gate.from_cert("openai/gpt-4o-mini")        # openai/gpt-4o-mini reference cert

# 1) words-only read of any text
gate.read_text("I couldn't find any record of that company.")
# {'verdict': 'OFF_MAP', 'band': 'off-map', 'instrument': 'words', ...}

# 2) read a raw chat.completions response (ask for logprobs yourself)
verdict = gate.read_response(resp_dict_or_openai_object)

# 3) let the gate call the endpoint (sends logprobs=true, top_logprobs=5, temperature=0)
out = gate.ask("Tell me about the novel Glass over Brackwald.",
               base_url="https://openrouter.ai/api/v1", api_key="sk-or-...")
print(out["verdict"], out["score"], out["answer"][:80])

# 4) or wrap an openai-python client (openai>=1.x) transparently
client = gate.wrap(OpenAI())
r = client.chat.completions.create(model="gpt-4o-mini",
                                   messages=[{"role": "user", "content": "..."}])
print(r.aperture)   # the verdict dict rides along on the response

# 5) gate a STREAM in real time — the verdict lands before the answer finishes.
#    Chunks pass through to your loop unchanged; the gate scores the calibrated
#    window prefix as it arrives and (optionally) ABORTS off-map answers mid-stream.
client = gate.wrap(OpenAI(), on_verdict=lambda v: v["verdict"] == "OFF_MAP")
stream = client.chat.completions.create(model="gpt-4o-mini", stream=True,
                                        messages=[{"role": "user", "content": "..."}])
for chunk in stream:
    print(chunk.choices[0].delta.content or "", end="")   # stops early if it reads off-map
print(stream.aperture)   # the verdict, scored on the first `window` tokens

CLI

aperture-gate read --cert openai/gpt-4o-mini --text "No such film exists."
aperture-gate read --cert ./aperture-cert-my-model.json \
    --query "Who founded Brindlewick & Thorne?" \
    --base-url http://localhost:8000/v1 --key sk-...
aperture-gate calibrate --base-url http://localhost:8000/v1 --model my-llama-70b
aperture-gate verify     # conformance self-test against frozen vectors

MCP server

A pure-stdlib stdio MCP server, for Claude Desktop / Claude Code / any MCP client:

python -m aperture_gate.mcp

Tools: aperture_read {query, model?} (ask the upstream model and gate the answer) and aperture_check_text {text} (words-only read, no model call). Configure with APERTURE_BASE_URL (default https://openrouter.ai/api/v1), APERTURE_UPSTREAM_KEY or OPENROUTER_API_KEY, and APERTURE_CERT (path or registry id; default openai/gpt-4o-mini).

Conformance

aperture-gate verify (or python -m aperture_gate.verify) runs six frozen vectors computed from the real gpt-4o-mini registry certificate and the public demo battery — three fingerprint scores to six decimal places and three refusal-reader reads pinning the normalization and guard logic. If any vector fails, the install does not implement the certified method.

Docs

Full method, evidence, and the certificate registry: honesty.tools/docs

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

aperture_gate-0.2.0.tar.gz (71.8 kB view details)

Uploaded Source

Built Distribution

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

aperture_gate-0.2.0-py3-none-any.whl (35.8 kB view details)

Uploaded Python 3

File details

Details for the file aperture_gate-0.2.0.tar.gz.

File metadata

  • Download URL: aperture_gate-0.2.0.tar.gz
  • Upload date:
  • Size: 71.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for aperture_gate-0.2.0.tar.gz
Algorithm Hash digest
SHA256 96d56506d547f7db1bfcd46b094168fa38aab95ff0a97dde505a26d2fdf77911
MD5 5736f6e25bcfc55688c1465791506104
BLAKE2b-256 c23dc7a5a9cce7d9e27e1c54ac00e576098cbb6992e53bdc224d9e8e332b1b73

See more details on using hashes here.

File details

Details for the file aperture_gate-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: aperture_gate-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 35.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for aperture_gate-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c12ec1eaf3ad56b854be518c29b71b94f7582df2d10e79b8785d3e34297265ec
MD5 54e3828f2bd191ed73b7be1fb8dcc830
BLAKE2b-256 75d6956c560b463b47abcccc835885e49069e074cd5f689b9cf86755d99ae66d

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