MCPInstall

building-finetuning-datasets

Use when preparing to fine-tune, post-train, distill, or LoRA/QLoRA-tune an LLM, when generating synthetic or instruction training data, building SFT/DPO/preference sets, reasoning traces or tool-call trajectories, when choosing rank/alpha/learning rate, when deciding fine-tuning vs RAG, or when a tuned model regressed — hallucinates, lost general ability, repeats, or ignores its format.

Installs
59
Last 24h
—
Trending rank
—
Security
Not audited

Install

Works with every agent the skills CLI supports.

npx skills add https://github.com/osmontero/opencode-skills --skill building-finetuning-datasets
  1. 01

    Install

    Run the command in your project. The CLI asks which agents to install for.

  2. 02

    Describe the task

    Ask your agent for something this skill covers. It loads building-finetuning-datasets automatically when relevant.

  3. 03

    Review the result

    The agent follows the SKILL.md steps, scripts and references bundled with the skill.

SKILL.md

The instructions your agent reads when the skill is triggered.

Building Fine-Tuning Datasets

A fine-tune is its dataset. Hyperparameters decide whether training converges; the dataset decides what the model becomes. Most disappointing fine-tunes are correctly-configured runs over data that encoded the wrong thing.

Two failures cause most of the damage, and both are settled before a single example is generated: teaching facts that belong in retrieval, and having no way to detect that the model got worse at everything else.

Gate 1: Is this a knowledge problem?

If the goal contains "so it knows our X" — product names, runbook facts, current inventory, policy details — that part is a retrieval problem, and fine-tuning is the wrong tool for it.

Models acquire facts in pretraining; fine-tuning teaches them to use what they have. Examples carrying genuinely new facts are learned much more slowly than ones consistent with existing knowledge, and as they finally are learned they linearly increase the model's tendency to hallucinate (Gekhman et al., EMNLP 2024, measured on closed-book QA). The rate is measured over the whole evaluation, not just the newly taught items — so the cost lands on factuality generally, and it grows the longer you train to make the new facts stick.

Split the request explicitly before proceeding:

Part of the goalWhere it goes
Facts, documents, entities, anything that changesRAG
Format, structure, house style, toneFine-tuning
Task procedure, tool-call syntax, reasoning styleFine-tuning
Domain vocabulary and question shapes over retrieved contextFine-tuning, with facts still retrieved at inference

Say which parts you routed where. A user asking for one thing usually wants both halves solved, not the retrieval half silently folded into the training set.

Gate 2: Which technique

Stage and parameter budget are independent choices. Read references/choosing-technique.md before committing — it covers prompt/RAG/decoding alternatives, continued pretraining vs SFT vs preference optimization vs RL, DPO/KTO/ORPO/SimPO selection, full FT vs LoRA vs QLoRA, and required stage ordering.

Short version: if you can write the correct output, SFT. If you can only say which of two outputs is better, preference optimization. If a script can verify correctness and SFT has plateaued, RL. Default parameter budget is LoRA, or QLoRA when VRAM-bound.

Gate 3: Does the base model already do it?

Before generating data for any capability or behavior, probe the base model on it — a couple dozen samples across the cases you care about — and only keep the slices it measurably fails. This is Gate 1's knowledge rule generalized: fine-tuning is for what the model gets wrong, and training a slice it already handles is not neutral.

The two costs are real and documented:

  • Wasted effort. A team building a behavior dataset probed their base model and found it already passed one entire behavior at ~94% with no reproducible failure pattern — they dropped 150 rows that would have taught nothing.
  • Active regression. The same narrow behavioral fine-tune, ~750 rows, caused a measurable general-capability regression on four reasoning benchmarks (grade-school math down ~10–16pp) that nobody saw until the benchmark panel ran, because the run had no eval split. Every row you add can cost capability elsewhere; rows that teach nothing pay that cost for no gain.

So the probe is not optional diligence — it decides what goes in the dataset. Keep the confirmed-failing cases, resample the ambiguous ones (a 1-of-3 refusal is sampling noise, not a failure — single-shot refusal evaluation is only ~92% accurate, Larsen et al. 2025), and drop what the base model already does. Report confirmed categories as a rate ("2/3", "3/3"), not a binary: a 2/3 confirmation is a watch-item, not a solved one, since under pure noise it still confirms ~26% of the time, and it is exactly the category to re-probe after the next training run.

The deliverable

A fine-tuning dataset is not a file of examples. It ships as eight parts, and a handoff missing any of them cannot be evaluated or reproduced. Deliver them in this order — the order is the method:

  1. eval/ — the held-out suite, built first. Real examples only, reserved before generation. Three subsets: task (held-out real examples of the target behavior), retention (general-capability probes the base model already passes), behavior (refusals, safety, tone invariants to preserve).
  2. baseline.json — the base model scored on all three subsets before any training. Without this there is no denominator and "it looks good" is not a result.
  3. taxonomy.md — the axes the data must cover, with a target count per cell. Diversity comes from varying what you condition on, so the axes have to exist on paper before generation and be re-counted after filtering. Empty cells are the next generation round's target, not an acceptable outcome.
  4. train.jsonl / val.jsonl / test.jsonl in messages format, split by source document so synthetic siblings never straddle the boundary, deduplicated at all three levels (exact, near-duplicate, semantic), and decontaminated against every eval set you intend to report.
  5. The replay mix — task data blended with general instruction data at a stated ratio, so the model does not lose what it already had.
  6. A verified format contract — which loss-masking flag matches your dataset format (assistant_only_loss for messages, completion_only_loss for prompt/completion), which EOS token the chat template actually emits, and confirmation of both by decoding one training batch. A wrong flag trains on the user's turns and a wrong EOS produces a model that never stops; neither shows up as a bad loss curve, which is why this is a checked artifact rather than a habit.
  7. card.md — provenance. Seed source, generator model and version, generation prompts, filters and thresholds, dedup and decontamination method, counts per taxonomy cell, license and terms.
  8. config.yaml — the training config, with the eval curve enabled so overfitting is visible while it happens.

Building the eval set first is what stops the dataset from being optimized toward whatever the generator happened to produce.

Write every prose artifact skeleton-first, one section per edit. A single tool call cannot emit more than roughly a thousand tokens, and the plan, taxonomy, and card all run longer, so a one-shot write truncates mid-string and the call fails. Write the file with its headings and a one-line stub under each, then replace one stub per edit. Start this way rather than falling back to it — the skeleton costs nothing and the sections land in the same number of edits either way.

Generate with a script, not by hand

You write the pipeline; the pipeline writes the data. Emitting training examples yourself, one at a time into a JSONL file, is the wrong shape for this work no matter how few examples you need:

  • It does not scale. Three hundred examples at ~800 tokens each is far past what any agent can emit, and you will produce a truncated file while believing you produced a dataset.
  • It is not reproducible. A dataset you cannot regenerate is one you cannot fix. A script plus a seed, a pinned generator model, and a versioned prompt can be re-run when you find a defect.
  • The generation loop is genuinely a loop. Generate into taxonomy cells → verify → filter → dedup → re-count coverage → generate into the cells that came up short. That cycle runs several times and cannot be done by hand.
  • Filtering needs code anyway. MinHash near-duplicate detection, embedding nearest-neighbor thresholds, and n-gram decontamination are not eyeball operations.

So the artifacts you hand-author are the inputs: the taxonomy, the generation prompts, the seed examples, the filter thresholds. Everything downstream is produced by running something.

scripts/generate.py and scripts/curate.py in this skill are a working reference pipeline — taxonomy-driven generation with resume, then dedup, decontamination, and a coverage report. Read them, adapt the prompts and taxonomy to the task, and run them; they are a starting point, not a framework. Prefer extending them over writing a pipeline from scratch.

Order of work

digraph finetune_data {
    rankdir=TB;
    "Split knowledge from behavior" [shape=box];
    "Behavior part non-empty?" [shape=diamond];
    "Route to RAG; stop" [shape=doublecircle];
    "Choose stage + parameter budget" [shape=box];
    "Write eval suite from real data" [shape=box];
    "Score base model -> baseline.json" [shape=box];
    "Define taxonomy of axes to cover" [shape=box];
    "Generate wide" [shape=box];
    "Verify, filter, dedup, decontaminate" [shape=box];
    "Coverage gaps remain?" [shape=diamond];
    "Blend replay data" [shape=box];
    "Train with eval curve" [shape=box];
    "Gates pass vs baseline?" [shape=diamond];
    "Ship with card.md" [shape=doublecircle];
    "Diagnose: data or config?" [shape=box];

    "Split knowledge from behavior" -> "Behavior part non-empty?";
    "Behavior part non-empty?" -> "Route to RAG; stop" [label="no"];
    "Behavior part non-empty?" -> "Choose stage + parameter budget" [label="yes"];
    "Choose stage + parameter budget" -> "Write eval suite from real data";
    "Write eval suite from real data" -> "Score base model -> baseline.json";
    "Score base model -> baseline.json" -> "Define taxonomy of axes to cover";
    "Define taxonomy of axes to cover" -> "Generate wide";
    "Generate wide" -> "Verify, filter, dedup, decontaminate";
    "Verify, filter, dedup, decontaminate" -> "Coverage gaps remain?";
    "Coverage gaps remain?" -> "Generate wide" [label="yes, target the empty cells"];
    "Coverage gaps remain?" -> "Blend replay data" [label="no"];
    "Blend replay data" -> "Train with eval curve";
    "Train with eval curve" -> "Gates pass vs baseline?";
    "Gates pass vs baseline?" -> "Ship with card.md" [label="yes"];
    "Gates pass vs baseline?" -> "Diagnose: data or config?" [label="no"];
    "Diagnose: data or config?" -> "Generate wide";
}

The loop back from coverage gaps is the step most pipelines skip. Generation is cheap and filtering is destructive, so generate wide and filter down — then look at which taxonomy cells came out empty and generate specifically into those, rather than running the same unconditioned loop again and getting the same modes back.

Quality over quantity, with numbers

Within a fixed budget, curated hundreds beat unfiltered tens of thousands for general instruction and style — the consistent result across LIMA (1,000 curated competitive against 50k), AlpaGasus, and LIMO (817 reasoning traces). That is what those papers measured, and it does not transfer to overriding a base prior (a safety refusal, a strong default): there the behavior needs both a minimum count and a minimum share of the mix, and a small set of rephrased variants of a handful of scenarios is the least-favorable regime for "less is more." Judge which regime you are in before reaching for the quality-over-quantity conclusion. Typical ranges:

GoalExamples
Format / structure conversion100–1,000
Style, tone, voice500–2,000
Classification / extraction50–500 per class
General instruction following1,000–10,000
Reasoning distillation800–10,000 verified traces

When a run underperforms, doubling the data is usually the wrong reflex — and specifically wrong when the extra rows are rephrasings of scenarios you already have: at a fixed update budget, repeating a small set causes the same world-knowledge forgetting as scaling, and a narrow, repetitive dataset is the mode-collapse setup. The data move that does help retention is adding new general replay, not more of the target behavior. Check in this order: LR (retention-side, first), then target modules, then diversity, then mix.

Degradation gates

Run these against baseline.json before calling a fine-tune successful. Each maps to a documented failure mode, and passing the task metric while failing these is the most common way a bad model ships.

GateCheckAction if it fails
TaskTarget metric improved on held-out real examplesThe fine-tune did nothing — check LR and target modules
RetentionAbove run-to-run noise (≥1 SE at your n) on capabilities the base already passedA single-digit drop on a few benches is a common LoRA-SFT outcome, not "catastrophic" (the literature's catastrophe is a bench near 0, e.g. SLIM's MMLU→0.00). Fix in this order: lower LR (retention-side, see lora-configuration.md) and add a replay mix — the evidence-backed levers — then a val split + small lora_dropout as cheap overfitting control, then fewer epochs
FactualityHallucination rate not above baseYou taught unknown facts — move them to RAG
SafetyRefusal behavior preservedSafety alignment degrades even from purely benign data (Qi et al., ICLR 2024) — add safety examples to the mix
FormatOutputs terminate and parseEOS or chat-template bug, not a data problem
DiversityOutputs not collapsed to one phrasingOverfitting — fewer epochs, lower LR, or scale alpha by 0.5

Measuring only the task metric is how a model that got 10 points better at one thing and 15 worse at everything else gets shipped.

References and scripts

Read the reference you need; do not load all five.

FileCovers
references/choosing-technique.mdRAG/prompting alternatives, CPT vs SFT vs DPO vs RL, DPO/KTO/ORPO/SimPO, full FT vs LoRA vs QLoRA, stage ordering
references/synthetic-generation.mdQuality/diversity/complexity tradeoff, Self-Instruct, Evol-Instruct, Magpie, personas, doc-grounded QA, self-chat, trajectories, distillation, verification and judge bias, model collapse, licensing
references/data-quality.mdEval set construction, sizing, dedup levels, decontamination, balance, mix-share to override a base prior, messages format, loss masking, EOS, chat templates, split leakage, dataset cards
references/lora-configuration.mdrank, alpha, target modules, LR, schedule, packing, dropout/val as regression levers, rsLoRA/DoRA/LoRA+/PiSSA, worked configs, symptom-to-knob table, merging
references/avoiding-degradation.mdForgetting mechanisms, replay ratios and sources, unknown-knowledge and unknown-capability detection, safety regression, overfitting and collapse symptoms, gate thresholds

The scripts/ are a runnable reference pipeline — adapt, don't rewrite:

ScriptDoes
scripts/generate.pyTaxonomy-driven generation against any OpenAI-compatible endpoint, resume-aware, records provenance per row
scripts/curate.pyMalformed-drop → exact/near-dup dedup → decontaminate against eval files → per-cell coverage report (stdlib only)

Common mistakes

MistakeWhy it bites
Fine-tuning to inject factsSlow to learn, and linearly increases hallucination as it does
alpha = 0.5rBackwards. Use alpha = 2r (or r); keep alpha/r ≥ 1
Targeting attention onlyMLP layers carry the higher-rank updates — target all linear layers
Splitting after augmentationSynthetic siblings straddle train/test and the score is fiction
No base-model measurementNo denominator; regressions are invisible
No replay data in the mixThe model gets the task and loses everything else
Raising temperature for diversityDiversity comes from varying conditioning — personas, taxonomy cells — not sampling noise
Trusting an unvalidated LLM judgePosition, verbosity, and self/familiarity-preference bias measure the wrong thing. For code quality, deterministic checks (syntax, execution, schema) are the validated layer — the judge is an advisory ranking, not a pass/fail gate
Deduplicating exact matches onlySynthetic pipelines overproduce semantic near-duplicates that exact hashing misses
Packing a small datasetNo throughput to gain on hundreds of rows, and cross-contamination risk on multi-turn data — leave it off
Training a slice the base model already passesWasted rows at best; every added row can cost capability elsewhere
No validation splitNo eval-loss curve means regressions stay invisible until the model ships
Ignoring the teacher's terms of serviceMajor API providers restrict training on their outputs; this blocks release, not development

FAQ

What does the building-finetuning-datasets skill do?

Use when preparing to fine-tune, post-train, distill, or LoRA/QLoRA-tune an LLM, when generating synthetic or instruction training data, building SFT/DPO/preference sets, reasoning traces or tool-call trajectories, when choosing rank/alpha/learning rate, when deciding fine-tuning vs RAG, or when a tuned model regressed — hallucinates, lost general ability, repeats, or ignores its format.

How do I install building-finetuning-datasets?

Run npx skills add https://github.com/osmontero/opencode-skills --skill building-finetuning-datasets in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/building-finetuning-datasets/ (personal) or .claude/skills/building-finetuning-datasets/ (project).

Which AI agents can use building-finetuning-datasets?

Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.

Is building-finetuning-datasets safe to install?

No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.

Who maintains building-finetuning-datasets?

It is published by osmontero in osmontero/opencode-skills. It has 59 recorded installs.

More from osmontero/opencode-skills

View all →

designing-frontend-interfaces

osmontero/opencode-skills

Use when building or restyling any web interface — landing pages, dashboards, marketing sites, web apps, React/Vue components, HTML/CSS layouts, artifacts, posters — or when asked to make a UI look better, more polished, more distinctive, less generic, or less "AI-generated". Also use when a design brief, art direction, visual identity, type scale, or color system is needed before implementation.

Frontend & Design650 installs

designing-user-experience

osmontero/opencode-skills

Use when designing how an interface behaves rather than how it looks — user flows, navigation and information architecture, forms and validation, loading/empty/error states, confirmation and undo for destructive actions, button and error message wording, feedback for slow operations, or mobile and touch behavior. Also use when a UI looks finished but breaks on bad input, slow networks, no data, or first use.

Frontend & Design462 installs

reviewing-interface-quality

osmontero/opencode-skills

Use when asked to review, critique, audit, or improve an existing user interface — "review this UI", "why does this look generic", "make this more polished", "design feedback", "does this look AI-generated", "audit this page". Also use as the final gate before shipping any frontend work, and when a UI renders correctly but feels unfinished, cheap, or inconsistent without an obvious cause.

Frontend & Design365 installs

building-accessible-interfaces

osmontero/opencode-skills

Use when building or auditing any web UI for accessibility — keyboard navigation, screen readers, focus management, ARIA, color contrast, form labels and error announcements, reduced motion, or touch target size. Triggers include "is this accessible", "WCAG", "a11y", "screen reader", "keyboard navigation", "focus trap", "contrast ratio", "aria-label", or building modals, menus, tabs, comboboxes, toasts, and custom controls that must work without a mouse.

Frontend & Design350 installs

systematic-debugging

osmontero/opencode-skills

Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes

verifying-before-completion

osmontero/opencode-skills

Use when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions always

157 installs

Popular ai & agents skills

View category →

google-agents-cli-publish

google/agents-cli

This skill should be used when the user wants to "publish an agent", "publish my ADK agent", "register an agent with Gemini", "publish to Gemini" (formerly Gemini Enterprise), or needs guidance on the agents-cli publish gemini command. Also use when the user wants to "manage agents in Agent Registry", "list/update/delete registered agents", or "register an MCP server". Covers ADK vs A2A registration modes, programmatic and interactive usage, flag reference, auto-detection from deployment metadata, Agent Registry fleet management, and troubleshooting. Part of the agents-cli skills suite. Do NOT use for deployment (use google-agents-cli-deploy).

AI & Agents513.9K installs

google-agents-cli-eval

google/agents-cli

This skill should be used when the user wants to "run an evaluation", "evaluate my agent", "evaluate my ADK agent", "write an eval dataset", "analyze eval failures", "compare eval results", "optimize agent", or needs guidance on the Gemini platform eval methodology and the Quality Flywheel. Covers eval metrics, dataset schema, LLM-as-judge scoring, and common failure causes. Applies to any agents-cli project, whatever framework the agent is written in. Do NOT use for agent API code patterns (ADK: use google-agents-cli-adk-code), deployment (use google-agents-cli-deploy), or project scaffolding (use google-agents-cli-scaffold).

AI & Agents513.5K installs

skill-creator

anthropics/skills

Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.

OfficialAI & Agents416.4K installs

codex-pet

prime-skills/runcomfy-agent-skills

Codex Pet generator on RunComfy. Build a Codex-compatible Codex Pet spritesheet.webp + pet.json from a single reference image, drop it into ${CODEXHOME:-$HOME/.codex}/pets/ / and Codex picks it up as a custom Codex Pet next to the 8 built-ins. This skill produces the exact Codex Pet atlas Codex expects (1536x1872 PNG/WebP, 8 cols x 9 rows, 192x208 cells, 9 animation states — idle, running-right, running-left, waving, jumping, failed, waiting, running, review). Calls OpenAI GPT Image 2 edit ONCE via the local RunComfy CLI as runcomfy run openai/gpt-image-2/edit to produce a canonical Codex Pet pose, then assembles all 9 animation rows programmatically with ImageMagick micro-transforms — no Codex Pro, no $imagegen, no OPENAIAPIKEY required, only RUNCOMFYTOKEN. Triggers on "codex pet", "create codex pet", "make codex pet", "hatch codex pet", "/hatch image", "desktop pet codex", "codex pets", "spritesheet.webp", or any explicit ask to build a custom pet for OpenAI Codex.

AI & Agents402.1K installs

full-output-enforcement

leonxlnx/taste-skill

Overrides default LLM truncation behavior. Enforces complete code generation, bans placeholder patterns, and handles token-limit splits cleanly. Apply to any task requiring exhaustive, unabridged output.

AI & Agents401K installs

executing-plans

obra/superpowers

Use when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available

AI & Agents245.7K installs