Q&A-1Choose fine-tuning versus prompt, RAG, tools, or code.
Answer
Start with the simplest thing that could work. For most production LLM features, that's prompt engineering. If the model lacks private or current knowledge, add retrieval-augmented generation (RAG). If the task requires live computation or side effects, use tools (function calling). If the requirement is exact, auditable rules or authorization, put it in code. Fine-tuning is the last resort: it's for stable behavior, style, or output format that prompting can't reliably achieve, and only when you have enough high-quality examples to justify the training and lifecycle cost.
Assumptions: you have a working LLM application, a baseline prompt, and a way to evaluate outputs. You're choosing one or a combination.
Why retrieval beats tuning for freshness: fine-tuning updates model weights via gradient descent on your examples. That bakes facts into parameters, which become stale as soon as the world changes. RAG fetches documents at inference time, so freshness is bounded by your index update latency, not retraining. Tuning also can't reliably add new facts: it shifts the distribution of outputs, which may cause hallucination if you try to teach facts.
Why tools for live computation: a tool call is a structured request to an external function. The model doesn't compute; it emits a JSON payload. That gives you deterministic results, auditability, and access to real-time data. Code is for rules that must never be violated, like "only refund if amount < $100 and user is admin."
Trade-offs table (hypothetical figures, labeled):
| Approach | Latency added | Cost per 1k queries | Freshness | Control |
|---|---|---|---|---|
| Prompt | 0 ms | $0.50 | static | low |
| RAG | +50-200 ms | $1.20 | minutes | medium |
| Tools | +100-500 ms | $2.00 | real-time | high |
| Fine-tune | 0 ms (inference) | $0.30 + $100 training | frozen | medium |
| Code | <1 ms | negligible | real-time | exact |
Failure modes: Fine-tuning overfits to your examples; detection: eval score drops on held-out set, or format violations increase. Catastrophic forgetting: model loses general ability; detection: regression on unrelated tasks. RAG retrieval misses: detection: low recall on golden set, or answers cite wrong doc. Tools: API timeouts; detection: p99 latency spike, error rate. Code: brittle rules; detection: false rejections in logs.
Worked example: customer support bot. User: "What's my balance?" → tool call to get_balance(user_id). User: "How do I reset password?" → RAG over help center. User: "Write a friendly apology" → fine-tune on 500 examples of brand voice. User: "Refund if order < $50" → code rule. Trace: if you tried to fine-tune the balance question, the model would hallucinate a number. If you used RAG for balance, it would fetch stale docs. So the decision is driven by the nature of the gap.
Code snippet (tool definition):
{
"name": "get_balance",
"description": "Get current account balance",
"parameters": {
"type": "object",
"properties": {
"user_id": {"type": "string"}
},
"required": ["user_id"]
}
}What would change the decision: if fine-tuning became cheap enough to retrain daily, or if you had a small model and needed to reduce prompt length for latency, fine-tuning might win for style. If your knowledge base updates every second, RAG index latency matters. If tools are unavailable, you might simulate with code.
Curated: · Written: · Reviewed:
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.