"The model is only as good as the question you ask. Prompt engineering is the skill of asking well — and it's mostly common sense."
Level: Beginner · Time: ~3–4 days · Prerequisites: Modules 4–5
Learning Objectives
By the end of this module, you will be able to:
- Explain what prompt engineering is and why it matters
- Use zero-shot, few-shot, chain-of-thought, and role-based prompting
- Build reusable prompts with Spring AI's
PromptTemplate - Pick the right technique for a task
1. What Is Prompt Engineering?
Prompt engineering is designing your input so the model reliably gives you what you want. It's the difference between a vague request and a precise one.

Explain like I'm new: It's like giving instructions to a new coworker. "Fix the bug" is vague. "Fix the null-check on line 45 of UserService" is clear. The model, like the coworker, does far better with specifics and structure.
Small wording changes can flip an answer from useless to exactly right, and none of it requires touching the model or writing extra code — you're simply communicating clearly. Here are the five foundational techniques.

2. Zero-Shot Prompting
Give a direct instruction with no examples — the model relies on its training.
[object Object], ,[object Object], ,[object Object], chatClient
.prompt(,[object Object],)
.call().content(); ,[object Object],Use it for: simple classifications, direct questions, translations — anything obvious.
Zero-shot leans entirely on what the model already learned during training, so it's fast and cheap. The catch: if your task has an unusual format or domain jargon, the model may guess the shape of the answer inconsistently — that's your cue to switch to few-shot.
3. Few-Shot Prompting
Show a few examples of the input→output pattern you want. The model copies the pattern.
[object Object], ,[object Object], ,[object Object], ,[object Object],;Use it for: custom formats, domain-specific tasks, or whenever zero-shot is inconsistent.
Concept: Few-shot works because models are pattern-matchers. Two or three good examples "teach" the format on the spot — no retraining needed.
4. Chain of Thought
Ask the model to reason step by step instead of blurting an answer. This boosts accuracy on math and logic.
[object Object], ,[object Object], ,[object Object], ,[object Object],;
,[object Object],Use it for: math, logic puzzles, debugging — any multi-step problem where you want to trust the answer.
Try this: Ask a tricky word problem with and without "let's think step by step." The step-by-step version is usually more accurate — a one-line change with a big payoff.
5. Role-Based Prompting
Give the model a persona to shape tone and depth. A "senior security auditor" answers differently than a "friendly tutor."
[object Object], ,[object Object], ,[object Object], ,[object Object],;Use it for: code reviews, tutoring, or tailoring answers to an expertise level.
Real-world use case: A learning app sets the role to "a patient tutor for a 10-year-old" for kids and "a concise senior engineer" for professionals — same underlying model and question, but the persona reshapes vocabulary, length, and tone to fit the audience.
6. Prompt Templates
When the structure stays the same but the values change, use Spring AI's PromptTemplate with {placeholder} variables — define once, reuse forever.
[object Object], ,[object Object], ,[object Object], ,[object Object], ,[object Object],(
,[object Object],);
,[object Object], ,[object Object], ,[object Object], template.create(Map.of(
,[object Object],, ,[object Object],, ,[object Object],, ,[object Object],));
,[object Object], ,[object Object], ,[object Object], chatClient.prompt(prompt).call().content();Use it for: repeated queries, batch processing, and reusable AI workflows.
Common mistake: Gluing user input into prompts with plain string concatenation. Templates keep prompts readable and make it clear where user-supplied values go — safer and cleaner.
✅ Checkpoint
- What's the difference between zero-shot and few-shot prompting?
- When does chain-of-thought help most?
- What problem does
PromptTemplatesolve?
Answers: 1) Zero-shot gives no examples; few-shot includes a few input→output examples to teach the pattern. 2) On multi-step reasoning tasks like math and logic. 3) Reusing the same prompt structure with different variable values.
Key Takeaway: Prompt engineering is asking well. Reach for zero-shot for obvious tasks, few-shot to teach a format by example, chain-of-thought for step-by-step reasoning, and role-based prompting to set tone and expertise. When only the values change, Spring AI's PromptTemplate turns a prompt into a reusable, variable-driven building block.
Further Learning
Part of "Spring AI for Beginners." Adapted from Microsoft's open Spring AI curriculum (MIT License).