The grounded prompt
# grade this stage (from your course directory)
npx theinference test --stage prompt-template --watchWrap the assembled context in the deterministic instruction template the generator receives. The system rules — answer using ONLY the context, cite sources as [doc i], say you don't know if it's not there — are what make citations checkable and hallucinations refusable.
You are a helpful assistant. Answer the question using ONLY the context below. Cite the sources you use as [doc i]. If the answer is not in the context, say you don't know.
Context:
<assembled context>
Question: <question>
Answer:
What to build
Implement buildPrompt
Implement buildPrompt(question, contextString) to produce the exact template above: the fixed system preamble, a blank line, Context: then the context block, a blank line, then Question: <question> and Answer: on its own line. The prompt <q> <k> <budget> command prints it.
export function buildPrompt(question: string, contextString: string): string {
return `${SYSTEM_PREAMBLE}\n\nContext:\n${contextString}\n\nQuestion: ${question}\nAnswer:`;
}
process mode, stdout_exact. The prompt string must equal expected.txt exactly. This exact string is what gets hashed to key the cassette — one stray byte and the lookup misses.
The "answer ONLY from context, cite [doc i], else say you don't know" instruction is the grounding contract, not boilerplate. It's what makes the next two steps — generation and citation-correctness — checkable.