Package org.mockserver.llm.analysis
Class LlmDatasetExporter
java.lang.Object
org.mockserver.llm.analysis.LlmDatasetExporter
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:
LlmDatasetExporter.DatasetFormat.OPENAI_EVALS— OpenAI-evals JSONL: one sample per line,{"input":[messages…],"ideal":"<assistant response>"}.LlmDatasetExporter.DatasetFormat.FINE_TUNE— chat fine-tune JSONL: one conversation per line,{"messages":[…,{"role":"assistant","content":…}]}(the prompt messages plus the captured assistant turn).LlmDatasetExporter.DatasetFormat.PROMPTFOO— a promptfoo test-suite JSON document:{"tests":[{"vars":{"messages":[…]},"assert":[{"type":"equals", "value":"<assistant response>"}]}]}.
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe supported dataset export formats. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionexport(List<LlmOptimisationReportBuilder.CapturedExchange> exchanges, LlmDatasetExporter.DatasetFormat format, FixtureRedactor redactor) Export the given exchanges in the requested format.
-
Constructor Details
-
LlmDatasetExporter
public LlmDatasetExporter()
-
-
Method Details
-
export
public String export(List<LlmOptimisationReportBuilder.CapturedExchange> exchanges, LlmDatasetExporter.DatasetFormat format, FixtureRedactor redactor) 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 formatredactor- the redactor applied to every request and response before emission
-