Class LlmRefusalPresets

java.lang.Object
org.mockserver.llm.LlmRefusalPresets

public final class LlmRefusalPresets extends Object
Presets that emit provider-style refusals — the response an aligned model returns when it declines to answer on safety grounds. Mocking a refusal lets an agent's refusal-handling path (retry with a softer prompt, surface a user-facing message, fall back to a tool) be exercised deterministically.

The flagship is Anthropic's refusal shape: a normal HTTP 200 message whose stop_reason is "refusal" (introduced alongside Claude's safety-refusal stop reason) rather than end_turn. The anthropicRefusal() preset builds a Completion carrying that stop reason, which the Anthropic codec encodes into the wire body; the raw wire body is also exposed as ANTHROPIC_REFUSAL_BODY for the chaos content-filter block path.

All factories are static and pure; each call returns a fresh Completion.

  • Field Details

    • ANTHROPIC_REFUSAL_STOP_REASON

      public static final String ANTHROPIC_REFUSAL_STOP_REASON
      The Anthropic stop_reason value signalling a safety refusal.
      See Also:
    • ANTHROPIC_REFUSAL_BODY

      public static final String ANTHROPIC_REFUSAL_BODY
      A fixed Anthropic refusal wire body (empty content, stop_reason:"refusal"), used by LlmContentFilterBodies for a content-filter block. Deterministic test fixture — the id is fixed rather than random.
      See Also:
  • Method Details

    • anthropicRefusal

      public static Completion anthropicRefusal()
      An Anthropic-style refusal: a completion with stop_reason:"refusal" and no text content (matching Anthropic's empty-content refusal), which the Anthropic codec encodes as an HTTP 200 refusal message.
    • anthropicRefusal

      public static Completion anthropicRefusal(String message)
      An Anthropic-style refusal carrying a short refusal message as its text content (some refusals include a brief explanation), still with stop_reason:"refusal".