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 roughly what an embedding and a context window are. Before you pick prompting, RAG, or fine-tuning, you need to know what kind of failure you are looking at. The wrong diagnosis leads to the wrong lever and wasted weeks.
Two kinds of gap
A knowledge gap means the model lacks a fact it needs. Examples are your refund policy, last week's pricing, or the contents of an internal wiki. The model cannot know these because they were not in its training data, or they changed after training.
A behavior gap means the model has the facts but responds in the wrong way. Examples are a wrong output format, an inconsistent tone, ignoring a rule, or misclassifying inputs in a pattern.
| Symptom | Likely gap | Typical lever |
|---|---|---|
| Invents a policy or price | Knowledge | RAG |
| Cites outdated information | Knowledge | RAG |
| Correct facts, wrong format | Behavior | Prompting, then fine-tuning |
| Tone drifts between replies | Behavior | Prompting, then fine-tuning |
| Fails a task the facts do not affect | Behavior | Prompting, examples |
A diagnostic test
The fastest test is to paste the needed facts directly into the prompt and rerun the failing cases.
- If the answers become correct, the gap was knowledge. The model can reason with the facts once it sees them.
- If the answers are still wrong in the same way, the gap is behavior. More facts will not help.
Running the test in code
The sketch below reuses the grounded-prompt idea. You supply the facts by hand and compare results with and without them. Replace call_model with your own API call.
def call_model(prompt):
# Replace with a real chat API call that returns the reply text.
raise NotImplementedError
def diagnose(question, expected, facts):
plain = call_model(question)
with_facts = call_model(
"Answer using only the context below. "
"If the answer is not in the context, say you don't know.\n\n"
"Context:\n" + facts + "\n\nQuestion: " + question
)
return {
"correct_without_facts": expected.lower() in plain.lower(),
"correct_with_facts": expected.lower() in with_facts.lower(),
}Read the two flags together. False then True points to a knowledge gap. False then False points to a behavior gap, or to a flaw in how you wrote the facts. True then True means this case is not failing.
Common errors in diagnosis
- Treating hallucination as a behavior problem. A model that invents a return policy usually has no access to the real one. Training it to sound more careful does not supply the policy.
- Treating style problems as knowledge problems. Adding retrieval will not fix a model that ignores your JSON schema.
- Testing on one example. One case can mislead you. Run a set of failing cases and count how many change.
- Mixed failures. Many systems have both gaps. Fix them one at a time and rerun the test after each change.
- Bad facts in the test. If the pasted context is incomplete or contradictory, a behavior-looking failure may really be a context problem.
What this means for the next steps
Diagnosis gives you a hypothesis, not a decision. The next chapter shows how to build an evaluation set so that you can measure whether a change helped. Cost, latency, and maintenance enter the choice later.
Exercise
A support bot answers "What is your current premium plan price?" with a price from two years ago. When you paste the current price list into the prompt, it answers correctly. Is this a knowledge gap or a behavior gap, and which lever fits first?
Show answer
It is a knowledge gap, because the model answers correctly once it sees the facts. The price changes over time, so RAG (or simply placing the current price list in the prompt) fits first. Fine-tuning would bake in prices that go stale again.
Exercise
A model has the right facts in its prompt but keeps replying in paragraphs when you need a one-word label. Pasting more facts changes nothing. What kind of gap is this, and what is the first thing to try?
Show answer
It is a behavior gap. Start with prompting: state the output format explicitly and add few-shot examples. Consider fine-tuning only if a measured evaluation shows the prompt cannot fix it.