Walk through one training example for SFT'ing a single weather-tool call.
A team wants to fine-tune a 7B chat model so it reliably calls a single `get_weather(city)` tool. Write out, end to end, what ONE training row in the SFT JSONL looks like, the message turns, the roles, what gets masked from the loss, and at least one important negative example you'd also include. Explain why each piece is there.
A positive row is four turns: user, assistant tool call, tool result, assistant grounded reply. Loss runs only on the two assistant turns, and the dataset must include negatives so the tool is not called for everything.
Picture training a new librarian to use one reference book. You stage a conversation where someone asks a real reference question, the librarian flips open the book, the book shows the page, and the librarian reads the answer aloud. You grade the librarian only on two moments: opening the right book and explaining the right page in plain words. You do not grade what the patron said or what the book literally printed. You also stage other conversations where the patron asks something the book cannot answer, and you teach the librarian to just talk normally without grabbing the book. Without those second kinds of conversations, the librarian learns to grab the book for every question and looks silly when someone asks the time.
Detailed answer & concept explanation~8 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
5 min: four-turn row shape + role of each turn + loss masking on user and tool turns + why both assistant turns matter + negative rows for over-invocation + argument variety + scaling considerations.
Real products, models, and research that use this idea.
- OpenAI's hosted fine-tuning API for gpt-5.5-class tool-calling models accepts JSONL with exactly this four-turn shape and rejects rows that put tool output under the assistant role.
- Anthropic's Claude Opus 4.7 tool-use API uses a similar messages contract, with tool_use and tool_result blocks distinguishing the two non-natural language turns.
- Hugging Face TRL's SFTTrainer supports chat templates that automatically mask user and tool turns when the role-marker format matches the model's tokenizer config.
- Berkeley's Gorilla and Toolformer projects established the convention that negative rows are essential for stable tool-call SFT, a pattern every 2026 production stack now follows.
What an interviewer would ask next. Try answering before peeking at the approach.
QHow would you scale this design from one tool to a fleet of fifty tools?
QWhat changes if you also want to teach parallel tool calls in one assistant turn?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Training only on positives where the tool is called. The model latches on to the shape question equals tool call and starts firing get_weather at trivia questions, the classic over-invocation failure mode.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.