Class LlmContentFilterBodies

java.lang.Object
org.mockserver.llm.LlmContentFilterBodies

public final class LlmContentFilterBodies extends Object
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)) — the content_filter_results / prompt_filter_results object Azure OpenAI attaches to every completion, one entry per harm category with a filtered flag and severity.
  • 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 a content_filter error; Azure → HTTP 400 whose innererror carries the filter result; Anthropic/Bedrock → HTTP 200 with stop_reason:"refusal"; Gemini → HTTP 200 with finishReason:"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.

  • Method Details

    • azureFilterResults

      public static com.fasterxml.jackson.databind.node.ObjectNode azureFilterResults(LlmContentFilter filter)
      Build the Azure content_filter_results / prompt_filter_results object for the four core harm categories. Each entry is {"filtered":bool,"severity":".."}; a null filter yields an all-safe, unfiltered object.
    • blockFor

      public static LlmContentFilterBodies.Block blockFor(Provider provider, LlmContentFilter filter)
      The provider-correct content-filter block response. filter shapes the Azure content_filter_result; a null filter uses a sensible default (hate at high).