Turn production traces into regression tests
Convert representative production failures into sanitized, reproducible evaluation cases that protect future LLM and agent releases.
![]()
Production traces contain the cases that matter most: real user intent, changing context, tool behavior, latency, cost, and the exact path that produced an outcome. Yet many teams inspect a failure, patch the prompt or code, and move on without preserving the evidence.
Turning a production trace into a regression test makes the fix durable. The test reproduces the important conditions, defines the expected behavior, and runs against future models, prompts, retrieval configurations, tools, and application releases.
What is a trace-derived regression test?
A trace-derived regression test is a versioned evaluation case created from a production interaction or workflow. It preserves the minimum context needed to reproduce a confirmed behavior while removing or protecting sensitive and unstable details.
For an LLM application, the case may include the user request, conversation context, retrieved evidence, prompt variables, model configuration, output, and expected quality criteria.
For an agent, it may also include tool schemas, initial state, simulated tool results, expected actions, prohibited actions, and the final environment state.
The objective is not to replay every production request verbatim. It is to convert a meaningful failure into a controlled test with a clear reason for existing.
Why production traces improve evaluation coverage
Designed test sets reflect what the team expects users and systems to do. Production exposes what they actually do.
Trace-derived cases add:
- Natural phrasing, ambiguity, and multi-turn context.
- Real combinations of tasks and constraints.
- Tool, retrieval, and provider failure behavior.
- Long-tail inputs that synthetic generation may miss.
- Interactions between application versions and live data.
- Examples connected to user feedback or business outcomes.
- Concrete evidence behind latency and cost regressions.
These cases help keep offline evaluation representative as the application, users, and external dependencies change.
Start with an observable production path
The trace needs enough lineage to support attribution and reproduction. Record:
- Trace, session, task, and application-release identifiers.
- Model provider, model, and inference parameters.
- Prompt or message template and version.
- Retrieval query, index version, ranked document identifiers, and selected context.
- Tool definitions, sanitized arguments, results, errors, and retries.
- Agent, router, policy, and state-schema versions.
- Evaluator results, user feedback, and task outcome.
- End-to-end latency, tokens, cost, and important span timing.
AI agent tracing provides the causal structure. Without version and state context, a trace can show that a failure happened without making it reproducible.
Decide which traces should become tests
Not every trace deserves a permanent case. Prioritize evidence with durable learning value.
Confirmed quality or safety failures
Promote unsupported answers, incorrect actions, permission violations, bad citations, missed escalations, or other behavior the team has verified as unacceptable.
High-impact incidents
Preserve rare cases with a large user, operational, financial, or compliance consequence even when traffic volume is low.
New task types and segments
Add production behavior that is not represented in the existing dataset, including new languages, tools, document sources, workflows, or user groups.
Evaluator disagreements
Cases where an automated evaluator conflicts with a knowledgeable reviewer are useful for improving both the application and the evaluator calibration set.
Expensive or slow trajectories
Promote traces that complete successfully but use unnecessary model calls, large context, repeated tools, or avoidable retries.
Repeated failure clusters
When many traces share the same underlying defect, select representative cases rather than storing every duplicate. Keep frequency as metadata so priority is not lost.
Convert a trace into a safe, stable test
1. Confirm and categorize the failure
Have an owner verify what failed and where it originated. Assign a category such as retrieval recall, groundedness, tool selection, argument construction, handoff context, policy, loop, latency, or cost.
Do not create a regression test from negative feedback until the expected behavior is understood.
2. Minimize the case
Remove steps and context that do not influence the failure. A smaller case is easier to understand, cheaper to run, and less likely to become brittle.
Minimization should preserve the causal condition. If the failure depends on a long conversation or a specific sequence of tool results, retain that structure.
3. Sanitize sensitive data
Remove or replace personal data, credentials, customer content, internal identifiers, and confidential tool results. Use realistic synthetic substitutes when the value's shape matters.
Record the sanitization method and restrict access to any original trace. The test dataset should have its own retention and permission policy.
4. Stabilize external dependencies
Snapshot required documents, use a versioned test index, or reference immutable fixtures. Replace state-changing tools with controlled test implementations or recorded responses where appropriate.
Keep contract behavior realistic. A mock that always succeeds cannot reproduce a retry or partial-failure bug.
5. Define expected and prohibited behavior
Specify the outcome rather than one exact string or reasoning path unless exact behavior is required.
An agent case might define:
- Required tool or state transition.
- Allowed alternative trajectories.
- Prohibited actions.
- Required clarification or escalation.
- Final response requirements.
- Latency, call-count, and cost limits.
6. Attach complementary evaluators
Use deterministic assertions for state, schemas, tool arguments, permissions, citations, and budgets. Use calibrated model-based or human evaluation for semantic properties.
7. Record provenance
Store the source incident or trace identifier, date added, owner, failure category, severity, affected release, and fix that motivated the case. Preserve the relationship without copying sensitive content into broadly accessible metadata.
Define a regression-case schema
A consistent schema makes cases portable across local testing, CI, scheduled evaluation, and release review.
| Field | Purpose |
|---|---|
| Case ID and version | Stable identity and change history |
| Source and provenance | Why the case exists and which incident it represents |
| Input and initial state | Reproducible starting conditions |
| Application dependencies | Prompt, model, retrieval, tool, policy, and schema versions |
| Fixtures | Documents, tool responses, environment state, or simulator behavior |
| Expected outcome | Task-level success definition |
| Required and prohibited actions | Trajectory, policy, and safety constraints |
| Evaluators | Deterministic, model-based, or human-review instructions |
| Budgets | Latency, calls, tokens, and cost boundaries |
| Segments and severity | Reporting and release-policy context |
Keep mutable review notes separate from the executable case definition where possible.
Avoid brittle regression tests
Generative systems can produce several valid responses and trajectories. Exact string matching or one required chain of reasoning often creates false failures.
Prefer:
- Structured claims or required facts instead of exact prose.
- Verified final state instead of a confirmation sentence.
- Allowed and prohibited tool sets instead of one exact sequence.
- Semantic rubrics calibrated with examples.
- Range or percentile budgets instead of a single observed latency.
- Invariants that remain meaningful across model providers.
Use exact matching for identifiers, structured fields, policy text, tool arguments, and other properties where variation is not acceptable.
Example: a failed refund-agent trace
A customer asks whether a delayed order is eligible for a refund. The agent retrieves the correct policy, calls the refund tool, and reports success. The user later discovers that no refund occurred.
Trace review shows that the tool returned pending_approval, but the agent interpreted every non-error response as completion.
The regression case contains:
- A sanitized customer request and order state.
- The relevant policy fixture.
- A refund tool that returns
pending_approval. - An assertion that the agent must not claim completion.
- An expected escalation or status explanation.
- A check that no duplicate refund call occurs.
- A task-level latency and call-count budget.
The fix updates the tool-result handling and prompt instructions. Future changes must pass the case even if the response wording or safe trajectory differs.
Build a production-to-evaluation workflow
- Detect a quality, safety, reliability, latency, or cost signal.
- Query traces from the affected release and segment.
- Group similar failures and choose representative examples.
- Assign an owner to confirm cause and expected behavior.
- Sanitize and minimize the case.
- Create stable fixtures and evaluators.
- Run the case against the failing version to confirm reproduction.
- Run it against the candidate fix and broader evaluation suite.
- Add the case to the appropriate release gate.
- Monitor production for the same failure category after release.
The failing version should fail the new test. Otherwise, the case or evaluator may not preserve the defect.
Manage the regression suite over time
Organize by task and risk
Use tags for failure category, task, language, source, tool, user segment, severity, and policy domain. This supports targeted evaluation and segmented reporting.
Track duplicates and clusters
Maintain the production frequency and impact associated with a representative case. A deduplicated suite should not make a common failure look rare.
Review stale cases
Products, policies, tools, and acceptable behavior change. Periodically verify that the expected outcome remains valid and that fixtures still model production realistically.
Separate release blockers from diagnostics
Critical safety and policy cases may block every release. Broader quality cases may use regression budgets. Expensive simulations can run on a schedule rather than for every small change.
Measure suite effectiveness
Track how many production incidents correspond to an existing case, how often tests catch a regression before release, evaluator disagreement, runtime and cost, and the age of unreviewed production candidates.
Common trace-to-test mistakes
Copying raw production content into the dataset
This creates privacy and retention risk. Sanitize, minimize, and control access before promotion.
Preserving the symptom without the cause
A final response alone may not reproduce a retrieval, tool, or state failure. Keep the relevant trace context and fixtures.
Requiring one exact agent path
Allow safe alternative trajectories unless the sequence itself is a requirement.
Adding cases without ownership
Unreviewed trace dumps create a large, low-trust suite. Require a failure definition, expected behavior, and responsible owner.
Never retiring or revising cases
Stale policy and tool assumptions can produce false regressions. Version changes and document why expectations changed.
Tracking pass rate without production impact
Connect cases with the frequency and severity of the failures they represent. Prioritize evaluation work using user impact, not test count.
Polyaxon and the production feedback roadmap
Polyaxon's tracking and orchestration capabilities provide a foundation for capturing versioned runs, artifacts, metadata, and automated evaluation workflows. Teams can preserve dataset and application lineage while scheduling repeatable regression suites.
Full OpenTelemetry-compatible LLM and agent observability and generative AI evaluation are active areas on the Polyaxon roadmap. The direction is to select a production trace, create a governed evaluation case, test a fix, and compare the released outcome through a connected lifecycle.
Make every failure teach the system
A production incident that ends with a one-time patch is likely to return in another form. A trace-derived regression test converts the team's investigation into reusable evidence.
Capture the path, minimize and sanitize the case, define the expected outcome, and attach the right evaluators. Use offline and online evaluation to keep the release and production loops connected. Over time, the suite becomes a practical memory of production behavior and a guardrail for faster, safer change.