Model-agnostic LLM output degeneration detector — 4-signal composite scoring in a single pass
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file llm_degen_guard-0.1.1.tar.gz.
File metadata
- Download URL: llm_degen_guard-0.1.1.tar.gz
- Upload date:
- Size: 14.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5ccb655f697baa08f99e560c6b22f328b58a03efceeeeea981d9c934e1b34d91
|
|
| MD5 |
af452125f8a6192c1982858703ec3615
|
|
| BLAKE2b-256 |
3e8438c2355c3d29f206e40c883012ed10c9f2f7a59c26d4f80657c48461b9d7
|
Provenance
The following attestation bundles were made for llm_degen_guard-0.1.1.tar.gz:
Publisher:
publish.yml on QuartzUnit/llm-degen-guard
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
llm_degen_guard-0.1.1.tar.gz -
Subject digest:
5ccb655f697baa08f99e560c6b22f328b58a03efceeeeea981d9c934e1b34d91 - Sigstore transparency entry: 1178846062
- Sigstore integration time:
-
Permalink:
QuartzUnit/llm-degen-guard@9501edbec38772bd4ffc5582bf994a7c4bf72afc -
Branch / Tag:
refs/heads/main - Owner: https://github.com/QuartzUnit
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9501edbec38772bd4ffc5582bf994a7c4bf72afc -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file llm_degen_guard-0.1.1-py3-none-any.whl.
File metadata
- Download URL: llm_degen_guard-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
294acf8b13d0e1acef5c68d76cbc4faa5fe665d5861030a1b085255cd099ec49
|
|
| MD5 |
44ee87c7144aeb9758fefb65d22a811a
|
|
| BLAKE2b-256 |
8886331fbd54567db730f1beeb4bdcbd5e77b61ae7b441390a5f2f563109fcb7
|
Provenance
The following attestation bundles were made for llm_degen_guard-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on QuartzUnit/llm-degen-guard
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
llm_degen_guard-0.1.1-py3-none-any.whl -
Subject digest:
294acf8b13d0e1acef5c68d76cbc4faa5fe665d5861030a1b085255cd099ec49 - Sigstore transparency entry: 1178846074
- Sigstore integration time:
-
Permalink:
QuartzUnit/llm-degen-guard@9501edbec38772bd4ffc5582bf994a7c4bf72afc -
Branch / Tag:
refs/heads/main - Owner: https://github.com/QuartzUnit
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9501edbec38772bd4ffc5582bf994a7c4bf72afc -
Trigger Event:
workflow_dispatch
-
Statement type: