← Blog
July 22, 20266 min readSeldon

Clustering 12,517 LLM traces without an LLM: contract features beat LLM summaries

Trace AuditClusteringCompiler

Historical post. This describes Trace Audit as it worked in July 2026. Seldon retired Trace Audit in October 2026. Seldon now optimizes a request you choose with Functions. The clustering result below still holds.

We grouped 12,517 LLM traces by their input/output contract, then clustered within each group using DBSCAN on a short feature string. The method reached 1.000 pair precision, 0.9999 recall and 1.000 purity with almost no model cost. Replacing the features with LLM-written summaries made the clusters less pure.

The question

Many production LLM calls repeat one task with different inputs: the same prompt template and the same output schema, applied to different invoices or tickets. Seldon wanted to find those repeated tasks so it could replace them with cheaper programs.

That required answering one question for every pair of traces: do they perform the same replaceable task? Two traces about invoices are not the same task if one returns JSON fields and the other returns a paragraph. Two span-extraction calls about different entities are the same task.

A common approach is to summarize each trace with an LLM, embed the summaries and cluster by similarity. That groups traces by topic, which is the wrong grouping for this purpose.

The method

Contract-first clustering pipelineOpenAI-format tracesExtract contract features in codeGroup traces with identical contractsSkip tiny or prose-only groupsCluster inside each group with DBSCAN
  1. Group traces by contract. Traces share a group only if they match on workspace, message roles, response mode (text, JSON or tools), schema or tool signature, output shape, JSON keys and task type. Prompt length is deliberately excluded.
  2. Drop groups that cannot be replaced. Groups that are tiny or contain only free-form prose are skipped.
  3. Cluster inside each group. Each trace becomes a short string of its contract features, with names, amounts and other variable values removed. DBSCAN clusters those strings at a cosine similarity of about 0.82.

The data

We built 12,517 OpenAI-format traces from about 10% of each public training split, plus a few hand-written examples.

SourceTaskTraces
Banking77Intent classification1,000
SQuADAnswer-span extraction8,759
CoNLL-2003Entity to ID1,404
STS-BPair similarity574
GSM8KNumeric answer747
Hand-written invoice, issuer and prose examplesMixed30
Adversarial traces that bridge two tasksMixed3

After skipping tiny and prose-only groups, 12,504 traces remained. Their raw inputs had 2,109 distinct values, and their feature strings had 998. The features collapse traces that perform the same task.

Results

Every method used the same groups, the same skipping rule and the same similarity cutoff. Only the text being clustered changed.

Text clusteredPrecisionRecallPurityNotes
Contract feature string1.0000.99991.000No model cost
Deterministic summary1.0000.99991.000Same score, more work
GPT-4.1 summary0.9660.9980.9208.2% of summaries degraded
GPT-5.6 Luna summary0.9660.9880.9200.6% of summaries degraded
Phi-4 summary1.0000.7711.000Stopped early on a subset

What we learned:

  • Grouping does the work. With the clustering algorithm fixed, summaries added nothing over the feature string.
  • LLM summaries lower purity. They reintroduce topic words that the features had removed.
  • Cleaner summaries still lost. Luna produced far fewer bad summaries than GPT-4.1 and clustered no better.
  • No incompatible merges. No method merged traces with different contracts, because the grouping step prevents it.
  • The cheapest method was the best. The feature-string method cost about $0 in model calls.

LLMs remain useful after clustering, for naming clusters and writing descriptions people can read.

Two bugs that mattered more than the model

Recall was stuck near 0.73 for every method until we fixed two bugs in the grouping key:

  1. Length buckets. The key split identical tasks into short, medium and long prompts. We removed length from the key.
  2. Numbers typed as spans. The key treated some numeric answers, such as years, as extracted text. We now treat a number as a span only when the prompt asks for extraction and the number appears as a whole token in the input. Computed answers, as in GSM8K, stay numeric.

After those fixes, recall rose to about 0.999 with no loss of precision. The design of the grouping key mattered more than the choice of embedding.

We also compared DBSCAN with mutual nearest-neighbor graphs at the same cutoff. DBSCAN recovered far more recall. Adding text-based edges to the graph method raised its recall but caused merges that lowered purity.

Limits of this result

  • The ground-truth labels come from the source datasets and line up with the contract features by construction. Real customer traffic is the harder test.
  • The hand-written invoice, issuer and prose examples repeat templates.
  • Phi-4 ran on an early-stopped subset because its hosted endpoint was slow. The GPT runs used the full set.
  • Public NLP benchmarks do not match any production mix, so treat the scores as specific to this test set.

Open beta

Route your traffic through Seldon and investigate recurring work that could benefit from a specialized program.

Sign up for open beta →
Clustering 12,517 LLM traces without an LLM: contract features beat LLM summaries | Seldon