Injecting Context Into Messages
Context
Part of: Chat Roles & Messages
You build a support bot and bolt on a search index so it can quote your docs. The retrieval works perfectly, the right paragraph comes back every time, yet the bot still hallucinates. The bug isn't retrieval. It's placement : the retrieved text got buried somewhere the model under-weights. Where context lives in the message list quietly decides whether the model trusts it. What it is Injecting context means inserting retrieved documents, database rows, or background facts into the message list so the model can use them. This is the heart of RAG (retrieval-augmented generation): you fetch relevant text, then place it into the messages before sending. The two common homes are the system message (stable, always-on context) and a dedicated user block right before the question (per-question, freshly retrieved context). How it works You don't paste docs into the user's actual question. You give the context its own clearly delimited block, usually a user message placed just before the real question: Three placement choices matter: - System vs user. Stable instructions ("only use the context") go in the system message. The retrieved text itself usually goes in a user block, because it chan
Challenge: RAG Prompt Builder