Anatomy of a Good Prompt
A prompt is the program you write for a language model. In an application, prompts aren't typed by hand β they're assembled by code from parts, the same way every time. Knowing the parts, and what each is for, is the foundation of reliable AI features.

The roles
Most chat models accept messages with roles:
- System β the standing instructions: who the assistant is, what it must and must not do, the rules of engagement. This is where you set behavior and guardrails.
- User β the actual request, plus any context the model needs to answer it.
- Assistant β the model's prior replies, included to give a conversation memory.
Putting rules in the system message (not buried in the user text) makes them clearer to the model and harder to override.
The parts of a strong prompt
A well-built prompt usually contains, in order:
- Role & goal β "You are a grounded assistant helping a learnerβ¦"
- Rules & constraints β "Answer only from the provided context. Cite sources. If the context doesn't cover it, say so."
- Context β the retrieved material, clearly delimited and labeled as data.
- The task β the user's actual question.
- Output format β how the answer should be shaped, if it matters.
Be specific and bounded
Vague prompts get vague, drifting answers. Strong prompts are specific ("answer in 3 short steps with a citation per claim") and bounded ("use only the context above"). Every degree of freedom you leave open is a degree the model can wander in.
Prompts are code β treat them that way
Because the application builds prompts programmatically, they deserve the same care as any code:
- Keep them in one place (a prompt assembler), not scattered through controllers.
- Version them and review changes β a prompt edit can change behavior as much as a code edit.
- Test them against examples, since you can't unit-test exact model output.
LyraLearn assembles the Tutor's prompt in a single PromptAssembler: a system message with the
grounding rules, then the question and the retrieved context in a clearly fenced block. Same
structure, every time β which is exactly what makes its behavior predictable.