liveBook · Manning

System prompt

As explained in Build Applications with Local AI Models on a Mac

A system message supplies instructions that guide an AI model's behavior in a conversation.

A system prompt is an instruction placed in a conversation’s system message. It gives an AI assistant a job description: its role, tone, and rules. Without one, the model behaves like a generic helpful assistant. A prompt can make the same model answer as a study buddy, a concise expert, or a tutor with a distinctive voice. section 13.1 section 13.2

Messages have three roles: system for guiding behavior, user for the human’s request, and assistant for previous model responses. Put the system message first. It frames the responses that follow, but it does not change the model’s trained weights or give it new knowledge. section 7.2.1 section 13.1

import ollama

response = ollama.chat(
    model="gemma3:4b",
    messages=[
        {
            "role": "system",
            "content": "You are a friendly science teacher who explains "  #1
                       "concepts using fun analogies. Keep your answers "  
                       "under 100 words."   
        },
        {
            "role": "user",
            "content": "How does gravity work?"
        },
    ],
)

print(response["message"]["content"])

This Python request puts a friendly science-teacher instruction before the gravity question. The instruction asks for analogies and an answer under 100 words. section 7.2.2

Change the instruction, keep the question

Ask “How does gravity work?” with the science-teacher prompt, then replace it with a prompt for a dramatic stage actor. Compare the answers’ style. If a small model ignores the instruction, make it more explicit or try a larger model. section 7.2.2 section 7.2.3

To use a system prompt in a chatbot:

  • Choose instructions that fit the job, such as simple explanations for a study buddy or brief answers for a quick fact check. section 13.2.5 section 13.5.1
  • Send the system message with the retained conversation history and each new user message on every request; the model does not manage that history for your code. section 13.5.1 section 7.6
  • Keep the prompt’s job distinct from generation settings: the prompt guides the task and presentation, while temperature affects how predictable or creative the response is. section 13.3

Use a system prompt to change personality or answer format, not to supply a collection of reference facts. For specific knowledge, consider RAG; for a change to fundamental model behavior, consider fine-tuning. A prompt is an instruction, not a retraining step. section 16.6.1 section 13.1

How Build Applications with Local AI Models on a Mac covers it

How deep it goes
Defines message roles and order, then demonstrates prompt changes and per-request chatbot assembly; stops short of changing model weights.
Examples
Contrasts science-teacher and dramatic-actor answers to a gravity question, then uses personality presets in a Streamlit chatbot.
What it assumes
Introduces the three message roles from zero and demonstrates their use in Python and Streamlit.
What you can do after
Apply it via Ollama’s Python library and Streamlit to customize a chatbot’s personality and response style.
How it connects
Connects system prompts to conversation history, temperature, RAG, and fine-tuning.

Also explained in

Compare how 2 books explain system prompt →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build Applications with Local AI Models on a Mac. The section links point to the parts of the book it draws on.