Skip to main content Switch to mobile version latchgate 0.1.1 Prevent silent AI hallucinations, fabricated tool calls, and sycophantic world-model physics via zero-decode 57.1%-depth circuit breakers
pip install latchgate==0.1.1 Copy PIP instructions
Prevent silent AI hallucinations, fabricated tool calls, and sycophantic world-model physics via zero-decode 57.1%-depth circuit breakers.
LLM Agents · Cosmos & Diffusers · Agent Skill & MCP · Adaptive Compiler · Pre-Built Packs · Mendmark Bridge
Created by Daniel Gaskins
Post-hoc text auditors and pixel-level video critics share a structural flaw: they pay 100% of generation and 3D-VAE decode cost before inspecting an output, and they are systematically fooled by sycophantic trajectories (
LatchGate moves safety and physical-consistency enforcement inside the residual stream at 57.1% network depth, compiling portable .lgate (safetensors) circuit breakers that execute in < 1 ms on LLM tokens and ~11 ms on 3D spacetime tokens with 0.0% benign capability tax and zero pixel decodes.
pip install latchgate # Optional extras for Hugging Face Transformers, Diffusers, or Hub helpers: pip install "latchgate[llm,diffusers,hub]" Which Guardrail Fits Your AI Stack?
Equip a Coding Agent and MCP Server
Every CLI command supports --json for deterministic agent orchestration, plus a built-in zero-dependency stdio Model Context Protocol (MCP) server and non-destructive repository skill installer (Claude Code, Codex, Cursor, Antigravity):
# 1. Ask which guardrail stack fits your model and failure mode: latchgate recommend --model Qwen/Qwen2.5-7B-Instruct --failure-mode "503 tool fabrication" --json # 2. Deterministically verify any .lgate circuit breaker on CPU in < 1 s: latchgate verify qwen2.5-7b-sabotage --json # 3. Scaffold .latchgate/ docs, MCP config, and repo-scoped agent skills (SKILL.md): latchgate equip --runtime auto --agent auto --json # 4. Run the stdio JSON-RPC 2.0 MCP server directly: latchgate mcp Quickstart A: LLM Agents
Intercept
from latchgate import LatchGate, TransformersLatchHook gate = LatchGate.from_pretrained("qwen2.5-7b-sabotage", device="cuda") hook = TransformersLatchHook(gate, policy="latched_steer") # or policy="early_abort" with hook.attach(model) as telemetry: output_ids = model.generate(**inputs, max_new_tokens=160) The same .lgate artifact attaches directly to local vLLM (VLLMLatchEngine) and SGLang (SGLangLatchHook) model runners over flattened 2D paged-attention hidden states.
Quickstart B: Cosmos and Diffusers World Models
Abort action-decoupled ("sycophantic") robot rollouts at Step 10/35 inside Cosmos-Predict2.5-2B before running the remaining 50 CFG passes or decoding a single frame through the Wan2.1 3D-VAE:
from latchgate import CosmosLatchFirewall, EarlyAbortRollout, LatchGate gate = LatchGate.from_pretrained("cosmos-predict2.5-bridge", device="cuda") with CosmosLatchFirewall(gate, policy="early_abort", abort_step=10).attach(world_model.dit) as step_cb: latents = world_model.rollout(frame0, actions, decode_video=False, step_callback=step_cb) For closed-loop model-predictive control (Cosmos-Policy-LIBERO), shield_value_critic prunes sycophantic action candidates at Step 3/10 before invoking the internal value head $V(\hat{s}')$, raising valid grasp selection to 80.0% while cutting 4-candidate planning latency from 8.93 s to 6.02 s.
Adaptive Compilation (latchgate fit)
Generic SAE pretraining on billions of tokens is unnecessary for runtime control and often counterproductive on 7B to 70B LLMs where linear probes already separate pre-action intent cleanly. Given 50 to 200 paired counterfactual traces (plus optional high-motion or benign confounders), latchgate fit measures the 57.1%-depth superposition gap via cross-validation and automatically compiles the lightest representation that achieves target 0.0% benign false-positive rate:
Fast Task Calibration (< 10 s on Frozen Base Dictionaries)
Because sparse dictionary learning is decoupled from task attribution, adapting a circuit breaker to a new robot manipulation suite or internal MCP tool schema does not retrain the 16,384-latent SAE. Pass --base-sae (any .lgate, .safetensors, Gemma Scope .npz, or Hugging Face repo) to calibrate $\mathcal{D} = \text{TopK}(d^{\text{bad}} - \lambda d^{\text{confound}})$ and conformal threshold $\tau$ in seconds:
latchgate fit custom_robot_pairs.npz \ --base-sae cosmos-predict2.5-bridge.lgate \ --max-benign-fpr 0.0 \ --output custom_cell_firewall.lgate When calibrating a brand-new backbone with no public SAE, latchgate train-sae trains a per-timestep standardized JumpReLU SAE on a single 24 GB GPU using buffer-replay saturation sizing (Koriagin et al., 2026) and variance/confounder-reweighted MSE (WSAE) so high-energy motion or formatting axes do not starve subtle contact or sabotage features.
Pre-Built .lgate Packs
All six SHA-256-verified packs are hosted on both Hugging Face Hub (danielgaskins/latchgate-packs) and GitHub Releases (v0.1.0). List or inspect them from the CLI (latchgate list-packs, latchgate inspect
Mendmark CI-to-Runtime Bridge
Mendmark (pip install mendmark-evals) discovers silent tool-call and outcome blind spots in CI via mutation testing; LatchGate blocks those exact failure modes in the residual stream at runtime:
# 1. Export planted fault mutations + clean golden traces from any Mendmark suite: mendmark export-latchgate examples/order_agent_suite.json \ --output calibration_pairs.jsonl # 2. Compile a zero-tax .lgate circuit breaker directly against your open-weights agent model: latchgate fit calibration_pairs.jsonl \ --model Qwen/Qwen2.5-7B-Instruct \ --output order_agent.lgate Research Foundations
LatchGate unifies the algorithms and empirical findings from three companion papers:
Agentic LLMs: Silent Pre-Action Commitment and Closed-Loop Circuit Breakers Against Agentic Sabotage (DOI: 10.5281/zenodo.24596272)
Long-Horizon Video DiTs: Sparse Temporal Latching: Overcoming Polysemantic Collateral Damage in Long-Horizon Video Diffusion Transformers (DOI: 10.5281/zenodo.24596273)
Embodied World Models: Sycophantic Physics in Embodied World Models: Zero-Decode Latent Firewalls for Action-Conditioned Video DiTs (DOI: 10.5281/zenodo.24593275)
Released under the MIT License.
Released: Nov 28, 2026
Author: Daniel Gaskins
Both files in this release have provenance metadata.
View provenance details
MIT View SPDX License List
hub llm diffusers dev
agent-reliability ai-control ai-guardrails circuit-breakers cosmos diffusers hallucination-detection interpretability llm-guardrails mcp mechanistic-interpretability robotics runtime-verification sae sglang sparse-autoencoders tool-calling vllm world-models
Development Status 4 - Beta
Intended Audience Developers
Operating System OS Independent
Programming Language Python :: 3
Topic Scientific/Engineering :: Artificial Intelligence
Software Development :: Quality Assurance
Software Development :: Testing
Release files for latchgate 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
Built distribution (wheel)
Total release size: 129.3 kB
Release files / latchgate-0.1.1.tar.gz
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 Nov 28, 2026.
Release files / latchgate-0.1.1-py3-none-any.whl
Security for latchgate 0.1.1
Both files in this release have been uploaded with provenance metadata.
With provenance latchgate-0.1.1.tar.gz Nov 28, 2026
With provenance latchgate-0.1.1-py3-none-any.whl Nov 28, 2026
Attestation for latchgate-0.1.1.tar.gz
Attestation for latchgate-0.1.1-py3-none-any.whl
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
Nov 28, 2026 2 release files Full provenance
Nov 27, 2026 2 release files Full provenance
"PyPI", "Python Package Index", and the blocks logos are registered trademarks of the Python Software Foundation.
© 2026 Python Software Foundation
Deployed from fc0d8e6











