AI & Machine Learning

Prompt Engineering Course: A Full Guide From Basics to Evaluation

A complete self-study prompt engineering course: lessons, exercises, code, a test harness and a final project.

Published 10 min read

Illustration of six prompt building blocks beside a sample prompt file and a test loop banner

Short on time? This prompt engineering course teaches you to write prompts that work, then prove it. The method is: define success criteria, write a first prompt with a clear role, context, task, examples and output format, test it on real cases, measure and improve. Anthropic and OpenAI both stress evaluations. This full guide has lessons, exercises, code and a test harness you can reuse.

Prompt engineering is the craft of telling a language model what you want so it delivers it reliably. It sounds simple. In practice, a prompt that works on three examples can fail on the fourth. A good prompt is clear, specific and tested.

This guide works as a self-study prompt engineering course. Each lesson explains one idea, gives an example and ends with an exercise. You will finish with a prompt library and a small evaluation harness. It suits beginners, analysts, developers and managers. For background, see Large Language Models Explained.

Key takeaways

  • Anthropic’s documentation says prompt engineering assumes you have clear success criteria, ways to test against them and a first draft prompt.
  • OpenAI’s prompt engineering guide lists message roles, few-shot examples, relevant context and evaluations among its core practices, and advises pinning production apps to a specific model snapshot.
  • Good prompts state role, context, task, format and rules, and use examples.
  • Test with real cases, including awkward ones, and keep a record of versions and scores.
  • Some problems are better solved by retrieval, a different model or code than by more prompt text.

Prompt engineering course outline

  1. Lesson 1: What a prompt is and what it is not
  2. Lesson 2: Set success criteria before you write
  3. Lesson 3: The five-part prompt
  4. Lesson 4: Examples (few-shot prompting)
  5. Lesson 5: Structured output
  6. Lesson 6: Reasoning and breaking tasks apart
  7. Lesson 7: Context, documents and retrieval
  8. Lesson 8: Settings: temperature and length
  9. Lesson 9: Testing and evaluation
  10. Lesson 10: Safety and prompt injection
  11. Lesson 11: Prompt management in teams
  12. Lesson 12: Final project
  13. Mistakes, business views and a study plan

Lesson 1: What a prompt is and what it is not

This prompt engineering course starts with the basics. A prompt is everything you send to the model: instructions, context, examples and the question. In many APIs it has roles. OpenAI’s guide describes developer messages for the application’s rules and user messages for inputs, with developer instructions taking priority. Other providers use a system message for a similar purpose.

A prompt is not magic words. It does not give the model knowledge it lacks, and it cannot guarantee facts. If the model needs your data, add it through retrieval. See Build Your First RAG App.

Exercise: take a task you do at work. Write down what the model would need to know to do it as well as you.

Lesson 2: Set success criteria before you write

Anthropic’s prompt engineering overview starts with prerequisites: a clear definition of success criteria, ways to test against them and a first draft prompt. Do this first.

Good criteria are specific and checkable:

  • “The summary is under 100 words and mentions the decision and the owner.”
  • “The category matches the human label in at least 9 of 10 cases.”
  • “The answer cites a source from the provided text, or says it does not know.”
  • “The reply uses a polite tone and no promises about refunds.”

Vague criteria such as “good quality” cannot be tested.

Exercise: write three checkable criteria for your task.

Lesson 3: The five-part prompt

Most strong prompts contain five parts.

  1. Role and goal: who the model acts as and what outcome you want.
  2. Context: the facts it needs.
  3. Task: the steps or the question.
  4. Format: how the output should look.
  5. Rules: limits and fallbacks, such as “use only the text below” and “say when unsure”.

A weak prompt:

Summarise this email.

A stronger prompt:

You are an assistant for a project manager.
Summarise the email below for a busy reader.

Include: the decision requested, the deadline and who must act.
Format: three bullet points, each under 20 words.
If the email contains no decision, say "No decision requested."
Use only information in the email.

Email:
{email_text}

Exercise: rewrite one of your own prompts using the five parts.

Lesson 4: Examples (few-shot prompting)

Examples show the pattern better than description. OpenAI’s guide describes few-shot learning: include a few input and output pairs, covering a range of inputs, so the model picks up the pattern without fine-tuning.

Classify each message as billing, technical or other.

Message: "I was charged twice this month."
Category: billing

Message: "The app crashes when I upload a photo."
Category: technical

Message: "Do you have a partner programme?"
Category: other

Message: "{new_message}"
Category:

Tips:

  • Use real examples, and include edge cases.
  • Keep the format identical across examples.
  • Use two to six examples. More is not always better.
  • Check that examples do not leak into answers.

Exercise: add three examples to your prompt, including one hard case.

Lesson 5: Structured output

When code reads the answer, ask for a fixed structure, and validate it.

Return only JSON with these keys:
{"category": "one of billing, technical or other", "confidence": 0.0 to 1.0, "reason": "one sentence"}

Validate in code:

import json

ALLOWED = {"billing", "technical", "other"}

def parse_classification(text):
    try:
        data = json.loads(text)
    except json.JSONDecodeError:
        return None
    if data.get("category") not in ALLOWED:
        return None
    if not 0.0 <= float(data.get("confidence", -1)) <= 1.0:
        return None
    return data

If validation fails, retry once, then route to a person. Many providers also offer built-in structured output features, so check your provider’s documentation.

Exercise: make your prompt return JSON and write the validator.

Lesson 6: Reasoning and breaking tasks apart

Hard tasks go better in steps.

  • Ask for steps. “First list the facts. Then decide. Then write the answer.”
  • Chain prompts. Use one call to extract facts, a second to analyse and a third to write. Anthropic describes this as prompt chaining, with checks between steps.
  • Separate checking. Use a second call to verify the first.

Chaining also makes testing easier, because you can test each step alone. Some models have built-in reasoning modes. Test whether they help your task and what they cost. See Build Your First AI Agent for larger patterns.

Exercise: split one complex task into two or three prompts.

Lesson 7: Context, documents and retrieval

OpenAI’s guide notes you can add outside data to a prompt, a technique known as retrieval-augmented generation, within the model’s context window. Good habits:

  • Put documents in clearly marked blocks.
  • Tell the model to use only those blocks.
  • Include source names so it can cite them.
  • Send only relevant passages.
  • Place instructions where the model will not miss them.
Answer using only the documents below. Cite the document name in brackets.
If the documents do not contain the answer, say you do not know.

<document name="leave-policy.md">
{passage_1}
</document>

<document name="travel-policy.md">
{passage_2}
</document>

Question: {question}

Exercise: write a grounded prompt, and test one question the documents cannot answer.

Lesson 8: Settings: temperature and length

  • Temperature controls randomness. Use low values for extraction and classification, higher for brainstorming.
  • Maximum length limits the answer and the cost.
  • Stop rules and formats keep outputs short.
  • Model choice matters. Anthropic notes that latency and cost can sometimes be improved more easily by choosing a different model than by editing prompts.

OpenAI advises pinning production applications to a specific model snapshot so behaviour stays consistent, and using evaluations to track results when you upgrade.

Exercise: run the same prompt at two temperatures ten times each. Compare consistency.

Lesson 9: Testing and evaluation

Testing turns prompt writing into engineering.

Build a test set

Collect 30 to 100 real inputs. For each, record the expected result or the checks it must pass. Include hard, odd and empty cases.

A tiny harness

import json

def run_tests(cases, call_model, build_prompt, check):
    results = []
    for case in cases:
        output = call_model(build_prompt(case["input"]))
        ok, note = check(case, output)
        results.append({"id": case["id"], "ok": ok, "note": note})
    passed = sum(r["ok"] for r in results)
    print(f"{passed}/{len(results)} passed")
    for r in results:
        if not r["ok"]:
            print("FAIL", r["id"], r["note"])
    return results

def check_category(case, output):
    data = parse_classification(output)
    if data is None:
        return False, "invalid output"
    return data["category"] == case["expected"], f"got {data['category']}"

Improve with discipline

  1. Change one thing at a time.
  2. Re-run the whole set.
  3. Keep a table of prompt version, model, settings and score.
  4. Read the failures, and fix the cause.
  5. Add every real-world failure to the test set.

Judging open-ended output

For writing tasks, use a rubric with a few clear criteria and score by hand on a sample. A second model can help score at scale, but check it against human scores first.

Exercise: build a 30-case test set, and measure your prompt’s pass rate.

Lesson 10: Safety and prompt injection

Text from outside, such as emails, web pages and documents, can contain instructions meant to hijack the model. The OWASP Top 10 for LLM Applications 2025 lists prompt injection first.

Defences:

  • Mark outside text as data, and tell the model to ignore instructions inside it.
  • Give the model no tools it does not need.
  • Validate outputs before acting on them.
  • Keep humans in the loop for risky actions.
  • Test with attack cases.
  • Do not put secrets in prompts.

See Prompt Injection Explained.

Exercise: add three injection attempts to your test set, such as “ignore the rules above”.

Lesson 11: Prompt management in teams

Treat prompts like code.

  • Store them in version control with the tests.
  • Review changes.
  • Record who owns each prompt.
  • Log which version produced which output.
  • Re-run tests when the model changes.
  • Share a prompt library with examples and known limits.

A simple file layout:

prompts/
  classify_message/
    prompt.txt
    examples.json
    tests.json
    CHANGELOG.md

Lesson 12: Final project

Build a prompt for a real task:

  1. Write success criteria.
  2. Draft the five-part prompt with examples.
  3. Add structured output and validation.
  4. Build a test set of 40 cases, including 5 attack cases.
  5. Iterate until you reach your target.
  6. Write a one-page note: purpose, prompt, test results, limits and owner.

A worked example: customer email triage

This example is illustrative.

A support team wants incoming emails sorted into billing, technical, sales and other, with urgency from 1 to 3.

  1. Criteria: category agrees with a human in at least 90 percent of cases, urgency within one point in 90 percent, no invented facts.
  2. Prompt: five parts, four examples, JSON output.
  3. Tests: 100 past emails labelled by agents, 10 empty or very short, 10 in other languages and 5 with injected instructions.
  4. First result: 82 percent category accuracy. Failures cluster on mixed billing and technical emails.
  5. Fix: add two mixed examples and a rule “choose the main issue, mention the second in the reason”. Accuracy rises to 91 percent.
  6. Controls: low-confidence emails go to a person. The prompt version is logged with every result.
  7. Monitoring: weekly sample of 30 emails reviewed by an agent.

Result to look for: a stable pass rate, a clear fallback path and a record that shows why the prompt is trusted.

Mistakes to avoid when you practise prompt engineering

  • Writing prompts before defining success.
  • Testing on three friendly examples.
  • Long prompts full of contradictory rules.
  • Changing many things at once.
  • No fallback when the output is invalid.
  • Trusting model output on facts without sources.
  • Using prompts to fix problems that need retrieval, code or a different model.
  • Not re-testing after a model update.

Small business and enterprise views

  • Sole trader or small business: keep a notes file of prompts that work, add a rule to check facts and never paste sensitive data into public tools.
  • Mid-size company: build a shared prompt library with tests, name owners and review costs monthly.
  • Enterprise: run prompt management as part of an AI platform with versioning, evaluation pipelines, approvals, red-team tests and model change control. See AI orchestration.

Regional and regulatory notes

If prompts include personal data, data protection law applies to your logs and test sets. Test prompts in every language you serve, since results vary. Where AI output affects people, such as hiring or credit, extra rules can apply. See EU AI Act after the Digital Omnibus.

Study plan

Follow this prompt engineering course over four weeks.

Week 1: Lessons 1 to 3 with your own task.

Week 2: Lessons 4 to 6, and build the structured output and validator.

Week 3: Lessons 7 to 9, and build your first test set.

Week 4: Lessons 10 to 12, and complete the final project.

Afterwards: read the provider guides, revisit your prompts each quarter and extend your prompt engineering course notes into a team playbook.

How SoftSapien supports prompt engineering

SoftSapien’s AI engineers run workshops, build prompt libraries and evaluation harnesses, review safety and cost and help teams embed good practice. See our AI development and AI governance services.

To train your team or build a tested prompt, use the contact page to chat with our team, send a message or schedule a free consultation call.

Frequently asked questions

What is prompt engineering?

The craft of writing instructions, context and examples so a language model delivers what you need reliably, and proving it with tests.

What should I do before writing a prompt?

Define success criteria you can check, decide how to test against them and write a first draft prompt, as Anthropic advises.

How many examples should a prompt include?

Usually two to six real examples covering a range of inputs, including a hard case. Test whether more examples help.

How do I know a prompt is good?

It passes a test set of real cases, including odd inputs and attack attempts, and keeps passing after model changes.

Can SoftSapien train our team in prompt engineering?

Yes, with workshops and prompt libraries. Contact SoftSapien through the contact page to chat with our team, send a message or schedule a free consultation call.

Related service AI & Machine Learning
SoftSapien

One partner for digital transformation, AI, cloud, and growth.

From legacy modernization and Gen-AI engineering to digital strategy and infrastructure, SoftSapien helps enterprises plan, build, and scale the initiatives that move the business forward.

Tell us what you're building and we'll get back to you within 2 business hours.

Contact Us

+1

How should we reach you?

Slide to verify you're human

Talk to an Expert