A practical guide to building LLM-powered applications – based on insights from the DeepLearning.AI / OpenAI course. (ChatGPT Prompt Engineering for Developers)
📚 What You’ll Learn
- ✅ Two core prompting principles
- ✅ 7 actionable tactics (with code examples)
- ✅ Iterative prompt development process
- ✅ 4 key LLM capabilities: Summarizing, Inferring, Transforming, Expanding
- ✅ How to build a custom chatbot (OrderBot)
- ✅ How to control randomness with
temperature
“The power of LLMs as a developer tool is still underappreciated. You can build software applications incredibly fast using API calls.”
— Andrew Ng
🧠 1. Base LLM vs Instruction‑tuned LLM
| Feature | Base LLM | Instruction‑tuned LLM |
|---|---|---|
| Training | Predicts next word from internet/text data | Fine‑tuned on instructions + RLHF |
| Example prompt | “What is the capital of France?” | “What is the capital of France?” |
| Typical output | “What is France’s largest city? …” | “The capital of France is Paris.” |
| Best for | Research, creative generation | Practical applications (recommended) |
💡 For most products, use instruction‑tuned LLMs (like
gpt-3.5-turbo). They are safer, more helpful, and easier to control.
🎯 2. Two Golden Principles of Prompting
Principle 1: Write clear and specific instructions 🧾
“Don’t confuse a clear prompt with a short prompt. Longer prompts often give more context and better results.”
Principle 2: Give the model time to think ⏳
“If you ask someone a complex math question without time to work it out, they’ll likely make a mistake. Same for LLMs.”
🛠️ 3. Tactics You Can Use Today
For Principle 1 – Clear & Specific Instructions
| Tactic | What it does | Example |
|---|---|---|
| Use delimiters | Separates input from instructions | Triple backticks, quotes, XML tags |
| Ask for structured output | Easier to parse programmatically | JSON, HTML |
| Check conditions | Handle edge cases gracefully | “If no instructions, say ‘no steps provided’” |
| Few‑shot prompting | Show examples of desired output | Child → grandparent dialogue example |
📌 Example: Delimiters + Structured Output
prompt = f"""
Generate a list of three made-up book titles along with their authors and genres.
Provide them in JSON format with keys: book_id, title, author, genre.
"""
📌 Example: Condition Check
prompt = f"""
You will be provided with text delimited by triple quotes.
If it contains a sequence of instructions, rewrite them as steps.
If not, write "No steps provided".
Text: ```{user_input}```
"""
For Principle 2 – Give Time to Think
| Tactic | How to use |
|---|---|
| Specify the steps | Ask the model to do step‑by‑step (summarise → translate → output JSON) |
| Instruct to work out its own solution | Before judging a student’s answer, have the LLM solve it first |
📌 Example: Model solves first, then compares
prompt = f"""
First, work out your own solution to the problem.
Then compare it with the student's solution and decide if the student is correct.
Do not decide until you have done the problem yourself.
"""
⚠️ Watch out for hallucinations – the model may invent plausible but false facts.
🔧 Mitigation: Ask the model to first find relevant quotes from source text, then answer based on those quotes.
🔁 4. Iterative Prompt Development (The Real Process)
“I’ve never come up with the final prompt on the first attempt. What matters is having a good process.”
The loop you will use again and again:
flowchart LR
A[Idea / Task] --> B[Write prompt]
B --> C[Run & get result]
C --> D{Good enough?}
D -- No --> E[Analyze error]
E --> B
D -- Yes --> F[Deploy / Use]
Example iteration (chair fact sheet → marketing description)
- First prompt → too long
- Add “use at most 50 words” → better length
- Change audience to “furniture retailers” → more technical
- Add “include product IDs” → complete
💡 Start with one example, refine, then later test on 10–100 cases for mature apps.
📦 5. Four Core Capabilities for Developers
1️⃣ Summarizing 📄→📝
Use case: E‑commerce reviews, articles, support tickets.
prompt = f"""
Summarize the review below, delimited by triple backticks, in at most 30 words.
Focus on shipping and delivery.
Review: ```{review}```
"""
- Can also extract instead of summarize (e.g. only shipping info)
- Loop over multiple reviews → build a quick dashboard
2️⃣ Inferring 🔍
Use case: Sentiment, emotions, named entity recognition, topic classification.
| Task | Prompt example |
|---|---|
| Sentiment | “Give answer as single word: positive or negative” |
| Emotions | “List up to 5 emotions, lower case, comma separated” |
| Anger detection | “Is the writer expressing anger? yes/no” |
| Extract item & brand | “Output JSON with keys Item, Brand” |
| Multi‑task | Sentiment + Anger + Item + Brand in one JSON |
| Topic inference | “Determine which of these topics appear: NASA, local government, …” |
🎯 No need to train separate models – one LLM does it all.
3️⃣ Transforming 🔄
Use case: Translation, tone change, format conversion, grammar correction.
- Translation – single or multiple languages, formal/informal
- Tone – slang → business letter
- Format – JSON → HTML table
- Spelling/grammar – proofread, correct, even show diffs
prompt = f"""
Proofread and correct the following text. Make it more compelling.
Output in markdown format.
Text: ```{review}```
"""
4️⃣ Expanding 🌱
Use case: Brainstorming, personalised emails, creative writing.
⚠️ Use responsibly – can also generate spam or misleading content.
Example: Customer service email based on sentiment
prompt = f"""
You are a customer service AI assistant.
If sentiment is negative, apologise and suggest reaching out to support.
Use specific details from the review.
Sign as 'AI customer agent'.
"""
🌡️ 6. The temperature Parameter
Controls randomness / creativity:
| Temperature | Behaviour | When to use |
|---|---|---|
| 0 (default) | Always picks most likely word | Predictable, reliable answers (summaries, extraction, code) |
| 0.5 – 0.7 | Some variation | Creative writing, brainstorming |
| 1.0+ | High randomness, more “surprising” | Exploring diverse outputs (use with caution) |
✅ For production applications, start with temperature = 0 and increase only if you need variety.
🤖 7. Building a Custom Chatbot (OrderBot)
Use the chat completions endpoint with a list of messages:
messages = [
{"role": "system", "content": "You are OrderBot, a pizza restaurant assistant."},
{"role": "user", "content": "Hi, I'd like a pizza."},
{"role": "assistant", "content": "Sure! What size? We have pepperoni, cheese, eggplant."}
]
- System message – sets the persona, instructions (invisible to the end user)
- User & Assistant messages – the conversation history
- The model does not remember past calls – you must feed the whole context each time.
Example OrderBot system prompt (excerpt)
You are OrderBot. First greet, then collect order (pizza type, size, toppings, sides, drinks).
Ask if pickup or delivery. If delivery, get address. Finally collect payment.
Menu: pepperoni pizza 12.95, cheese 10.95, fries 4.50, coke 3.00...
Respond in short, friendly style.
At the end, ask the model to output a JSON summary that your backend can consume.
🧪 Quick Reference: Common Use Cases & Prompt Snippets
| Task | Prompt pattern |
|---|---|
| Summarise | "Summarise in at most X words: ```text```" |
| Sentiment | "What is the sentiment (positive/negative)? Answer in one word." |
| Extract fields | "Output JSON with keys: Item, Brand, Price" |
| Translate | "Translate English to Spanish: {text}" |
| Grammar fix | "Proofread and correct: ```{text}```" |
| Email reply | "You are a support agent. Reply to this review (sentiment: negative). Use details." |
| Chatbot | messages = [{"role":"system","content":"..."}, ...] |
📌 Final Tips for Product Managers & Developers
- Start with a working example – iterate, don’t aim for perfect first prompt.
- Use delimiters to avoid prompt injections and confusion.
- Prefer instruction‑tuned models (GPT‑3.5‑Turbo, GPT‑4) for products.
- Test temperature – use 0 for deterministic tasks, higher for creative flows.
- Be responsible – LLMs can hallucinate or be misused. Always label AI‑generated content.
“The key to being an effective prompt engineer is not knowing the perfect prompt – it’s having a good process to develop prompts that work for your application.”
— Andrew Ng
🧰 Next Steps
- ✍️ Pick a small task (summarise reviews, extract sentiment, build a simple bot).
- 🔁 Iterate on prompts using the principles above.
- 📊 When your app matures, test on 10–100 examples to measure performance.
- 🚀 Deploy and monitor – you can always refine further.
Now go build something amazing! 🎉
