<< Home | Prompting craft
Model refuses to answer outside provided context
| Area | Prompting craft |
| AI used | Any |
| Source | Reddit thread |
| Posted | unknown |
The move
Explicitly instruct the model to use only the provided context and ignore outside information.Steps
- Start the prompt with a strict instruction to use only provided context.
- Add a secondary rule to exclude any information not specifically discussed.
- Format the input with clear labels for question and context.
- Use the template: Answer the following question using only the context below. Only include information specifically discussed.
Prompt for your AI
Answer the following question using only the context below. Only include information specifically discussed. question: {question} context: {text}
What happened
The user struggled with 7B models hallucinating during RAG tasks. They found that adding strict constraints to the prompt significantly reduced off-topic answers. The technique was validated by the user's own examples in txtai.Who confirmed it
I have a number of examples showing this in txtai.Watch out
If the retrieval function is not optimized, the model may still struggle regardless of the prompt.Give it to your agent
Read https://howtheyuse.ai/p/model-refuses-to-answer-outside-provided-context.md and help me do this.