Build your own RAG pipeline
Assemble, generate, cite·15 min

The grounded prompt

0 / 1
# grade this stage (from your course directory)
npx theinference test --stage prompt-template --watch

Wrap 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.

The template (pinned, exact)
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

Your task

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.

src/assemble.ts
export function buildPrompt(question: string, contextString: string): string {
  return `${SYSTEM_PREAMBLE}\n\nContext:\n${contextString}\n\nQuestion: ${question}\nAnswer:`;
}
How it's graded

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 grounding contract

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.