Class LLMPromptGuardFilter
- java.lang.Object
-
- org.openidentityplatform.openig.ai.filter.LLMPromptGuardFilter
-
- All Implemented Interfaces:
org.forgerock.http.Filter
public class LLMPromptGuardFilter extends Object implements org.forgerock.http.Filter
Detects and blocks prompt-injection attacks before they reach the downstream LLM API.Detection pipeline
- Prompt extraction – parses the JSON request body and
extracts all prompt text from
messages[].content(OpenAI chat format) or a top-levelpromptfield. - Layer-1: Regex – fast, deterministic pattern matching including Unicode normalization and Base64 decode-then-scan.
- Layer-2: Typoglycemia (enabled by
typoglycemiaEnabled, defaulttrue) – catches injection keywords whose interior letters have been transposed to evade exact matching (e.g."jialbrek"for"jailbreak"). Uses a fingerprint gate (first char + last char + sorted interior bag) followed by true unrestricted Damerau-Levenshtein distance ≤typoglycemiaMaxEditDist(default 3).
Actions on detection
BLOCK– returns a configurable HTTP error (default 400).LOG_ONLY– no headers, no blocking.
Route JSON configuration
{ "type": "LLMPromptGuardFilter", "config": { "action": "BLOCK", "patternFile": "injection-patterns.json", "typoglycemiaEnabled": true, "typoglycemiaMaxEditDist": 3, "typoglycemiaMinWordLen": 4, "typoglycemiaKeywords": "typoglycemia-keywords.json", "blockResponse": { "status": 400, "body": "{ \"error\": \"prompt_injection_detected\" }" } } }
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classLLMPromptGuardFilter.Actionstatic classLLMPromptGuardFilter.Heaplet
-
Constructor Summary
Constructors Constructor Description LLMPromptGuardFilter(InjectionDetector detector, LLMPromptGuardFilter.Action action)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.forgerock.util.promise.Promise<org.forgerock.http.protocol.Response,org.forgerock.util.promise.NeverThrowsException>filter(org.forgerock.services.context.Context context, org.forgerock.http.protocol.Request request, org.forgerock.http.Handler next)
-
-
-
Constructor Detail
-
LLMPromptGuardFilter
public LLMPromptGuardFilter(InjectionDetector detector, LLMPromptGuardFilter.Action action)
-
-
Method Detail
-
filter
public org.forgerock.util.promise.Promise<org.forgerock.http.protocol.Response,org.forgerock.util.promise.NeverThrowsException> filter(org.forgerock.services.context.Context context, org.forgerock.http.protocol.Request request, org.forgerock.http.Handler next)- Specified by:
filterin interfaceorg.forgerock.http.Filter
-
-