Sub topic 2
Is it missing knowledge or behaving wrongly?
This chapter assumes you have called a chat-style LLM API, can read Python, and know what an embedding and a context window are. It covers the first diagnostic step in choosing an adaptation approach: deciding whether a bad output comes from a knowledge gap or a behavior gap.
Why diagnosis comes first
Prompting, retrieval-augmented generation (RAG), and fine-tuning fix different problems. If you pick the wrong one, you spend effort and the failure stays. A team that fine-tunes a model to "learn the product catalog" usually gets confident, outdated, wrong answers. A team that builds a retrieval system to fix inconsistent tone gets the same inconsistent tone with extra latency.
The two categories are:
- Knowledge gap: the model lacks a fact it needs. The fact may be private (your refund policy), recent (last week's release), or rare (an obscure internal API). The model's wording and format may be fine, but the content is wrong or invented.
- Behavior gap: the model has, or is given, the facts but responds in the wrong way. It uses the wrong format, ignores a rule, writes in the wrong tone, picks the wrong label, or reasons badly about a task.
A single bad answer can contain both. The goal is to find which one dominates, then fix it first.
Symptoms of each gap
| Symptom | Likely gap | Why |
|---|---|---|
| Invents a policy, price, or function name | Knowledge | The fact is not in the weights or the prompt |
| Gives an answer that was true last year | Knowledge | Training data has a cutoff date |
| Says "I don't know" about your internal terms | Knowledge | Private data was never seen |
| Returns prose when you asked for JSON | Behavior | The model knows the content, but not your format |
| Answer varies in tone between runs | Behavior | Style is not pinned down |
| Ignores "reply with one word" | Behavior | Instruction following is weak for this phrasing |
| Misclassifies edge cases despite clear labels | Behavior | The model needs examples of the boundary |
| Wrong answer even when the right text is in the prompt | Behavior | The model has the knowledge but does not use it correctly |
The last row matters. If the correct fact is already in the context and the model still answers wrongly, retrieval will not help. You need better instructions, examples, or possibly fine-tuning.
A diagnostic test: supply the answer
The most reliable way to separate the two gaps is to give the model the missing fact by hand and see whether the output improves. This is a controlled experiment, and it takes minutes.
- Pick a failing example from real usage.
- Find the correct fact yourself and paste it into the prompt as context.
- Run the request again.
If the output is now correct, the original failure was a knowledge gap. The model can use the fact once it sees it. If the output is still wrong, you have a behavior gap, because the fact was available and the model still failed.
The same logic works in reverse for behavior. Add a clear instruction and two worked examples to the prompt. If the format or label becomes correct, the gap was behavioral and a cheap prompt change fixes it.
Worked example: a support assistant
Suppose you build a ticket assistant for a software company. You collect three failures.
- A user asks, "Can I get a refund after 45 days?" The model answers "Yes, within 60 days." Your policy says 30 days.
- You ask for a one-word label. The model replies "This looks like a billing issue."
- A user asks about the new "Teams" plan, released last month. The model says no such plan exists.
Apply the supply-the-answer test.
- Failure 1: paste the refund policy into the prompt. The model now answers correctly. This is a knowledge gap (private data).
- Failure 2: no fact is missing. Adding "Reply with one word" and two examples fixes it. This is a behavior gap.
- Failure 3: paste the plan description. The model answers correctly. This is a knowledge gap (fresh data).
Here is a small harness that runs the test. It sends the same question with and without the supporting fact, so you can compare outputs side by side. The call_model function is a stand-in that you replace with your own API call.
def call_model(messages):
# Replace this with a real chat API call that returns the reply text.
raise NotImplementedError("connect your model client here")
def with_fact(question, fact):
return [
{"role": "system", "content": "Answer the customer's question."},
{"role": "user", "content": "Context:\n" + fact + "\n\nQuestion: " + question},
]
def without_fact(question):
return [
{"role": "system", "content": "Answer the customer's question."},
{"role": "user", "content": question},
]
def diagnose(question, fact, is_correct):
"""Return 'knowledge', 'behavior', or 'ok' for one failing example."""
plain = call_model(without_fact(question))
if is_correct(plain):
return "ok"
supplied = call_model(with_fact(question, fact))
if is_correct(supplied):
return "knowledge"
return "behavior"
# Example of a checker for the refund question.
def mentions_30_days(answer):
return "30" in answerThe is_correct argument is a function you write. For short factual answers a string check is enough. For longer answers you may need a rubric or a human reviewer. Chapter three of this tutorial covers building an evaluation set properly. Here, one example at a time is fine.
Counting patterns, not single failures
One failure tells you little. Collect twenty to fifty failures from real traffic or realistic test cases, label each as knowledge or behavior, and count. The distribution guides your plan.
| Pattern in your failures | What it suggests |
|---|---|
| Mostly knowledge gaps about changing documents | RAG is the likely lever |
| Mostly behavior gaps fixed by clearer prompts | Stay with prompting |
| Mostly behavior gaps that survive prompt changes | Fine-tuning becomes a candidate |
| An even mix | Expect to combine approaches, but fix the larger share first |
This tally is the evidence you later use in the decision framework. Without it, the choice rests on preference.
Edge cases and traps
Knowledge the model has, but cannot reach
Sometimes the fact is in the model's training data, yet it answers wrongly because the question is phrased unusually or the fact is rare. Supplying the fact in the prompt fixes it, so it looks like a knowledge gap, and RAG or a prompt reminder is the right remedy. The test cannot tell "never learned" from "learned weakly." Both are treated the same way: put the fact in the context.
Long context that the model ignores
If you paste the fact into a very long prompt, the model may miss it. Models tend to use information at the start and end of a long context more reliably than information in the middle. If the supply-the-answer test fails with a long context, retry with only the relevant passage. If a short context works, the gap is a retrieval and context-size problem, not a missing skill.
Reasoning failures that look like knowledge gaps
A model asked to compute a prorated refund may give a wrong number. The policy text is in the prompt, so the facts are present. The failure is in applying the rule. This is a behavior gap. Better step-by-step instructions, worked examples, or a tool such as a calculator function help more than extra documents.
Safety and policy refusals
If the model refuses a valid request, that is a behavior gap. No document fixes it. Adjust the system prompt to state the legitimate context, or review whether the refusal is correct.
Hallucination as a mixed signal
A hallucination is a confident invention. It usually appears when the model lacks a fact and is not told to admit uncertainty. It has two fixes: supply the fact (knowledge) and instruct the model to say it does not know when the context lacks the answer (behavior). Treat it as a knowledge gap first, and add the behavior instruction as a guard.
A classification helper
You can record your labels in code so the counts are reproducible. This helper tallies labeled failures.
from collections import Counter
def tally(labels):
"""labels is a list of 'knowledge' or 'behavior' strings."""
counts = Counter(labels)
total = sum(counts.values())
return {name: round(count / total, 2) for name, count in counts.items()}
failures = ["knowledge", "behavior", "knowledge", "knowledge", "behavior", "knowledge"]
print(tally(failures))Running this prints {'knowledge': 0.67, 'behavior': 0.33}. With a split like this, you would address the knowledge share first, probably through context supplied at query time, and then check whether the behavior failures remain.
What to do with the diagnosis
The diagnosis does not choose the final approach by itself. It narrows the options and tells you which later chapters apply.
- Knowledge gaps point toward giving the model facts at query time, which is the subject of the RAG chapters.
- Behavior gaps that respond to clearer instructions and examples point toward prompting.
- Behavior gaps that resist prompting point toward fine-tuning.
Before changing anything, record your baseline: the failures, their labels, and the current pass rate. The next chapter shows how to turn those failures into an evaluation set, so you can prove that a change helped.
Exercise
A model asked about your company's parental leave policy answers with a plausible but wrong number of weeks. You paste the correct policy into the prompt and rerun, and the answer is now right. Which gap is this, and why is fine-tuning a poor first fix?
Show answer
It is a knowledge gap. The model could use the fact once it was in the context, so the fact was missing, not the skill. Fine-tuning is a poor fix because it changes behavior more reliably than it stores facts, and the policy would go stale whenever it changes. Supplying the policy at query time (RAG or a pasted passage) keeps the answer current.
Exercise
You paste the correct refund policy into the prompt, but the model still computes the wrong prorated amount. Which gap is this, and what would you try first?
Show answer
It is a behavior gap. The fact is present, so the failure is in applying the rule. Try step-by-step instructions, one or two worked examples of the calculation in the prompt, or a calculator tool. Only if those fail would fine-tuning become a candidate.
Exercise
Why should you label twenty to fifty failures instead of fixing the first one you find?
Show answer
A single failure may be a one-off or a lucky or unlucky run. Counting labeled failures shows which gap dominates, so you pick the approach that addresses most of the problems. The tally also becomes the evidence and baseline for the later decision.