Class InjectionDetectionResult

java.lang.Object
com.tnsai.quality.security.llm.InjectionDetectionResult

public final class InjectionDetectionResult extends Object
Result of prompt injection detection.

Contains detection status, confidence score, and details about detected injection patterns.

Confidence Levels

Score RangeLevelRecommended Action
0.0 - 0.3LOWAllow with logging
0.3 - 0.6MEDIUMFlag for review
0.6 - 0.8HIGHBlock or require approval
0.8 - 1.0CRITICALBlock immediately
  • Method Details

    • safe

      public static InjectionDetectionResult safe()
      Creates a safe (no injection) result.
      Returns:
      safe result
    • detected

      public static InjectionDetectionResult detected(double confidenceScore, List<InjectionDetectionResult.InjectionType> detectedTypes, List<String> matchedPatterns)
      Creates a detection result.
      Parameters:
      confidenceScore - confidence score (0.0 - 1.0)
      detectedTypes - types of injections detected
      matchedPatterns - patterns that matched
      Returns:
      detection result
    • builder

      public static InjectionDetectionResult.Builder builder()
      Creates a result builder.
      Returns:
      new builder
    • isInjectionDetected

      public boolean isInjectionDetected()
      Checks if injection was detected.
      Returns:
      true if injection detected
    • getConfidenceScore

      public double getConfidenceScore()
      Gets the confidence score.
      Returns:
      confidence score (0.0 - 1.0)
    • getConfidenceLevel

      public InjectionDetectionResult.ConfidenceLevel getConfidenceLevel()
      Gets the confidence level.
      Returns:
      confidence level
    • getDetectedTypes

      public List<InjectionDetectionResult.InjectionType> getDetectedTypes()
      Gets the detected injection types.
      Returns:
      list of injection types
    • getMatchedPatterns

      public List<String> getMatchedPatterns()
      Gets the patterns that matched.
      Returns:
      list of matched patterns
    • shouldBlock

      public boolean shouldBlock()
      Checks if this result should block the request. Default threshold is HIGH confidence.
      Returns:
      true if should block
    • shouldBlock

      public boolean shouldBlock(double threshold)
      Checks if this result should block with custom threshold.
      Parameters:
      threshold - confidence threshold
      Returns:
      true if should block
    • toString

      public String toString()
      Overrides:
      toString in class Object