Skip to main content

Overview

This walkthrough demonstrates how to implement continuous fine-tuning using traces. You’ll learn how to:
  • Use your fine-tuned model for inference
  • Automatically evaluate model responses using a judge model (Claude 4.5 Sonnet)
  • Create traces with scores and feedback
  • Add ALL traces to your dataset (both successes and failures)
  • Let the API automatically improve low-quality outputs using judge feedback
  • Create new snapshots and launch iterative fine-tuning jobs that fix model weaknesses
Why This Matters: Models improve over time when you continuously gather production data, evaluate it, and learn from both successes and failures. Low-scoring responses identify where your model is weak - these are automatically corrected and used for training, so your model gets better at exactly what it struggles with. This creates a virtuous cycle of targeted improvement. What You’ll Build: A continuous fine-tuning loop that:
  1. Generates responses from your fine-tuned model using domain-specific test prompts
  2. Uses an AI judge to evaluate response quality (0-1 scale: feedback → reasoning → score)
  3. Creates traces with structured feedback
  4. Adds ALL traces to your dataset (both high and low-scoring) - low-scoring traces are automatically improved by the API
  5. Triggers a new fine-tuning job that learns from both successes AND corrected failures
CRITICAL: This workflow requires you to provide test prompts that match your fine-tuned model’s domain. Generic prompts will produce useless results. For example:
  • Invoice model? Test with actual invoice text
  • Stock analysis model? Test with financial questions/transcripts
  • Custom domain? Test with prompts from YOUR specific use case
Prerequisites: This walkthrough assumes you have already completed one of the previous workflows (JSONL, PDF, or YouTube) and have:
  • A project with at least one fine-tuned model
  • An existing dataset
  • A fine-tuned model ID/alias ready for inference
Export your Prem API key as API_KEY before running any script.
1

Define initial parameters and fetch dataset from project

2

Generate responses from your fine-tuned model

3

Evaluate responses with judge model

4

Create traces

5

Add all traces to dataset

Add all traces to dataset. Low-scoring traces are automatically improved by the API using judge feedback.
6

Create snapshot

7

Generate recommendations

8

Launch fine-tuning job

Full Example

Key Takeaways

  1. Explicit Prerequisites: This workflow requires a PROJECT_ID and FINETUNED_MODEL_ALIAS from a previous workflow. The DATASET_ID is automatically fetched from the project - no manual input needed!
  2. Automated Evaluation: Uses Claude 4.5 Sonnet as a judge to score responses (0-1 scale, where 0 is completely wrong and 1 is perfect)
  3. Learn from ALL Traces: Critical - Add ALL traces (both high and low-scoring) to the dataset! Low-scoring traces identify weaknesses
  4. Automatic Correction: The addToDataset endpoint automatically rewrites low-quality outputs using judge feedback, creating corrected training examples
  5. Structured Evaluation: The judge provides feedback, reasoning, and then score (in that order) for better evaluation quality
  6. Targeted Improvement: Each cycle adds new training data focusing on model weaknesses, creating progressively better models
  7. Production-Ready: Can be automated to run on a schedule, continuously improving your model with real-world data