LyraLearn AI Learning Platform
Exams
← Module 3 Β· Prompt Engineering
🎧 Listen

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.

A blueprint of a prompt as five ordered stacked sections β€” role, rules, context, task, and output format β€” being assembled by code.

The roles

Most chat models accept messages with roles:

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:

  1. Role & goal β€” "You are a grounded assistant helping a learner…"
  2. Rules & constraints β€” "Answer only from the provided context. Cite sources. If the context doesn't cover it, say so."
  3. Context β€” the retrieved material, clearly delimited and labeled as data.
  4. The task β€” the user's actual question.
  5. 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:

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.

🧠 Quiz yourself on this lesson →

Ask the AI Tutor

Grounded in the course lessons β€” it cites its sources and says when it doesn't know.