llm-degen-guard
Model-agnostic LLM output degeneration detector — 4-signal composite scoring in a single pass.
Install
pip install llm-degen-guard
Quick Start
from degen_guard import DegenGuard
# Batch check
report = DegenGuard.check("Some LLM output text...")
print(report.is_degenerate, report.composite_score)
# Streaming check
guard = DegenGuard()
for chunk in llm_stream:
is_degen, score = guard.feed(chunk)
if is_degen:
print(f"Degeneration detected! score={score:.2f}")
break
How It Works
Four independent signals are combined into a single composite score (0.0 = normal, 1.0 = degenerate):
| Signal | Weight | What it measures |
|---|---|---|
| N-gram diversity | 0.35 | Distinct 3-gram ratio — low diversity = repetitive |
| Compression ratio | 0.30 | zlib compression ratio — highly compressible = repetitive |
| Substring match | 0.20 | Exact overlap between first/second half of window |
| Line diversity | 0.15 | Unique line ratio — duplicate lines = degenerate |
Structural content (code, lists, tables) gets a discount factor to reduce false positives.
Streaming API
guard = DegenGuard(
window_size=256, # characters to analyze
check_interval=64, # characters between checks
alert_threshold=3, # consecutive alerts before flagging
score_threshold=0.50, # minimum score to trigger alert
)
for chunk in llm_stream:
is_degen, score = guard.feed(chunk)
if is_degen:
break
guard.reset() # reuse for next stream
Batch API
report = DegenGuard.check(full_text)
report.is_degenerate # bool
report.composite_score # 0.0 ~ 1.0
report.signals # tuple of SignalDetail
report.structural_penalty # < 1.0 if code/tables detected
report.text_length # input length
Why not...?
| Alternative | Limitation | llm-degen-guard |
|---|---|---|
| Antislop Sampler | Needs model weight access (no API support) | Works on any output text |
| SpecRA | Paper only, no code available | pip install ready |
| UQLM | Requires N generations (cost × N) | Single pass, real-time streaming |
| repetition_penalty | Penalizes prompt tokens, causes incoherence | Post-generation, no side effects |
License
MIT
Metadata
Release files for llm-degen-guard 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| llm_degen_guard-0.1.1.tar.gz | 14.2 kB | With provenance | Details for llm_degen_guard-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| llm_degen_guard-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for llm_degen_guard-0.1.1-py3-none-any.whl |
Total release size: 21.0 kB
Release files / llm_degen_guard-0.1.1.tar.gz
| Download URL | llm_degen_guard-0.1.1.tar.gz |
|---|---|
| Size | 14.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5ccb655f697baa08f99e560c6b22f328b58a03efceeeeea981d9c934e1b34d91
|
|
BLAKE2b-256 checksum How to use checksums |
3e8438c2355c3d29f206e40c883012ed10c9f2f7a59c26d4f80657c48461b9d7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Mar 25, 2026.
Transparency logRelease files / llm_degen_guard-0.1.1-py3-none-any.whl
| Download URL | llm_degen_guard-0.1.1-py3-none-any.whl |
|---|---|
| Size | 6.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
294acf8b13d0e1acef5c68d76cbc4faa5fe665d5861030a1b085255cd099ec49
|
|
BLAKE2b-256 checksum How to use checksums |
8886331fbd54567db730f1beeb4bdcbd5e77b61ae7b441390a5f2f563109fcb7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Mar 25, 2026.
Transparency logSecurity for llm-degen-guard 0.1.1
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for llm_degen_guard-0.1.1.tar.gz
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 Mar 25, 2026.
Transparency logA 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.