FreeFoundations · 30 min · Beginner
✍️

Prompt Engineering

System, user and assistant roles — craft effective prompts

💡

What Is Prompt Engineering?

Simple overview · Real-world examples included

This topic is about learning to "talk" to AI effectively — a skill called prompt engineering. AI models are powerful, but they need clear instructions. The same question worded two different ways can give completely different results. We will learn how to structure your instructions so the AI always does exactly what you want. Real example we will build: an email classifier that automatically sorts support emails into BUG / FEATURE / BILLING / GENERAL — with no human involved.

🎯 What You'll Learn

System vs user vs assistant roles
Few-shot prompting
Chain-of-thought
PromptTemplate in Spring AI

🌍 Real-World Use Case

An IT helpdesk that auto-categorizes incoming tickets as Bug/Feature/Billing/General

📊 How It Works — Interactive Flowchart

Hover nodes for quick tip · Click to open detail · Press "Run Data Flow" to animate

Click any box to learn what it does
🧑‍💻
Your Prompt
User message
Step 1
⚙️
System Prompt
AI persona
Step 2
🔢
Template
Merge inputs
Step 3
🌐
API Call
Both prompts
Step 4
🤖
AI Model
Follows rules
Step 5
Output
Constrained
Step 6

🛠️ Step-by-Step Implementation

Click any step to expand · Check the circle to mark complete · Progress saves in your browser

Implementation ProgressClick ○ to mark a step complete
0 / 6
01
Understand message roles
💡 WHY AM I DOING THIS?

Roles tell the LLM who is speaking and what authority they have.

▶ WHAT HAPPENS IN THIS STEP

System = AI persona, User = human input, Assistant = AI response

📄 FILES TO CREATE / MODIFY
+ChatController.java
📁 FOLDER STRUCTURE
No new files needed
💻 CODE EXAMPLE
chatClient.prompt()
    .system("You are an expert email classifier.")
    .user(emailContent)
    .call()
    .content();
⚠ COMMON MISTAKES
Mixing business rules into user message instead of system
▶ HOW TO TEST
Send same email with different system prompts — watch output change
✅ EXPECTED RESULT
System prompt change dramatically affects classification accuracy
02
Write constrained output prompts
Without constraints LLMs write essays
03
Add few-shot examples
Examples in the prompt dramatically improve accuracy — the model learns your specific classification logic
04
Use Spring AI PromptTemplate
PromptTemplate lets you inject variables into prompts safely — no string concatenation bugs
05
Build classification endpoint
Wrap the classifier in a REST endpoint so any system can call it
06
Test edge cases
Real emails are messy — mixed languages, typos, ambiguous content

✍️ How to Write the Prompt for This Topic

System: "Classify the email into exactly one: BUG | FEATURE | BILLING | GENERAL. Reply with only the category word." — Constrain the output strictly.

🎯

Job Interview Prep

8 curated questions · 0 / 8 mastered
Click answers, then rate yourself to track progress
LEVEL:

💡 Don't memorise answers word-for-word. Understand the concept, then explain it in your own words using a real example from this topic's project — that's what impresses interviewers.

⚡ Live AI Demo

LIVE AI DEMO — CLAUDE HAIKUSign up for 3 free demos/day
0/500

📦 Clone & Run the Sample Project

📦
github.com / ai-dev-academy / ai-dev-academy-projects

02-prompt-engineering

Smart Email Classifier — classifies support tickets automatically

Spring Boot 3.xSpring AIPromptTemplateJava 17
QUICK START — RUN IN 5 STEPS
1
Clone the full repo
git clone https://github.com/ai-dev-academy/ai-dev-academy-projects.git
2
Enter the topic folder
cd ai-dev-academy-projects/02-prompt-engineering
3
Set up your API key
cp .env.example .env
# Then open .env and add your API key
4
Run the project
mvn spring-boot:run
5
Test the endpoint
curl -X POST http://localhost:8080/ai/chat \
  -H "Content-Type: application/json" \
  -d '"Hello, what is Prompt Engineering?"'
OPEN IN YOUR IDE
← DashboardAll Topics →