Sub topic 14
Maintenance and common failure modes
This chapter assumes you have read the earlier chapters on prompting, RAG, and fine-tuning. It also assumes you can read Python, have called a chat-style LLM API, and know what an embedding and a context window are. You will learn how each approach breaks over time, how to notice the break, and what routine keeps a working system working.
Why adaptation needs upkeep
A system built from a prompt, a retrieval index, or a fine-tuned model works on the day you ship it. Three things then change without your involvement:
- The world changes. Prices, policies, and product names go out of date.
- The inputs change. Users ask questions you did not predict.
- The model changes. Providers retire model versions and update hosted ones.
Each approach has a different part that goes stale. Prompting depends on a fixed model reading a fixed text. RAG depends on an index that mirrors your documents. Fine-tuning depends on a frozen snapshot of examples. Knowing which part goes stale tells you where to look when quality drops.
Failure modes in prompting
Prompt drift. Prompts grow by patches. Someone adds a rule to fix one bad output, then another rule, and soon the rules contradict each other. Each patch fixes one case and may break three others. The cure is to treat the prompt as code. Keep it in version control and change it only when the evaluation set shows no regression.
Model version change. A prompt tuned for one model version can behave differently on the next. A hosted alias such as "latest" can change under you. Pin an explicit model version where the provider allows it. Re-run your evaluation set before you move to a new version.
Context crowding. Few-shot examples, long instructions, and retrieved text all share one context window. Adding more of one can push out another, or bury the instruction the model needs. Long contexts also raise cost and latency on every call.
Example overfitting. The model may copy the surface of your few-shot examples. If all three examples are labeled billing, it may over-predict billing. Vary the examples and balance the labels.
Failure modes in RAG
RAG has the most moving parts, so it has the most ways to fail. Debug it in two stages: did retrieval find the right passage, and did the model use it correctly?
Stale index. Documents change, but the index still holds old chunks. The model answers confidently from outdated text. Fix this with an update pipeline. Re-embed changed documents, delete chunks from removed documents, and store a timestamp or version with every chunk.
Retrieval miss. The answer exists in your documents, but the top results do not contain it. Common causes are chunks that split an answer across two pieces, chunks too large to match a specific question, and queries worded differently from the document. Log the retrieved passages for every request. Without them you cannot tell a retrieval failure from a generation failure.
Embedding mismatch. Vectors from different embedding models are not comparable. If you change the embedding model for new documents but keep old vectors, similarity scores become meaningless. When you change the model, re-embed everything.
Ignored or misused context. The passage is in the prompt, but the model answers from its own memory, or blends the passage with a guess. Stronger grounding instructions help, such as the "say you don't know" rule from the earlier chapter. Evaluation cases whose correct answer is "not in the documents" test it directly.
Conflicting sources. Two documents give different answers, for example an old policy and a new one. The model picks one or merges them. Remove superseded documents from the index, or attach dates to chunks and tell the model to prefer the newest.
Access control leaks. If the index mixes documents with different permissions, retrieval can place text in the prompt that the user is not allowed to see. Filter by permission at retrieval time, before the text reaches the model.
Failure modes in fine-tuning
Frozen knowledge. A fine-tuned model does not learn new facts reliably, and any facts it did absorb age. Do not use fine-tuning to store facts that change. If the facts change monthly, you would be retraining monthly.
Narrow overfitting. If the training set is small or repetitive, the model memorizes phrasing. It does well on inputs that resemble training examples and worse on everything else. Hold out part of your data, and compare training and held-out scores.
Regression on general ability. Tuning on one task can degrade others, sometimes called catastrophic forgetting. Include a few general-purpose cases in your evaluation set to catch this.
Bad labels in, bad behavior out. The model learns your examples exactly, including their inconsistencies. If two annotators labeled similar tickets differently, the model learns the confusion. Audit a random sample of training data before every training run.
Base model retirement. A fine-tuned model sits on top of a base model. When the provider retires that base, your tuned version may go with it, and you must retrain on the new base. A LoRA adapter (a small set of added weights) is tied to the exact base model it was trained on. Keep your training data and training configuration, not just the resulting weights.
Failures that cross all three approaches
- No evaluation set, so no detection. Most quality loss is silent. Users get slightly worse answers, and nobody notices for weeks. The evaluation set from the "measure first" chapter is your detector.
- Evaluation set that goes stale. If it never receives new cases, it measures last quarter's traffic. Add real failures from production to it regularly.
- Fixing the wrong layer. Teams often fine-tune to fix a retrieval miss, or add documents to fix a formatting problem. Go back to the diagnosis step: a knowledge gap and a behavior gap need different fixes.
- Unmonitored cost and latency. RAG adds a retrieval step and longer prompts. Few-shot examples add input tokens to every call. Track both, because they grow quietly.
- Prompt injection through retrieved text. A retrieved document can contain instructions such as "ignore previous rules." Treat retrieved text as data. Tell the model to do so, and limit what actions the model can take.
A regression gate you can run
Whatever you change, whether a prompt, an index, or a model version, run the same evaluation set and compare it to the stored baseline. The sketch below works with any function that takes an input string and returns an output string.
def run_eval(generate, cases):
"""Return the fraction of cases where the output matches the expected label."""
passed = 0
for case in cases:
output = generate(case["input"]).strip().lower()
if output == case["expected"]:
passed += 1
return passed / len(cases)
def regression_gate(generate, cases, baseline_score, max_drop=0.02):
"""Fail the change if the score falls more than max_drop below the baseline."""
score = run_eval(generate, cases)
ok = score >= baseline_score - max_drop
return ok, score
cases = [
{"input": "I was charged twice this month.", "expected": "billing"},
{"input": "The export button crashes the app.", "expected": "bug"},
{"input": "Do you have a student discount?", "expected": "other"},
]
def fake_model(text):
# Stand-in for a real model call, so the example runs as shown.
if "charged" in text or "invoice" in text:
return "Billing"
if "crash" in text:
return "bug"
return "other"
ok, score = regression_gate(fake_model, cases, baseline_score=1.0)
print(ok, round(score, 2))Replace fake_model with a call to your real system. For RAG, also record which passages were retrieved for each case, so a failure points to retrieval or generation.
What to check, and when
| Approach | What goes stale | Trigger to re-check | Routine task |
|---|---|---|---|
| Prompting | Instructions vs. model behavior | Prompt edit, model version change | Run the evaluation set before every change |
| RAG | Index contents, chunking, embeddings | Document updates, embedding model change | Re-embed changed documents; review retrieval logs |
| Fine-tuning | Training data and base model | Policy change, base model retirement | Audit data; retrain from stored data and configuration |
| All | The evaluation set itself | Production failures | Add real failures as new test cases |
The maintenance loop
Practical habits
- Version everything. Keep the prompt, the model version, the embedding model, the chunking settings, and the training data under version control. When quality drops, you can compare against the last good configuration.
- Log inputs, retrieved passages, and outputs. You cannot debug what you did not record. Mind privacy: redact personal data and set retention limits.
- Change one thing at a time. If you change the prompt and the chunk size together, you cannot tell which one helped.
- Review a sample of real traffic. Automated scores miss new kinds of failure. Reading 20 real conversations a week finds problems the evaluation set does not cover yet.
- Plan for retirement. Know the deprecation dates of your model versions. Keep a runnable path to rebuild: stored data, stored configuration, and an evaluation set that tells you whether the rebuild is good enough.
Exercise
A RAG support bot starts giving the old refund policy after the policy page was rewritten last week. Retrieval logs show the old page is returned and the new page is not. Name the failure mode and two fixes.
Show answer
This is a stale index, possibly combined with conflicting sources. Fix it by re-embedding the rewritten page and deleting the chunks from the old version, and by running that update automatically whenever documents change. Storing a version or timestamp with each chunk lets you detect and remove superseded content in future.
Exercise
Your fine-tuned classifier scores well on a held-out set, but a month after launch users report poor results on a new product line. Which failure is most likely, and what do you do first?
Show answer
The most likely failure is narrow overfitting to the training distribution, together with an evaluation set that no longer reflects real traffic. First, add the failing production inputs to the evaluation set to confirm the drop and get a new baseline. Then add correctly labeled examples of the new product line to the training data and retrain, or check whether a prompt or retrieval change fixes it more cheaply.
Exercise
Why is it risky to switch a hosted model alias from an older version to a newer one without a test run, even when the newer model is generally better?
Show answer
Your prompts, few-shot examples, and output-format rules were tuned against the old model's behavior. The new version may interpret instructions differently, change formatting, or respond differently to your examples, so your specific task can regress even when general quality improves. Running the evaluation set against the new version and comparing it to the baseline shows whether this has happened.