Skip to main content

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

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)

Source distribution for llm-degen-guard 0.1.1
File Size Uploaded
llm_degen_guard-0.1.1.tar.gz 14.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for llm-degen-guard 0.1.1
File Interpreter ABI Platform
llm_degen_guard-0.1.1-py3-none-any.whl Python 3 none any Details

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 log

Release 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 log

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.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