Skip to content
Streak:0Loading your progress…Sign in

Module 13 · Lesson 2 of 2

Prompt vs RAG vs fine-tune

Choose the right lever, then prepare data properly if you do fine-tune. ~25 min

Lesson notes

Decision ladder: (1) better prompts + examples — cheapest, fastest to iterate; (2) RAG when the model needs knowledge it doesn't have or that changes (docs, tickets, catalogues); (3) fine-tuning when you need a consistent style/format/behaviour at scale, a smaller/cheaper model to match a bigger one on a narrow task, or lower latency. Fine-tuning teaches *behaviour*, not reliable new facts.

Fine-tuning data is usually chat-formatted JSONL: one example per line, each {"messages": [{"role": "system"|"user"|"assistant", "content": ...}]} ending with the assistant response you want. Quality beats quantity: a few hundred clean, diverse, deduplicated examples often beat thousands of noisy ones. Always hold out an eval set first.

Practice

  1. 1. Validate a fine-tuning dataset

    medium25 XP

    Write validate_jsonl(text) -> (valid_examples, errors). Each non-blank line must be JSON with a messages list; roles must be system (optional, only first), then alternating user/assistant starting with user and ending with assistant; every content a non-empty string. Duplicate examples (identical messages) after the first are errors. Errors are strings "line N: <reason>" (1-based). Reasons: invalid json, missing messages, bad roles, empty content, duplicate.

    Ctrl/⌘ + Enter runs the tests · Esc then Tab leaves the editor

  2. 2. Pick the lever

    Quizmedium10 XP
    A customer wants their support bot to answer questions about product docs that change weekly. What's the best first approach?