Sub topic 1
What a system prompt is and how roles work
Prerequisites
Assume you can call an LLM chat API, read JSON, and follow basic Python code. This chapter focuses on prompt design rather than API authentication or model selection.
Message roles and instruction priority
A system prompt is a controlled instruction that defines how an LLM-powered application should behave. It usually states the assistant’s job, limits, and response format. The application sends it separately from changing user content.
Chat APIs commonly use three roles:
- System: application-owned instructions that set the assistant’s behavior.
- User: the current request and its supplied content.
- Assistant: a previous model response, sometimes included as an example or conversation history.
The exact priority rules depend on the provider, but application instructions should not be placed in user content. Keeping roles separate makes the boundary between policy and input clearer.
You are a support assistant for Acme Billing.
# Task
Answer invoice questions using only the supplied documents.
# Rules
- If the documents do not answer the question, say so.
- Do not provide legal or tax advice.
# Output
Return one JSON object with "answer" and "sources" fields.State the task, role, and audience
Start with an observable task. “Be helpful” is vague; “answer invoice questions using the supplied documents” is testable. Describe the role when it adds useful behavior, such as “support assistant” or “technical editor.”
State the audience when it changes the response. For example, tell the model whether it is writing for a customer, an operator, or a developer. These details reduce ambiguity, but they do not replace specific constraints.
Organize sections and delimiters
Short headings make instructions easier to maintain. Delimiters mark dynamic content as data rather than instructions.
<documents>
<document index="1">Invoice 104 is overdue.</document>
</documents>
<question>When is payment due?</question>Tell the model how to interpret each region. A delimiter alone does not create a security boundary.
Write constraints the model can follow
Use concrete rules with clear outcomes. Specify what the model must do, must not do, and should do when information is missing. Avoid conflicting rules such as “be concise” and “include every detail.” Prefer “answer in three sentences or fewer.”
Exercise
Where should a rule such as “return valid JSON” be placed?
Show answer
In the system prompt, because it is an application-owned constraint rather than user-supplied data.