# Prompt Engineering Fundamentals

> Chapter 4 of the Courseiva GOOGLE-GEN-AI-LEADER curriculum — https://courseiva.com//learn/google-gen-ai-leader/prompt-engineering-fundamentals

**Official objective:** 2.1 — Explain prompt engineering principles

## Introduction

Prompt Engineering Fundamentals. This concept solves the problem of getting useless or unpredictable answers from generative AI tools like ChatGPT or Google Gemini. It matters because the Generative AI Leader exam tests your ability to design inputs that reliably produce correct, safe, and useful outputs, which is the core skill for anyone managing AI projects.

## The 3-Ingredient Recipe Analogy

3 teaspoons of baking soda was the only difference between a tray of delicious, fluffy chocolate chip cookies and a tray of flat, metallic-tasting discs that went straight into the bin. When I first learned to bake, I thought the recipe was just a list of ingredients. I would dump in flour, sugar, eggs, and chocolate chips, mix them together, and hope for the best. The results were always disappointing. I soon discovered that a recipe is not just a list; it is a precise set of instructions for both ingredients and actions. The exact measurement of baking soda matters. The order matters — cream the butter and sugar first, then add the eggs, then the dry ingredients. The temperature of the butter matters — room temperature, not melted. The baking time and temperature matter — 350 degrees Fahrenheit for exactly 10 minutes, not until the smoke alarm goes off.

Prompt engineering works the same way. You are the baker, and the large language model (an AI trained on vast amounts of text) is your oven. Your prompt is the recipe. If you just give the AI a vague instruction like 'write something about dogs', you will get a flat, generic, useless result. But if you specify the exact format, the tone, the target audience, the length, the key points to include, and the style of language, you get a perfectly baked response. Just like baking, small changes in the prompt produce dramatically different results. Changing one word from 'explain' to 'summarise' is the difference between a 500-word essay and a three-bullet-point list. Prompt engineering is the skill of writing those precise, controlled recipes for AI.

## Core explanation

Prompt engineering is the practice of designing and refining the text you give to a generative AI model to get a specific, high-quality output. Think of the AI as a very smart but very literal intern. If you say, 'Write a report', the intern might write a novel, a haiku, or a shopping list. You have to give clear, detailed instructions. The prompt is simply the input text you provide. The output is the text the AI generates.

Why does this exist? Early AI models were like vending machines — you pushed a button and got a predetermined snack. Modern generative AI models are more like a master chef who can cook any dish but needs your exact order. Prompt engineering is the menu you hand them. Without it, the model has no context, no constraints, and no direction. It will guess what you want, and its guess is usually wrong for your specific need.

What did it replace? Before prompt engineering, using AI meant training a custom model for every single task, which took months and cost millions of dollars. Prompt engineering lets you use one giant pre-trained model for thousands of different tasks just by changing what you write in the prompt box. This is revolutionary because it makes powerful AI accessible to anyone who can write clear instructions.

Here are the core principles of prompt engineering you need to know for the exam:
- Clarity: Be specific about what you want. Instead of 'Write about cloud computing', write 'Write a 200-word explanation of cloud computing for a non-technical business executive. Use the analogy of renting an apartment versus buying a house.'
- Context: Give the model background information. Tell it who the audience is, what the tone should be, and what key facts must be included. A prompt with no context is like making a phone call without saying who you are.
- Format: Specify the output format. Ask for a list, a table, a paragraph, bullet points, or a JSON object. If you do not specify, the AI will pick a format, and it might not be the one you need.
- Constraints: Set boundaries. Tell the AI what not to include. For example, 'Do not use jargon', 'Keep it under 100 words', or 'Do not mention competitors by name'.
- Examples: Provide a sample of what you want. This is called 'few-shot prompting'. If you want the AI to write a marketing email, show it one good example of a marketing email first.

A common technique is 'chain-of-thought prompting'. This means asking the AI to show its reasoning step by step before giving the final answer. For example, 'Solve this maths problem. First, explain your reasoning step by step. Then give the final answer.' This dramatically improves accuracy for complex tasks.

Another key idea is 'temperature'. This is a setting that controls how creative or random the AI's responses are. A low temperature (like 0.1) makes the AI predictable and safe. A high temperature (like 0.9) makes it more creative and surprising. For factual tasks, use low temperature. For creative writing, use higher temperature.

Prompt engineering is not just about asking nicely. It is a technical skill with measurable effects. A well-engineered prompt can make an AI model that normally fails a task suddenly pass it. The exam will test your understanding of these principles, not your ability to memorise specific prompts.

## Real-world context

Meet Sarah, a product manager at a mid-sized insurance company. She needs to generate 50 personalised customer service emails responding to claims. Each email must be polite, explain the claim decision, list the next steps, and include the customer's name and claim number. Without prompt engineering, she would write them all by hand, taking three days of boring work.

Sarah uses a generative AI tool. She starts with a basic prompt: 'Write a claim response email.' The AI gives her a generic, overly formal email that does not include the claim number or customer name. It is useless. Sarah must engineer a better prompt.

She writes a structured prompt with these components:
- Role: 'You are a helpful and empathetic customer service representative for SafeGuard Insurance.'
- Task: 'Write a personalised email to a customer responding to their recent claim.'
- Context: 'The customer's name is {customer_name}, their claim number is {claim_number}, and the claim decision is {decision}. If the decision is approved, explain that the payment will be sent within 5 business days. If the decision is denied, explain the reason and offer to review additional documents.'
- Format: 'The email should have a friendly greeting, a clear statement of the decision, a short explanation, the next steps in a bulleted list, and a polite closing with my name, Sarah Jones.'
- Constraint: 'Do not use legal jargon. Keep the email under 150 words.'

Sarah uses a tool that replaces the placeholders (like {customer_name}) with actual data from her spreadsheet. She runs the prompt for 50 customers. The AI generates 50 perfect emails in 30 seconds. She reviews a random sample of 5, finds them all correct, and sends them.

What does Sarah actually do as an IT professional? She practises these steps:
- Define the goal of the prompt before writing anything.
- Break the task into components: role, task, context, format, constraints.
- Test the prompt with one example before scaling up.
- Iterate — she runs the prompt, sees the output, adjusts the wording, and tests again until the output is exactly right.
- Use parameters like temperature. For this task, she sets temperature to 0.2 to ensure consistent, non-creative responses.

Prompt engineering saves Sarah three days of work per week. It reduces errors because the AI follows the same structure every time. It also lets her handle higher volumes without hiring more staff. For the Generative AI Leader exam, this scenario represents the core value proposition of prompt engineering: increasing productivity, consistency, and scale while reducing human effort for repetitive language tasks.

## Exam focus

The Generative AI Leader exam tests your understanding of prompt engineering principles, not your ability to write prompts. You will not be asked to write a prompt from scratch. Instead, you will be given scenarios and asked to identify the best prompt design approach or the most important principle applied.

Here are the exact concepts the exam loves to test:
- Zero-shot vs. few-shot prompting: Zero-shot means giving the AI a task with no examples. 'Translate this sentence to French.' Few-shot means giving one or more examples first. 'Here are three sentences translated to French. Now translate this one.' The exam will give you a scenario and ask which approach is better and why.
- Chain-of-thought prompting: This is a specific technique for reasoning tasks. The exam asks you to recognise when this technique is appropriate (for maths, logic, or multi-step problems) and what its benefit is (improved accuracy by forcing the model to explain its reasoning).
- Temperature settings: The exam tests your understanding of what temperature does. Low temperature equals deterministic, safe outputs. High temperature equals creative, varied outputs. A common trap question asks you to choose the best temperature for a factual task — the correct answer is always low temperature.
- Prompt structure: The exam may ask about the importance of including role, context, format, and constraints. A classic trap is a prompt that is technically correct but missing context, leading to an irrelevant answer.
- The problem of hallucination: AI models sometimes make up facts. Prompt engineering can reduce hallucination by asking the model to cite sources, restrict its answer to a specific dataset, or use a 'grounding' technique like providing a reference document.

Trap patterns to watch for:
- A question that gives a very long, complex scenario and asks for the 'best' prompt. The right answer is almost always the simplest prompt that includes all four elements: role, task, format, and constraint. The wrong answers will be missing one of these elements or will be overly complicated.
- A question that asks about 'temperature' for a creative task. The trap is that beginners think high temperature is always better for creativity, but the exam expects you to know that even creative tasks need some constraint — you would not set temperature to 1.0 for a business email.
- A question that confuses 'prompt engineering' with 'model training'. Prompt engineering does not change the model. It only changes the input. The exam will test this distinction.

Key definitions to memorise:
- Prompt: The input text given to the AI model.
- Output: The text generated by the AI model.
- Zero-shot prompting: Giving a task with no examples.
- Few-shot prompting: Giving a task with one or more examples.
- Chain-of-thought prompting: Asking the model to explain its reasoning step by step.
- Temperature: A parameter that controls the randomness of the output.
- Hallucination: The model generating false information.
- Context: Background information provided in the prompt to guide the model.

## Step by step

1. **Define Your Goal** — Before writing a single word, decide exactly what you want the AI to produce. Is it a summary, a list, an email, or a story? Defining the output type first prevents you from writing a vague prompt that leads to a useless answer.
2. **Assign a Role** — Tell the AI who it is pretending to be. For example, 'You are a senior financial analyst' or 'You are a friendly customer support agent'. This sets the tone, vocabulary, and level of expertise in the response.
3. **Provide Context and Task** — Give the background information the AI needs. Include the audience, the purpose, and any key facts. Then state the task clearly. For example, 'Write a 100-word product description for a waterproof smartwatch aimed at marathon runners.'
4. **Specify Format and Constraints** — Tell the AI exactly how to structure the output and what to avoid. 'Use bullet points. Keep it under 200 words. Do not use technical jargon. Include a call to action at the end.' Constraints prevent the AI from going off-topic or producing something you cannot use.
5. **Test and Iterate** — Run the prompt. Evaluate the output. Is it what you wanted? If not, change one element at a time — the role, the context, the format, or the constraints. Test again. Prompt engineering is an iterative process, not a one-time write. Each adjustment brings you closer to the perfect output.
6. **Set Parameters (Optional)** — If your tool allows, adjust parameters like temperature. For factual tasks, set temperature low (0.1 to 0.3). For creative tasks, set it higher (0.7 to 0.9). This fine-tunes the AI's behaviour without changing the prompt text itself.

## Comparisons

### Zero-shot prompting vs Few-shot prompting

**Zero-shot prompting:**
- No examples given in the prompt
- Works well for simple, well-defined tasks
- Faster to write and requires less effort

**Few-shot prompting:**
- One or more examples provided in the prompt
- Works better for complex or nuanced tasks
- Takes more time to craft but yields higher accuracy

### High temperature vs Low temperature

**High temperature:**
- Produces more creative and varied outputs
- Risk of hallucination and off-topic responses
- Best for creative writing, brainstorming, or poetry

**Low temperature:**
- Produces more deterministic and predictable outputs
- Lower risk of hallucination and higher factual accuracy
- Best for factual answers, code generation, or data extraction

### Prompt engineering vs Fine-tuning

**Prompt engineering:**
- Requires no changes to the underlying AI model
- Can be done by anyone with access to the AI tool
- Changes only the input to guide the output

**Fine-tuning:**
- Requires retraining the model on custom data
- Needs specialised machine learning skills and resources
- Permanently changes the model's behaviour

### Chain-of-thought prompting vs Standard prompting

**Chain-of-thought prompting:**
- Asks the model to show reasoning step by step
- Improves accuracy on arithmetic, logic, and multi-step tasks
- Produces longer outputs with visible reasoning

**Standard prompting:**
- Asks for the final answer directly
- Works well for simple, single-step tasks
- Produces shorter, direct outputs

## Common misconceptions

- **Misconception:** Prompt engineering is just about asking the AI nicely, like saying 'please' and 'thank you'. **Reality:** Prompt engineering is a structured technical skill involving role assignment, context provision, format specification, constraints, and parameter tuning. Politeness has no measurable effect on output quality. (People anthropomorphise AI and assume it responds to social cues like a human. In reality, the AI is just processing patterns in text, and polite language is just another pattern — it does not 'feel' appreciated.)
- **Misconception:** Once you write a good prompt, it will work perfectly for every similar task forever. **Reality:** Prompts are context-dependent. A prompt that works for generating marketing copy for a shoe brand may fail for a luxury watch brand. Models also get updated, and a prompt that worked with one version may break with the next. (Beginners think of prompts like software code — once it compiles, it works. But prompts are more like spoken instructions; their effectiveness depends on the listener's current training data and context.)
- **Misconception:** The longer the prompt, the better the output. **Reality:** Longer prompts can introduce noise and confusion. The best prompt is as short as possible while still including all necessary context, format, and constraints. Redundant or irrelevant information often degrades performance. (People mistakenly believe that more information always helps, but AI models can be distracted by irrelevant details, just like a human can be. Concise, targeted prompts are more effective.)
- **Misconception:** Prompt engineering is only useful for text generation, not for tasks like code generation or data analysis. **Reality:** Prompt engineering applies to any task you give a generative AI model, including writing code, generating SQL queries, summarising data, and even creating images. The principles of clarity, context, format, and constraints are universal. (Beginners often associate prompts only with chatbots. They do not realise that the same model can be used for hundreds of different tasks, and each task requires a tailored prompt design.)
- **Misconception:** If the AI gives a bad answer, you need to retrain the model. **Reality:** In most cases, the solution is not retraining the model but redesigning your prompt. Changing the wording, adding context, or adjusting the temperature often fixes the problem without any model training. (People come from a traditional software background where bugs mean fixing the code. Prompt engineering inverts this: the model is usually fine; the instruction is what is broken.)

## Key takeaways

- Prompt engineering is the skill of designing input instructions to control the output of a generative AI model, and it is the single most important skill for anyone using these tools.
- A well-structured prompt includes four components: role, task, format, and constraints — missing any one of these can lead to useless outputs.
- Zero-shot prompting gives the model a task with no examples, while few-shot prompting provides examples to improve accuracy on specific tasks.
- Chain-of-thought prompting asks the model to show its reasoning step by step, which dramatically improves performance on maths, logic, and multi-step reasoning problems.
- Temperature settings control the randomness of outputs: low temperature for factual accuracy, high temperature for creative variety.
- Prompt engineering does not modify or retrain the underlying AI model; it only changes the input to guide the existing model toward better outputs.
- The exam tests your ability to choose the right prompting technique for a given scenario, not your ability to memorise sample prompts.
- Hallucination — the AI inventing false information — can be reduced through careful prompt design, especially by providing reference material and asking the model to cite sources.

## FAQ

**Do I need to know how to code to do prompt engineering?**

No. Prompt engineering is a language skill, not a coding skill. You write instructions in plain English. However, knowing basic concepts like APIs and parameters can help you use advanced tools.

**Can one prompt work for every AI model?**

No. Different models (GPT-4, Gemini, Claude) are trained on different data and have different strengths. A prompt that works well on one model may need adjustment for another.

**Is prompt engineering the same as instructing a human assistant?**

Not exactly. Humans understand implied context and vague instructions. AI models take everything literally. You must be much more explicit and structured with an AI than with a person.

**What happens if I do not use any prompt engineering?**

You will get inconsistent, generic, and often useless outputs. The AI will guess what you want, and its guess will be wrong most of the time. You will waste time rewriting and correcting its responses.

**How do I know if my prompt is good?**

Run it. If the output meets your goal on the first try, the prompt is good. If you have to manually edit the output heavily, the prompt needs improvement. A good prompt produces usable output with zero or minimal edits.

**Is there a standard template for writing prompts?**

Yes, a common structure is: Role + Context + Task + Format + Constraints. You do not have to include all five every time, but starting with this template gives you a solid foundation.

---

Interactive version with quiz and diagrams: https://courseiva.com//learn/google-gen-ai-leader/prompt-engineering-fundamentals
