Skip to content

Trace-to-Preference

v0.26.0 turns traffic logs into DPO / KTO training data. Point soup data from-traces at LangChain, OpenAI, or Soup-serve logs. Soup extracts preference signals — thumbs, regenerations, user edits — and writes clean pairs.

Ingest a log

bash
soup data from-traces \
  --logs chat_logs.jsonl \
  --format langchain \
  --signal thumbs_up \
  --output prefs.jsonl

Flags

FlagMeaning
--logsJSONL trace file; for --format soup-serve it must be a directory (one holding the JSONL file or files that soup serve --trace-log writes; --trace-log itself takes a file path, and a directory there records nothing), and a single file is refused with exit 1
--formatlangchain · openai · soup-serve (with a hyphen: soup_serve is refused with exit 1)
--signalthumbs_up · regenerations · user_edit (regeneration, singular, is refused with exit 1)
--output / -oDestination JSONL (default prefs.jsonl). Since v0.77.1 it must not be the same file as --logs, so a --logs file named prefs.jsonl is refused under the default: exit 1, --output 'prefs.jsonl' is the same file as --logs 'prefs.jsonl'; choose a different --output (#2261)
--judgeKeep only pairs an LLM judge agrees with
--judge-provideropenai · server · ollama
--judge-modelModel id for the judge
--judge-api-baseJudge endpoint, validated against the SSRF guard: plain HTTP only for loopback, HTTPS for anything else, and since v0.75.2 never an IP address in a private, link-local or reserved range (see what v0.75.2 refuses), and, since v0.76.0, never a host written only as numbers that is not a valid IPv4 address (10.0.0.256, 4294967296)
--min-confidenceJudge-confidence floor, default 0.7

Signals

  • thumbs_up — a prompt with both a thumbs-up and a thumbs-down response becomes a pair: the thumbed-up output is chosen, the thumbed-down one rejected. A prompt with only thumbs-up feedback yields no pair. Since v0.77.2 (#2495) the two answers have to differ: each prompt gives at most one pair, taking the first upvoted answer and the first downvoted answer that is a different text, and if every downvoted answer equals that first upvote, a later upvoted answer that differs can still pair with it. A prompt whose upvoted and downvoted answers are all the same text yields no pair
  • regenerations — if the user hit regenerate, the later response is preferred
  • user_edit — if the user rewrote the response, the edit becomes chosen

What a trace record has to look like

The soup-serve parser reads a top-level signal in this vocabulary and falls back to a nested feedback.rating (up or down) for older logs:

json
{"prompt": "Q", "output": "Good", "signal": "thumbs_up"}
{"prompt": "Q", "output": "Bad",  "signal": "thumbs_down"}
{"prompt": "Q", "output": "Raw",  "signal": "user_edit", "edited_output": "Polished"}

On a three-row directory like the one above, --signal thumbs_up wrote {"prompt": "Q", "chosen": "Good", "rejected": "Bad", "source": "thumbs_up"} and --signal user_edit wrote the edited text as chosen and the original as rejected. Who writes what:

  • soup ingest is a producer. It writes one record per trace with trace_id, prompt, output, source, metadata and a top-level signal of thumbs_up, thumbs_down or none, so its output feeds this command directly. For a Langfuse --logs export, a score of 0, 0.0 or false becomes thumbs_down since v0.77.1 (through v0.77.0 it was dropped); see Trace ecosystem.
  • user_edit and regenerated rows come from your own pipeline. signal: user_edit has to accompany the edit field: a record with edited_output and no signal reads as "no trace carried a signal". The edit is read from edited_output, edited_response or a nested feedback.edited_output.
  • soup serve --trace-log records carry no signal (since v0.78.0 each is a version-1 conversation record: schema_version, id, conversation_id, ts as an ISO 8601 UTC string, model, version (always null), adapter, canary_bucket, messages, response, prompt, finish_reason, latency_ms, tokens as an object, source; no options field; see the field table), so harvesting that directory with from-traces builds nothing. The signal lives elsewhere: thumbs recorded through POST /v1/thumbs go to the database soup serve --record-thumbs writes, and thumbs, ratings, edits and comments posted to POST /v1/feedback go to the file --feedback-log names, joined to the answer by its response_id. Since v0.77.0 the pre-wired harvest of soup loop reads the thumbs database (soup loop init --thumbs-db), and since v0.78.0 it also reads the feedback log; from-traces reads the trace directory only and joins neither.

Migration (v0.78.0). A script of your own that reads a --trace-log line's ts as epoch seconds or tokens as one integer has to read both shapes. soup data from-traces and soup loop read both, and a line whose schema_version is not 1 is skipped by both. A line with no schema_version is version 0, the old shape, and is read as a single user message.

Through v0.75.2 the soup-serve parser read the signal only from a nested feedback.rating that no Soup producer writes, so soup ingest output and --trace-log records alike read as none, and --signal thumbs_up wrote an empty file and exited 0. Since v0.76.0 the top-level signal is read, and a harvest that reads traces but matches none says so. On a directory of --trace-log records it printed Read 1 trace(s) but built no pairs for --signal thumbs_up. No trace carried a signal. Check the record shape: ... and then Wrote 0 preference pair(s). That is still exit 0, so check the count line in a script rather than the exit code. A source that reads zero traces says so before the count line. A single trace file is capped at 100,000 lines (a warning says it was truncated); the directory of the soup-serve format is read in full, and a PII reminder panel prints on every run.

If you built a preference dataset with from-traces on an older release from soup ingest output, it is worth checking that it is not an empty file.

Which prompt a pair is grouped under (v0.77.0). Pairs are grouped by prompt. Since v0.77.0 the OpenAI and LangChain parsers, like soup ingest, keep a conversation's context through its last user turn: with no user or assistant turn before it (a system prompt plus one question included), the prompt is that user's plain text, and otherwise it is compact JSON of the role and content turns through the last user (#1848). See Trace ecosystem for the full rule.

Warning:

Re-run this (v0.77.0). Through v0.76.1 the OpenAI parser took a multi-turn trace's first user turn as its prompt, so answers from different conversations that opened the same way could become one preference pair; upstream now keeps "context through the last user turn so unrelated answers do not form preference pairs" (#1809, #1848). Build preference files from multi-turn traces again, including files written by soup ingest, and re-train a model trained on them.

Warning:

Re-run this (v0.77.2). Upstream, on soup data from-traces --signal thumbs_up and the harvest stage of soup loop: v0.77.1 "could write a pair whose chosen and rejected were identical, so the number of pairs from the same logs can change" (#2495 by @kok-o). If you built a preference file with either on v0.77.1 or earlier, build it again from the same logs and compare the pair count; soup data lint reports pairs whose chosen and rejected are the same text as identical_pairs. Run on v0.77.2: a prompt with one upvote and one downvote of the same text wrote no pair (Wrote 0 preference pair(s), exit 0), and a prompt with the upvotes Same and Other and the downvote Same wrote Other as chosen and Same as rejected. This covers the two commands upstream names, and in soup loop the trace-log half of its harvest stage. The recorded-thumbs database path (soup local-rl harvest, and the --thumbs-db half of the loop's harvest stage) is separate code that v0.77.2 did not change, and this note does not cover it.

Review before training

bash
soup data review prefs.jsonl --sample 10

Previews the first N pairs in the file, in file order (--sample / -s, 1 to 100, default 10), each with its prompt, chosen and rejected text cut to 400 characters. It is not a random sample, so it will not show you problems that only occur later in the file. Use it as a sanity check before burning a GPU on junk data.

Train on them

DPO or KTO — the output format of from-traces matches both:

yaml
base: Qwen/Qwen2.5-0.5B-Instruct
task: dpo
data:
  train: prefs.jsonl
  format: dpo

Safety

  • Logs never execute model code — parsers only read JSON.
  • Traces may contain PII or secrets; Soup warns on ingest and leaves scrubbing to you before sharing pairs externally.
  • A judge that stops answering stops the run. With --judge, each request is retried twice on a 429, a 5xx or a transport error. A pair whose judge call keeps failing is skipped and counted, but once 3 requests in a row have spent their retries unanswered the command exits 1, names the judge URL and how many pairs were not judged, and writes no output file (v0.76.0, #1522). Before, from-traces --judge waited out the retries for every pair against a judge that never answered, and then wrote an empty file with exit 0. This comes from the code and the changelog; it was not run here, because no judge endpoint was available.
  • Output JSONL can be validated with the same soup data validate pipeline as any other dataset.

See also

Soup is free and Apache-2.0. If it saved you a training run, starring the repo costs nothing and helps most. You can also fund the GPU time behind the work a 4 GB laptop cannot reach.