Package org.mockserver.llm
Class LlmContentFilterBodies
java.lang.Object
org.mockserver.llm.LlmContentFilterBodies
Pure, deterministic helper for content-filter / guardrail simulation across
providers. Two concerns, both provider-correct so an agent's filtering-detection
and refusal-handling logic can be exercised faithfully against a mock:
- Azure annotations (
azureFilterResults(org.mockserver.model.LlmContentFilter)) — thecontent_filter_results/prompt_filter_resultsobject Azure OpenAI attaches to every completion, one entry per harm category with afilteredflag andseverity. - Content-filter block (
blockFor(org.mockserver.model.Provider, org.mockserver.model.LlmContentFilter)) — the response a provider returns when it refuses to answer on safety grounds. The shape is provider-specific: OpenAI-family → HTTP 400 with acontent_filtererror; Azure → HTTP 400 whoseinnererrorcarries the filter result; Anthropic/Bedrock → HTTP 200 withstop_reason:"refusal"; Gemini → HTTP 200 withfinishReason:"SAFETY"; otherwise a generic 400.
This is the content-filter counterpart to LlmErrorBody (overload /
rate-limit / server errors): content-filter is a distinct wire shape, so it lives
in a sibling helper rather than being shoehorned into LlmErrorBody.Kind.
All methods are static and pure — no clocks, no randomness, no shared state.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classImmutable (status, jsonBody) pair for a content-filter block response. -
Method Summary
Modifier and TypeMethodDescriptionstatic com.fasterxml.jackson.databind.node.ObjectNodeazureFilterResults(LlmContentFilter filter) Build the Azurecontent_filter_results/prompt_filter_resultsobject for the four core harm categories.static LlmContentFilterBodies.BlockblockFor(Provider provider, LlmContentFilter filter) The provider-correct content-filter block response.
-
Method Details
-
azureFilterResults
public static com.fasterxml.jackson.databind.node.ObjectNode azureFilterResults(LlmContentFilter filter) Build the Azurecontent_filter_results/prompt_filter_resultsobject for the four core harm categories. Each entry is{"filtered":bool,"severity":".."}; a nullfilteryields an all-safe, unfiltered object. -
blockFor
The provider-correct content-filter block response.filtershapes the Azurecontent_filter_result; a nullfilteruses a sensible default (hate athigh).
-