> ## Documentation Index
> Fetch the complete documentation index at: https://scorecard-d65b5e8a-mintlify-update-user-annotations-convers.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Tracing: Trace to Testcase

> Turn production traces into reusable testcases and build datasets from real traffic.

export const DarkLightImage = ({lightSrc, caption, alt, darkSrc = null, width = "1000"}) => {
  const getAbsoluteUrl = src => {
    if (src.startsWith('http://') || src.startsWith('https://')) {
      return src;
    }
    const currentUrl = typeof window !== 'undefined' ? window.location.origin : '';
    if (currentUrl.includes('.mintlify.app')) {
      const subdomain = currentUrl.split('.')[0].replace('https://', '');
      return `https://mintlify.s3.us-west-1.amazonaws.com/${subdomain}${src.startsWith('/') ? '' : '/'}${src}`;
    } else if (currentUrl === 'https://docs.scorecard.io') {
      return `https://mintlify.s3.us-west-1.amazonaws.com/scorecard-d65b5e8a${src.startsWith('/') ? '' : '/'}${src}`;
    } else {
      return `${currentUrl}${src.startsWith('/') ? '' : '/'}${src}`;
    }
  };
  const content = <>
      <img className="block dark:hidden" width={width} src={getAbsoluteUrl(lightSrc)} alt={alt} />
      <img className="hidden dark:block" width={width} src={getAbsoluteUrl(darkSrc || lightSrc.replace('light', 'dark'))} alt={alt} />
    </>;
  if (caption) {
    return <Frame caption={caption}>{content}</Frame>;
  } else {
    return content;
  }
};

<DarkLightImage lightSrc="/images/monitors/trace-to-testcase-toast.png" darkSrc="/images/monitors/trace-to-testcase-toast.png" caption="Create testcase from span." alt="Create testcase from span screenshot." />

Live traffic uncovers edge-cases synthetic datasets rarely catch. **Trace ➜ Testcase** lets you capture those moments, convert them into structured testcases, and bake them into your regression suite—all without leaving the trace view. This is production-to-dataset in one click.

## Why it matters

* Grow testsets from real user prompts and outputs.
* Reproduce tricky scenarios when evaluating new models or prompts.
* Track quality over time with consistent, production-grounded inputs.

## If you call it something else

* **Traces → Testcases**: Similar to “snapshotting” production examples into a labeled dataset. Scorecard streamlines it in the trace UI and auto-maps prompt/completion fields.
* **Where testcases live**: Saved into **Testsets** so you can re-run evaluations and compare **Runs & Results** over time.
* **What’s extracted**: Prompt and completion are pulled from common keys (`openinference.*`, `ai.prompt`/`ai.response`, `gen_ai.*`).

<DarkLightImage lightSrc="/images/monitors/trace-to-testcase-create.png" darkSrc="/images/monitors/trace-to-testcase-create.png" caption="Create testcase modal." alt="Create testcase modal screenshot." />

## How it works

1. Open any trace and drill down to the span that contains the LLM call.
2. Click **Create Testcase** (document icon).
3. Pick a **Testset** or create a new one.
4. Scorecard auto-extracts the prompt and completion from span attributes (`openinference.*`, `ai.prompt` / `ai.response`, `gen_ai.*`). Adjust fields before saving.
5. The testcase appears immediately in the selected testset.

<DarkLightImage lightSrc="/images/monitors/trace-to-testcase-select.png" darkSrc="/images/monitors/trace-to-testcase-select.png" caption="Select Testset dialog." alt="Select Testset dialog screenshot." />

<DarkLightImage lightSrc="/images/monitors/trace-to-testcase-select.png" darkSrc="/images/monitors/trace-to-testcase-select.png" caption="Create testcase result ." alt="Create testcase result screenshot." />

## Use cases

* create gold-standard datasets from production data
* run offline evaluations on real cases, and validate changes before deployment.

<Info>
  Automating this flow? Use the `/testcases` API to create testcases programmatically from traces.
</Info>
