Prompts are software.
A great prompt is not clever wording. It is a small, precise program written in English, aimed at a machine that already understands language. The difference between an amateur and a professional is not vocabulary — it is structure. This chapter teaches you the structures the pros use.
Learning Objectives
- Understand the three layers of every prompt: system, developer, user.
- Choose between zero-shot, few-shot, and chain-of-thought techniques.
- Use XML tags to enforce structure and reduce ambiguity.
- Write reliable prompts for planning, code generation, refactoring and debugging.
- Diagnose why a prompt failed — and rewrite it in under a minute.
1. The Three Prompt Layers
Every professional AI interaction is a stack of three messages:
┌─ SYSTEM "Who is the model? What are its rules?"
├─ DEVELOPER "What tools and constraints does this app impose?"
└─ USER "What do I want right now?"2. System Prompt
The system prompt sets identity, tone, and non-negotiable rules. It is written once, at the top of the conversation, and stays in effect for every message that follows.
You are a senior TypeScript engineer.
- Prefer functional style and immutability.
- Never invent library APIs — if unsure, ask.
- Return runnable code, not pseudocode.
- Explain in short sentences.3. Developer Prompt
The developer prompt is the app author speaking to the model. It usually holds the schema of tools, the shape of expected outputs, and safety guardrails.
You have access to two tools: search_web(query), read_file(path).
Output must be valid JSON matching { "answer": string, "sources": string[] }.
Refuse questions unrelated to travel planning.4. User Prompt
The message the end-user actually types. Keep the system and developer layers strong, and the user layer can stay short and human.
5. Zero-Shot Prompting
Ask the model to do a task with no examples. It works for common tasks the model has seen a million times.
Classify this review as positive, negative, or neutral:
"Shipping was slow but the product is excellent."6. Few-Shot Prompting
Show 2–5 examples of the exact input/output format you want. Few-shot fixes almost every "the model keeps returning the wrong shape" problem.
Extract the city and country as JSON.
Input: "I flew to Kyoto in Japan last spring."
Output: {"city":"Kyoto","country":"Japan"}
Input: "Berlin was cold this winter."
Output: {"city":"Berlin","country":"Germany"}
Input: "We spent a week in Lisbon."
Output:7. Chain of Thought
Ask the model to think step by step before answering. Accuracy on reasoning tasks improves dramatically.
Question: A shirt costs $40 and is on sale for 25% off. Sales tax is 8%.
What is the final price? Think step by step, then give the final number on the last line.8. XML Prompting
Claude was trained to respect XML-style tags. Wrapping sections in tags dramatically reduces confusion about what is context, what is instruction, and what is data.
<role>Senior editor for a science magazine.</role>
<article>
{{ARTICLE_TEXT}}
</article>
<task>
1. Suggest a stronger headline.
2. Flag three sentences that could be tightened.
3. Return your answer inside <suggestions></suggestions>.
</task>9. Constraints
State what the model must not do. Constraints are how you keep outputs safe, on-topic, and machine-readable.
- Answer in at most 3 sentences.
- Never mention competitors by name.
- If the question is off-topic, reply "OUT_OF_SCOPE".10. Role Prompting
A clear role sets the model's vocabulary and priorities. "Act as a security auditor" produces different output than "act as a friendly tutor," even for the same question.
11. Planning Prompts
Before letting Claude Code touch a large task, ask for a plan first, then approve or edit it.
Before writing any code, produce a numbered plan with:
- files to create or edit
- the order of changes
- any risky assumptions
Wait for my approval, then execute.12. Code Generation Prompt
Write a TypeScript function 'slugify(input: string): string'.
- Lowercase everything.
- Replace non-alphanumerics with '-'.
- Collapse multiple '-' into one.
- Trim leading/trailing '-'.
Include 5 unit tests using Vitest.13. Refactoring Prompt
Refactor the file src/legacy/report.js:
- Convert to TypeScript.
- Extract the CSV parsing into its own module.
- Add JSDoc for every exported symbol.
Do NOT change behavior; add tests to prove it.14. Debugging Prompt
My test 'checkout adds tax' is failing with:
"Expected 108 but received 100."
<code>
{{PASTE FAILING FUNCTION HERE}}
</code>
Diagnose the root cause, propose the smallest fix, and show a diff.15. Good vs Bad Prompts
| Bad | Good |
|---|---|
| "fix my code" | "The function sum in utils.ts returns NaN when input is empty. Change it to return 0 and add a test." |
| "make it faster" | "Profile parseCsv, find the hottest function, and reduce its runtime by at least 30%. Show benchmarks before/after." |
| "write a landing page" | "Create a one-page landing site for an AI resume tool. Sections: hero, features (3), pricing, FAQ. Use Tailwind. No lorem ipsum." |
16. Real Project Prompts
Blog post generator
<role>Senior technical writer for a developer audience.</role>
<topic>{{TOPIC}}</topic>
<constraints>
- 800–1000 words
- H2 sections only, no H3
- Include one code snippet
- End with a 3-line summary
</constraints>Meeting notes summarizer
<transcript>{{TRANSCRIPT}}</transcript>
Return JSON:
{ "decisions": string[], "actions": {owner:string, item:string, due:string}[], "risks": string[] }SQL assistant
<schema>{{SCHEMA_DDL}}</schema>
<question>{{USER_QUESTION}}</question>
Return ONE valid Postgres query. Do not explain unless asked.