Class HttpLlmResponseActionHandler

java.lang.Object
org.mockserver.mock.action.http.HttpLlmResponseActionHandler

public class HttpLlmResponseActionHandler extends Object
  • Constructor Details

    • HttpLlmResponseActionHandler

      public HttpLlmResponseActionHandler(MockServerLogger mockServerLogger)
  • Method Details

    • handle

      public HttpResponse handle(HttpLlmResponse httpLlmResponse, HttpRequest request)
    • enforcementErrorResponseOrNull

      public HttpResponse enforcementErrorResponseOrNull(HttpLlmResponse httpLlmResponse, HttpRequest request)
      Strict structured-output enforcement, opt-in via Completion.getEnforceOutputSchema(). When enforcement is enabled and the completion's configured text does not conform to its declared output schema, returns a provider-correct error HttpResponse (status 502, with the x-mockserver-structured-output-invalid diagnostic header) so the mock fails loudly rather than returning a non-conforming body. Returns null when enforcement is off, no schema is declared, or the text conforms — in which case the response is delivered normally.

      Models real providers' strict response_format: json_schema mode, which guarantees schema-valid output: a non-conforming strict fixture is a configuration error and surfaces as an error rather than silently passing. Applies to both the streaming and non-streaming paths (checked before dispatch by HttpActionHandler, mirroring chaosErrorResponseOrNull(org.mockserver.model.HttpLlmResponse)), so a strict streaming completion with a non-conforming body never begins streaming.

    • streamingFormatFor

      public StreamingFormat streamingFormatFor(Provider provider)
      Returns the streaming wire format for the given provider. Used by the action handler dispatch to choose between SSE and NDJSON framing.
      Parameters:
      provider - the LLM provider
      Returns:
      the streaming format (defaults to StreamingFormat.SSE)
    • handleStreaming

      public List<SseEvent> handleStreaming(HttpLlmResponse httpLlmResponse, HttpRequest request)
      Handle streaming LLM response by producing a list of SSE events. Called by HttpActionHandler when streaming is detected.
      Parameters:
      httpLlmResponse - the LLM response action
      request - the original HTTP request
      Returns:
      list of SSE events to be sent through the SSE handler
    • chaosErrorResponseOrNull

      public HttpResponse chaosErrorResponseOrNull(HttpLlmResponse httpLlmResponse)
      Returns an error HttpResponse (status + optional Retry-After) when the chaos profile triggers a probabilistic error, or null otherwise. An errorStatus with no errorProbability always fires; a fractional probability draws once (reproducible via seed). Applies to both streaming and non-streaming responses — a provider error is a normal HTTP response, not an SSE stream.