LLM Degenerate Loop Guardrails
A zero-runtime-dependency toolkit for detecting degenerate loops in LLM output and tool calls, producing conservative engineering decisions, and preserving reproducible evidence.
30-second start
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;
- suspicious non-consecutive tool-call patterns;
- 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.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mimo_stable-1.1.4.tar.gz | 16.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mimo_stable-1.1.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 30.1 kB
Release files / mimo_stable-1.1.4.tar.gz
| Download URL | mimo_stable-1.1.4.tar.gz |
|---|---|
| Size | 16.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ec6c880134383260578add60a3865916ab3267bb5bc7ba287f7877a3552b08a9
|
|
BLAKE2b-256 checksum How to use checksums |
62bb73ee23f2aabce79c5579f572053afe904c8b6aabefe101813432eadee8b4
|
| 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 24, 2026.
Transparency logRelease files / mimo_stable-1.1.4-py3-none-any.whl
| Download URL | mimo_stable-1.1.4-py3-none-any.whl |
|---|---|
| Size | 13.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a25c94b0b0e8ffcd9253e8b78909136fcb7b709e507277cb5bd459d971d93685
|
|
BLAKE2b-256 checksum How to use checksums |
a993e7e25c65031ccd79bf167ab42967da4e73705cb6073f5830927865b8dfe3
|
| 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 24, 2026.
Transparency log