Package org.mockserver.llm
Class LlmRefusalPresets
java.lang.Object
org.mockserver.llm.LlmRefusalPresets
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final StringA fixed Anthropic refusal wire body (empty content,stop_reason:"refusal"), used byLlmContentFilterBodiesfor a content-filter block.static final StringThe Anthropicstop_reasonvalue signalling a safety refusal. -
Method Summary
Modifier and TypeMethodDescriptionstatic CompletionAn Anthropic-style refusal: a completion withstop_reason:"refusal"and no text content (matching Anthropic's empty-content refusal), which the Anthropic codec encodes as an HTTP 200 refusal message.static CompletionanthropicRefusal(String message) An Anthropic-style refusal carrying a short refusal message as its text content (some refusals include a brief explanation), still withstop_reason:"refusal".
-
Field Details
-
ANTHROPIC_REFUSAL_STOP_REASON
The Anthropicstop_reasonvalue signalling a safety refusal.- See Also:
-
ANTHROPIC_REFUSAL_BODY
A fixed Anthropic refusal wire body (empty content,stop_reason:"refusal"), used byLlmContentFilterBodiesfor a content-filter block. Deterministic test fixture — the id is fixed rather than random.- See Also:
-
-
Method Details
-
anthropicRefusal
An Anthropic-style refusal: a completion withstop_reason:"refusal"and no text content (matching Anthropic's empty-content refusal), which the Anthropic codec encodes as an HTTP 200 refusal message. -
anthropicRefusal
An Anthropic-style refusal carrying a short refusal message as its text content (some refusals include a brief explanation), still withstop_reason:"refusal".
-