Class LlmDatasetExporter

java.lang.Object
org.mockserver.llm.analysis.LlmDatasetExporter

public class LlmDatasetExporter extends Object
Turns captured LLM sessions (the same request/response pairs the optimisation report is built from) into datasets that off-the-shelf eval / fine-tune tooling consumes:

The prompt messages are decoded from the request via the provider ProviderCodec; the "ideal"/expected/assistant turn is decoded from the captured response via the provider LlmClient. Both the request and the response are pushed through FixtureRedactor before any content is emitted, and free-text credential shapes are additionally masked with LlmOptimisationBriefRenderer.maskSecrets(java.lang.String), so an exported dataset never leaks Authorization / api-key headers, configured body fields, or a key a user pasted into a prompt.

Pure and deterministic — no network, no LLM call. Lives in mockserver-core so the control-plane REST endpoint and the MCP tool share one implementation.

  • Constructor Details

    • LlmDatasetExporter

      public LlmDatasetExporter()
  • Method Details

    • export

      Export the given exchanges in the requested format. Non-LLM exchanges (and those whose request cannot be decoded to any message) are skipped, mirroring the optimisation report's inclusion rule. A null/empty input yields an empty JSONL document (for the JSONL formats) or an empty {"tests":[]} document (promptfoo), so callers never have to null-check the result.
      Parameters:
      exchanges - the captured request/response pairs (chronological)
      format - the target dataset format
      redactor - the redactor applied to every request and response before emission