Class LlmConversationMatcher

java.lang.Object
org.mockserver.matchers.LlmConversationMatcher

public class LlmConversationMatcher extends Object
Matches inbound HTTP requests against LLM conversation predicates. All predicates compose with AND semantics. Parse failures and oversize bodies are treated as no-match (fail-closed) without throwing.
  • Constructor Details

    • LlmConversationMatcher

      public LlmConversationMatcher()
  • Method Details

    • withTurnIndex

      public LlmConversationMatcher withTurnIndex(Integer turnIndex)
    • getTurnIndex

      public Integer getTurnIndex()
    • withLatestMessageContains

      public LlmConversationMatcher withLatestMessageContains(String text)
    • getLatestMessageContains

      public String getLatestMessageContains()
    • withLatestMessageMatches

      public LlmConversationMatcher withLatestMessageMatches(String regexSource)
      Set regex from a source string. The pattern is compiled eagerly so that syntactically-invalid regexes are rejected at configuration time (not at match time). Throws PatternSyntaxException wrapped in IllegalArgumentException if the regex does not compile.
      Parameters:
      regexSource - the regex source string
      Returns:
      this matcher
      Throws:
      IllegalArgumentException - if the regex source is syntactically invalid
    • withLatestMessageMatches

      public LlmConversationMatcher withLatestMessageMatches(Pattern pattern)
    • getLatestMessageMatches

      public Pattern getLatestMessageMatches()
    • getLatestMessageMatchesSource

      public String getLatestMessageMatchesSource()
    • withLatestMessageRole

      public LlmConversationMatcher withLatestMessageRole(ParsedMessage.Role role)
    • getLatestMessageRole

      public ParsedMessage.Role getLatestMessageRole()
    • withContainsToolResultFor

      public LlmConversationMatcher withContainsToolResultFor(String toolName)
    • getContainsToolResultFor

      public String getContainsToolResultFor()
    • withSemanticMatchAgainst

      public LlmConversationMatcher withSemanticMatchAgainst(String semanticMatchAgainst)
    • getSemanticMatchAgainst

      public String getSemanticMatchAgainst()
    • withProvider

      public LlmConversationMatcher withProvider(Provider provider)
    • getProvider

      public Provider getProvider()
    • withNormalization

      public LlmConversationMatcher withNormalization(NormalizationOptions normalization)
      Set optional prompt normalisation applied to the latest-message text (and, for latestMessageContains, the expected substring) before the text predicates are evaluated. Null leaves matching exact (today's behaviour).
    • getNormalization

      public NormalizationOptions getNormalization()
    • hasPredicates

      public boolean hasPredicates()
      Returns true if any predicate is configured on this matcher.
    • matches

      public boolean matches(HttpRequest request)
      Matches the given request against all configured predicates. Returns true if no predicates are set. Returns false on parse failure, oversize body, missing codec, or any predicate mismatch. Never throws.