Courses / Agentic AI from Scratch (Python)

Session 6 of 40

Prompt engineering 1: a prompt framework, zero-shot, one-shot, few-shot and persona

Notes

Prompt Engineering for Beginners: Prompt Framework, Zero-Shot, One-Shot, Few-Shot and Persona Prompts

Agentic AI Foundations · Session 6 — Prompt engineering 1: a prompt framework, zero-shot, one-shot, few-shot and persona

Before you start: what do you need to practise prompt engineering?

You need the setup from the first sessions: Python, the openai package, a model endpoint that accepts the OpenAI request format, and your three settings (LLM_BASE_URL, LLM_API_KEY and LLM_MODEL), typed at the top of helpdesk_agent.py or set in your terminal. Recap of what this session assumes: a Chat Completions request is a list of messages, each with a role (system, user or assistant), and the reply comes back as the next assistant message; and session 5 gave you helpdesk_agent.py, a helper whose model asks for tools and answers in JSON with answer, section and needs_human. The code folder for this session has the same helper, a model_prompts/ folder next to it, and the data/ folder the tools read. Run every command from the folder that holds helpdesk_agent.py. Have paper or a notes app ready for the Flashcards and the Model answer.

Summary: how do you improve a prompt with a framework, examples and a persona?

A prompt is the input you send a model to steer its reply, and a good one has four parts: an instruction, context, examples and the format you want back. A zero-shot prompt gives an instruction and no examples, so it rests on how clearly the instruction is written, while a few-shot prompt adds a handful of example inputs with the outputs you want, so the model picks up the pattern. A persona is the role you give the model, and it sits with the rules in the system message at the start of the message list, which the helper now reads from model_prompts/system.md. You improve a prompt by changing one thing at a time and running the same questions after each change, so you can see which change helped. This session ends with the helper’s prompt kept in a file, with its examples switched on or off by one setting.

Key concepts: prompt, zero-shot, one-shot, few-shot and persona defined

Term Definition
Prompt The input you send the model to steer its reply: an instruction, context, examples and the format you want back.
Instruction The part of a prompt that states the task, such as “answer the employee’s leave question in two sentences”.
Context The information the model should use to answer, such as the policy text for the question.
Zero-shot prompting Giving the model an instruction and no examples, so the result depends on how clear the instruction is.
Few-shot prompting Adding a handful of example inputs, each with the output you want, so the model picks up the pattern and applies it to the new question.
Shot One example in a few-shot prompt: a sample question paired with the ideal reply.
Persona The role given to the model in its standing instructions, such as “You are Fernhill’s help desk assistant”, which sets voice and scope.
System message The message at the start of the message list that carries the persona and the standing rules, ahead of the user’s words.
Main prompt The helper’s standing instructions, kept in model_prompts/system.md and loaded when the program starts.
USE_EXAMPLES The setting in helpdesk_agent.py: True adds model_prompts/examples.md to the prompt (few-shot), False leaves it out (zero-shot).

Explanations: how do you design a prompt step by step?

Where are we? What does this session add to the HelpDesk Copilot?

In session 5 you built helpdesk_agent.py: the model asks for a policy or a ticket, your code fetches it, and the reply comes back as JSON. Its prompt sat inside the script as one long string. This session improves what goes into the model: the instructions. The session 5 helper stays as it is, with two changes: the prompt is read from files in model_prompts/, and a setting called USE_EXAMPLES turns the examples on or off. Already built: the first call (session 1), the token counter (2), the temperature and limits (3), the chat (4) and the tool-calling helper with its fixed reply format (5).

Box What it does for the employee
model_prompts/system.md The standing instructions: role, tools, reply format, and when to ask a person
model_prompts/examples.md Two finished replies the model can copy (the few-shot part)
USE_EXAMPLES One setting that adds the examples to the prompt or leaves them out

Read it as write, load, ask: the prompt files feed the helper, and the helper feeds the call. The folder model_prompts/ holds what the model reads; the folder prompts/ holds what you paste into a coding assistant.

What is a prompt, and what parts does a good prompt have?

Failure first. Two teammates ask the same model about leave. One types “Tell me about leave.” and gets, in an illustrative reply: “Leave is time away from work. There are many kinds, such as annual, sick and parental leave, and the rules differ between companies. Would you like more detail on any of these?” The other types a longer prompt and gets: “Up to 5 unused annual-leave days carry over to the next year and must be used by 31 March (Leave Policy 4.2).” The model is the same; the prompt differs.

Why does the short prompt give an essay? Picture telling a taxi driver “take me somewhere nice”: you get a drive, but not the one you pictured. Or asking a tailor to “make me a suit”: no fabric, no size, no date, so the tailor decides those three things. The request leaves out what you want, the listener fills the gaps with a reasonable guess, and a reasonable guess is not your guess. OpenAI’s guide notes that the content a model generates is non-deterministic, so getting the output you want is a mix of art and science; the techniques here are how you tilt that in your favour.

A prompt is the input you send the model to steer its reply. A good one has four parts, much like a briefing for a new colleague or a recipe card:

  • an instruction: the task (“answer the employee’s leave question”);
  • context: the information to use (the policy or ticket the model asks for);
  • examples: inputs with the output you want;
  • the format you want back (in the helper, JSON with answer, section and needs_human).

OpenAI’s guide describes the same recipe: an identity for the assistant, instructions, examples and context, and it suggests placing the context near the end of the prompt because it changes from request to request. Taking the weak prompt apart shows what is missing:

Part What the weak prompt has What the helper’s prompt has
Instruction “Tell me about leave.” Answer only from what the tools return
Context Nothing The policy or ticket the model asks for
Examples Nothing Two finished replies in examples.md
Format Anything goes JSON with answer, section, needs_human

Missing parts are not neutral: the model fills each gap with a guess.

What are zero-shot, one-shot and few-shot prompting, with examples?

Imagine leaving a sticky note for a colleague: “Reply to the leave question, from the policy, in two sentences.” You gave a task and no sample of past work. That is zero-shot prompting: an instruction and no examples, so the result rests on how clearly the instruction is written. A job ticket to a contractor works the same way: the task, the limits and the finish. OpenAI’s guide says GPT models benefit from more explicit instructions around how to accomplish tasks, which is the case for starting here: a clear instruction is the cheapest thing to try. The table shows a zero-shot prompt improving in two steps:

Version What the prompt says What it changes
Weak “Tell me about leave.” Anything goes, any length
Clear task “Answer the employee’s leave question in two sentences.” Scope and length
Plus rules “Answer from the policy text given. Name the section. If it is not there, say so.” What counts as a good answer

One-shot prompting is the step between: the same instruction plus a single example, a sample question with the ideal reply. It shows the layout once, and it is the cheapest way to test whether an example helps. Its risk is that one example is the strongest signal the model has, so replies may copy it even where a question needs a different shape.

Sometimes rules are not enough, because a rule can describe a layout but not show it. Think of a new colleague handed a template: “reply like these three” beats “reply well”. Or a cook shown a plated dish: one picture shows the portion, the layout and the garnish. Few-shot prompting adds a handful of example inputs, each with the output you want. OpenAI’s guide says few-shot learning lets you steer a model toward a new task by including a handful of input and output examples in the prompt, rather than fine-tuning the model, and that the model picks up the pattern from them. Each example is one shot.

In the helper, the shots live in one file, model_prompts/examples.md:

## Examples
Here are two finished replies. Match their style and their format.

Question: Who approves my annual leave request?
Reply: {"answer": "Your manager approves or declines it.", "section": "Leave Policy 4.3", "needs_human": false}

Question: Please cancel my approved leave for next week.
Reply: {"answer": "Cancelling changes your record, so your manager must approve it first. I have asked a person to help.", "section": "Leave Policy 4.5", "needs_human": true}

Each example is a question and a finished reply in the exact format the program reads. The second one shows a request that changes someone’s record, with needs_human true: a rule can say “ask a person”, but an example shows what that reply looks like. The program adds the file to the system message when one setting is True:

USE_EXAMPLES = True

system_message = (PROMPTS / "system.md").read_text()
if USE_EXAMPLES:
    system_message += "\n" + (PROMPTS / "examples.md").read_text()
print("Examples in the prompt:", USE_EXAMPLES)

With USE_EXAMPLES = True the prompt is few-shot; with False it is zero-shot. The first line the helper prints, Examples in the prompt:, tells you which version you are running. Examples need care, because the model copies the pattern, including a flaw in your example. Keep examples short and different from each other, and test with a question that is not among them.

What is a persona and a system message, and how do I improve a weak prompt?

Think of a person in a uniform with a name badge: they know their role and speak to match it. Or a job description pinned on the wall, telling the assistant what to do and what it must not do before any customer arrives. A persona is the role you give the model in its standing instructions, such as “You are the help desk helper for Fernhill Systems”, the first line of model_prompts/system.md. It sets voice and scope. The rules say what a good answer is. The system message is the message at the start of the message list that carries both:

 messages = [
   system:  system.md  (+ examples.md when USE_EXAMPLES is True)
   user:    the employee's question
 ]

Why does the position matter? OpenAI’s guide says developer messages are instructions from the application developer, prioritized ahead of user messages, and user messages are instructions from an end user, prioritized behind them. Its Chat Completions reference describes the system message as developer-provided instructions the model should follow regardless of messages sent by the user, and says newer OpenAI models use a developer message for the same purpose. This course writes the system message because it is the form compatible providers document for Chat Completions; check your provider if you use another. Each request is independent and stateless, so the standing instructions must be sent with each request; the helper sends the system message again on every trip round the tool loop. A persona does not make answers true: it sets who is speaking, and the answer still needs the policy text.

Here is one weak prompt improved in three steps; change one thing at a time so you can tell which change helped:

Prompt version What the prompt says What it changes
Weak “Tell me about leave.” Anything goes, any length
+ Persona “You are Fernhill’s help desk assistant. Answer employees plainly.” Voice and scope
+ Rules “Answer from the policy text given. Name the section. If it is not there, say so.” What counts as a good answer
+ Examples Two sample questions with ideal replies Layout and tone

Basic assignment: run the helper with the examples on and off.

python helpdesk_agent.py

With USE_EXAMPLES = True at the top of helpdesk_agent.py, a real run on 2026-11-11 printed Examples in the prompt: True first, then the same two tool steps as in session 5 and an answer from Leave Policy 4.2:

Examples in the prompt: True
Question: I have 7 unused leave days and ticket T-1047 is open. How many days can I keep?
model asked: read_policy('leave')
model asked: get_ticket('T-1047')
answer: You can carry over up to 5 unused annual-leave days into the next leave year.
section: Leave Policy 4.2
needs_human: False

Now run the second example’s question, python helpdesk_agent.py "Please cancel my approved leave for next week.", and look at needs_human. Change USE_EXAMPLES = True to USE_EXAMPLES = False, run the same line again, and write one line on what changed. In our run with examples on, the reply was the second example word for word:

answer: Cancelling changes your record, so your manager must approve it first. I have asked a person to help.
section: Leave Policy 4.5
needs_human: True

With examples off, the same question came back like this:

answer: I cannot cancel your leave for next week. I can only answer questions about leave, expenses, laptop security, and support tickets.
section: none
needs_human: True

Both ask a person, but only the first gives a reason and a section, because only that prompt shows what a record change looks like. It also shows that a model may copy an example outright. Model replies vary, so run each version a few times.

Project step: the prompt in a file. Start from your session 5 helpdesk_agent.py, with the model_prompts/ folder next to it. Paste the prompt in prompts/1-write-helpdesk-agent.md into Claude Code or Codex, and run the result. Then write a third example in examples.md for a question about expenses, and see whether the style follows it. Stop when the cancel question runs with USE_EXAMPLES set to True and to False.

What are three situations where a prompt fails, and what does each mean for the design?

Before the design table, three situations you will meet:

  1. An employee asks “Tell me about leave.” and gets a page about leave types they did not ask about. The prompt gave no scope or length, so the model chose its own.
  2. The helper treats a request to cancel approved leave as a plain question. The prompt had no rule for a request that changes a record, so the model filled the gap.
  3. Replies copy the layout of one example, even for a question that needs a different shape. The single example was the strongest signal, so the model repeated its pattern.

What these mean for the Copilot’s design:

What you learned The design decision Where it shows
A prompt has four parts Check each part is present before you test model_prompts/system.md
A clear instruction is the cheapest fix Start zero-shot, then add rules Rules in system.md
Examples show what rules cannot Add two finished replies, one an “ask a person” case model_prompts/examples.md
The persona sets voice and scope Give the helper a role and limits First lines of system.md
Examples change replies Keep one setting to switch them, and compare USE_EXAMPLES

Flashcards: prompt framework, few-shot and persona questions with answers

Say the answer aloud before revealing it. Speaking is a different skill from reading, so practise both.

1. What is a prompt, and what four parts does a good one have? A prompt is the input you send the model to steer its reply. A good one has an instruction (the task), context (the information to use), examples (inputs with the output you want) and the format you want back.
2. Why does "Tell me about leave." give a rambling answer? It leaves out what you want: which policy, for whom, how long, in what format. The model fills each gap with a reasonable guess, and a reasonable guess is not your guess.
3. What is zero-shot prompting, and when do you start with it? It gives the model an instruction and no examples, so the result rests on how clear the instruction is. Start here because a clear instruction is the cheapest thing to try.
4. What is one-shot prompting, and what is its risk? It is an instruction plus a single example, a sample question with the ideal reply. It shows the layout once, but one example is the strongest signal the model has, so replies may copy its shape even for a question that needs a different one.
5. What is few-shot prompting? It adds a handful of example inputs, each with the output you want, so the model picks up the pattern and applies it to the new question. OpenAI's guide says this steers a model toward a new task without fine-tuning it.
6. How is one example (a shot) written in the helper? As a question and a finished reply in the exact JSON format the program reads, kept in `model_prompts/examples.md`. When `USE_EXAMPLES` is `True`, the helper adds that file to the system message.
7. Why should one of your examples be an "ask a person" reply? Rules can say when to set `needs_human` to true, but an example shows it. The second example in `examples.md` is a request that changes someone's record, with `needs_human` true.
8. What is a persona, and what does it change? It is the role you give the model in its standing instructions, such as "You are Fernhill's help desk assistant." It sets voice and scope, but it does not make answers true, since the policy text still has to be supplied.
9. What is the system message, and where does it sit? It is the message at the start of the list that carries the persona and the standing rules. OpenAI's guide says instructions from the application developer are prioritized ahead of the user's, which is why the rules go there.
10. Why change one thing at a time when improving a prompt? If you change the persona, the rules and the examples together, you cannot tell which one helped. One change and the same three questions after each step show the effect of each.
11. What does `USE_EXAMPLES` do? It is a setting at the top of `helpdesk_agent.py`. `True` adds `model_prompts/examples.md` to the prompt (few-shot) and `False` leaves it out (zero-shot), and the helper prints `Examples in the prompt:` with the setting so you know which run you are looking at.

Model answer: how would you improve a rambling prompt, and how would you know it worked?

The core question this session answers: “A teammate asks: our Copilot gives rambling answers when someone types a short question. How would you improve the prompt, and how would you know it worked?”

Five beats a teammate listens for, in this order: name the parts · start zero-shot · add a persona in the system message · add examples if rules are not enough · compare fairly. Skip any of these five and the answer is incomplete.

  1. Name the parts: a prompt has an instruction, context, examples and a format, and the weak one has just a vague instruction.
  2. Start zero-shot: write a clear task with rules, such as answer from the policy and name the section.
  3. Add a persona in the system message: who the assistant is and what it must not do.
  4. Add examples if rules are not enough: two sample question and reply pairs, including a case for a person to handle.
  5. Compare fairly: change one thing at a time and run the same questions after each change.

The full answer, said aloud:

(Name the parts) “A prompt has four parts: an instruction, context, examples and a format. The prompt that rambles has just a vague instruction, so the model fills the gaps with guesses.

(Start zero-shot) I would first write a clear task with rules: answer from the policy text supplied, name the section, and say so when it is not there. That is the cheapest change.

(Add a persona) Then I would put a persona and the standing rules in the system message, so the model knows who it is and what it must not do.

(Add examples) If rules are not enough, I would add two examples as question and reply pairs, one of them a case where a person should take over.

(Compare fairly) And I would change one thing at a time and run the same questions after each change, so I know which change helped.“

Missing a beat is a failure state. The follow-up question lands where you went quiet: finish without the last beat and the next question is how you know it worked. Practise until the five come out without prompting, then stop talking and let the questions come.

Why this matters: where is prompt design used at work?

In a conversation with a teammate or manager: people who build with models are asked why an answer was vague and what you changed. The five beats give you a structure with no obvious gap, and the habit of changing one thing at a time gives you evidence instead of an opinion.

On the job: a feature built on a model has a prompt behind it, and its quality depends on the parts you write down. Standing instructions kept in a file, loaded by the program, can be reviewed and changed like code.

In the rest of this course: session 7 adds step-by-step reasoning and chaining; session 8 tests the main prompt against your test set and keeps it in a prompt library; the LangChain sessions turn it into a prompt template; the retrieval sessions supply the policy text as context; and the safety sessions return to what a persona cannot protect against.

After this unit: what is the assignment and what comes next?

Assignment. Run the helper with USE_EXAMPLES on and off, then add a third example about expenses to model_prompts/examples.md and run it again. The brief for the project work, keeping the prompt in a file, is the project file. Keep your helper and its model_prompts/ folder: the next session builds on them.

What’s next. Session 7 is prompt engineering 2: asking for step-by-step reasoning, and chaining one prompt’s output into the next.

Want help building this with someone?

Tell us what you are working on and we will write back about a mentor-led cohort, live sessions or 1:1 training. It is only an enquiry: you choose whether to go further.

Ask about mentor-led training

TechEazy Consulting training material — not affiliated with or endorsed by OpenAI, Anthropic, LangChain or any other company named in this course.