nemoguardrails.library.context_bloat_detection.actions
nemoguardrails.library.context_bloat_detection.actions
Context bloat detection action
Detects context-manipulation attacks where attacker-controlled content (retrieved chunks or user input) is padded, oversized, or repetitively structured to cause system prompt forgetting, bury instructions mid-context (harder to detect), or exhaust token budget.
Wire as retrieval rail (RAG chunks) or input rail.
Module Contents
Classes
Functions
Data
API
Bases: typing.TypedDict
Fraction of text that is the longest run of a single character.
High values are a padding-attack signature.
Samples large inputs to bound runtime.
Detect context-bloat / context-manipulation attacks. Check order is cheapest first to enable early-exit.
Parameters:
The text to inspect (joined chunks or user message).
RailsConfig with rails.config.context_bloat_detection settings.
Returns: ContextBloatResult
ContextBloatResult with is_bloat flag, processed text, reason, metrics.