Package org.mockserver.mock.action.http
Class HttpLlmResponseActionHandler
java.lang.Object
org.mockserver.mock.action.http.HttpLlmResponseActionHandler
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionchaosErrorResponseOrNull(HttpLlmResponse httpLlmResponse) Returns an errorHttpResponse(status + optionalRetry-After) when the chaos profile triggers a probabilistic error, ornullotherwise.enforcementErrorResponseOrNull(HttpLlmResponse httpLlmResponse, HttpRequest request) Strict structured-output enforcement, opt-in viaCompletion.getEnforceOutputSchema().handle(HttpLlmResponse httpLlmResponse, HttpRequest request) handleStreaming(HttpLlmResponse httpLlmResponse, HttpRequest request) Handle streaming LLM response by producing a list of SSE events.streamingFormatFor(Provider provider) Returns the streaming wire format for the given provider.
-
Constructor Details
-
HttpLlmResponseActionHandler
-
-
Method Details
-
handle
-
enforcementErrorResponseOrNull
public HttpResponse enforcementErrorResponseOrNull(HttpLlmResponse httpLlmResponse, HttpRequest request) Strict structured-output enforcement, opt-in viaCompletion.getEnforceOutputSchema(). When enforcement is enabled and the completion's configuredtextdoes not conform to its declaredoutput schema, returns a provider-correct errorHttpResponse(status 502, with thex-mockserver-structured-output-invaliddiagnostic header) so the mock fails loudly rather than returning a non-conforming body. Returnsnullwhen 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_schemamode, 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 byHttpActionHandler, mirroringchaosErrorResponseOrNull(org.mockserver.model.HttpLlmResponse)), so a strict streaming completion with a non-conforming body never begins streaming. -
streamingFormatFor
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
Handle streaming LLM response by producing a list of SSE events. Called by HttpActionHandler when streaming is detected.- Parameters:
httpLlmResponse- the LLM response actionrequest- the original HTTP request- Returns:
- list of SSE events to be sent through the SSE handler
-
chaosErrorResponseOrNull
Returns an errorHttpResponse(status + optionalRetry-After) when the chaos profile triggers a probabilistic error, ornullotherwise. AnerrorStatuswith noerrorProbabilityalways fires; a fractional probability draws once (reproducible viaseed). Applies to both streaming and non-streaming responses — a provider error is a normal HTTP response, not an SSE stream.
-