Module 5 · Writing the answer
Lesson 5.2
The prompt
The prompt is the fixed rules, the sources, and the question, sent together as one text.
The problem
Why it matters
Without it
The model gets the question alone. It answers from memory and cannot name a source.
With it
The model gets rules, labeled sources, and the question. It answers from the sources and names them.
How it works
The rules never change
A prompt has three parts: fixed rules, labeled sources, and the question. The rules stay the same for every request. Only the sources and the question change.
Same for every request
- The rules
- The rule numbers
Changes per request
- The labeled sources
- The question
What stays the same between requests, and what changes. Each rule is a numbered line
The code writes each rule as a numbered line. A new rule is one more string in the list. The numbers let a reader point to one rule by its number.
const rules = [ "Answer only from the sources below.", "Name the source id for every fact you use.",];const numbered = rules.map((rule, i) => i + 1 + ". " + rule);console.log(numbered.join("\n"));Output
1. Answer only from the sources below. 2. Name the source id for every fact you use.
The parts join into one text
The parts are joined with headings and blank lines. The model reads this one text from top to bottom, so the order matters. The question comes last, after the sources it must use.
- Rules
- Sources
- Question
- One prompt text
The three parts, joined top to bottom into one prompt. const sources = "[faq-12] Refunds take 5 to 7 days.";const question = "How long do refunds take?";const prompt = [ "Sources:", sources, "", "Question: " + question,].join("\n");console.log(prompt);Output
Sources: [faq-12] Refunds take 5 to 7 days. Question: How long do refunds take?
Where each part sits
The rules sit at the top, so every source is read under them. The sources follow, and the question is last. Only the last two rows change from one request to the next.
Order Part Changes per request? 1 Rules no 2 Sources yes 3 Question yes The order the model reads the parts in, and what changes.
Common mistakes
What goes wrong
- Mixing the question into the rules. Keep each part under its own heading, so the model can tell them apart.
- Writing a rule the sources cannot meet. If no source covers a case, the rules must say what to do.
- Changing the rules without a test. A new rule can change many answers, so run the eval set after each change.
Use it when and skip it when
Is it the right tool?
Use it when
- Answers must come only from your documents.
- You want the same answer format and the same rules for every question.
Skip it when
- The model only answers general questions and no sources are involved.
- A plain lookup already returns the exact answer.
Words to know
Terms in this lesson
- Prompt
- The full text sent to the model for one request.
- Rule
- A fixed instruction that the model must follow.
- Source
- A chunk of text that the answer must rely on.