Skip to main content

LLM Degenerate Loop Guardrails

Quality Gate Release License Python

中文说明

See the public specification and implementation roadmap for the supported contract and scope.

A zero-runtime-dependency toolkit for detecting degenerate loops in LLM output and tool calls, producing conservative engineering decisions, and preserving reproducible evidence.

The package also exposes a small inspect_events API for framework-neutral integration. It normalizes text and tool-call events, returns detector evidence and a policy suggestion, and performs no retries or other side effects.

30-second start

Guardrails architecture

Run the included synthetic fixture:

python3 scripts/detect_loop.py \
  --json \
  --timeout 60 \
  --log fixtures/loop_detected.log

The command exits with status 1 when a loop signal is detected. A typical summary looks like this:

{
  "loop_detected": true,
  "details": {
    "type": "consecutive_identical_output"
  }
}
Exit code Meaning
0 No loop detected
1 Loop detected
2 Invalid input or arguments

What it detects

The detector is designed for observable signals such as:

  • consecutive identical or near-identical output blocks;
  • repeated tool calls, including normalized JSON key order;
  • repeated calls only when their output blocks are consecutive;
  • language drift and related output anomalies when evidence supports them.

Detection results are signals, not model-level explanations. MiMo is the initial case study; observations from MiMo, GLM, and other models must be recorded independently and must not be treated as universal conclusions.

Recovery decisions

Pipe a detector summary into the conservative policy layer:

python3 scripts/detect_loop.py \
  --json \
  --timeout 60 \
  --log fixtures/loop_detected.log \
  > /tmp/loop-summary.json

python3 scripts/recovery_policy.py \
  --summary /tmp/loop-summary.json \
  --retryable \
  --retry-count 0

The policy emits a decision only. The upper-layer runner decides whether to pause, retry, switch models, or request human review under its own safety and idempotency rules.

Installation

The project has no runtime dependencies and currently supports source execution and local CLI installation.

Run from source

git clone https://github.com/xli498/mimo-stable.git
cd mimo-stable
python3 scripts/detect_loop.py --log fixtures/loop_detected.log

Install the CLI from PyPI

python3 -m pip install mimo-stable
mimo-loop-detect --json --timeout 60 --log fixtures/loop_detected.log

Examples

Each example shows inputs, signals, or decisions only. Actual stopping, retrying, model switching, tool execution, and human review remain the responsibility of the upper-layer runner.

Repository layout

scripts/detect_loop.py       # Signal detection
scripts/recovery_policy.py   # Conservative decision output
fixtures/                    # Synthetic regression fixtures
examples/                    # Minimal integration examples
references/                  # Evidence and parameter notes
tests/                       # Behavioral tests

Testing

python3 scripts/check_version.py
python3 tests/test_detector.py
python3 scripts/benchmark_fixtures.py
bash scripts/test_short.sh
bash scripts/test_long.sh

CI tests Python 3.10, 3.11, and 3.12.

Evidence and boundaries

  • Fixtures are synthetic or fully redacted.
  • Do not commit API keys, tokens, private prompts, user data, private endpoints, or raw production payloads.
  • Historical model parameters are case-study evidence, not cross-model defaults.
  • The detector and policy layer have no implicit side effects.

License

MIT. See LICENSE.

Metadata

Release files for mimo-stable 1.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mimo-stable 1.1.5
File Size Uploaded
mimo_stable-1.1.5.tar.gz 21.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mimo-stable 1.1.5
File Interpreter ABI Platform
mimo_stable-1.1.5-py3-none-any.whl Python 3 none any Details

Total release size: 36.0 kB

Release files / mimo_stable-1.1.5.tar.gz

Download URL mimo_stable-1.1.5.tar.gz
Size 21.7 kB
Tags Source
SHA-256 checksum
How to use checksums
81680f609509a72422103c4d4fa934d7dbec9093f86e68df9ce61f149d6ce5fa
BLAKE2b-256 checksum
How to use checksums
4fb13f590954b3471719203108538175edc8aadb676748d09b0056d7d4b72b7d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 28, 2026.

Transparency log

Release files / mimo_stable-1.1.5-py3-none-any.whl

Download URL mimo_stable-1.1.5-py3-none-any.whl
Size 14.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9682f8a53f7d47baaf8717f8293a78719853bc55e6c2aabb1efffceb9b61c78f
BLAKE2b-256 checksum
How to use checksums
84655a7712736819e644e8f46758d6cb7cc50969c8d2b3bfd4f36926ced5e87e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 28, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.1.5 This release

2 release files

1.1.4

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

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