# What Is Prompt Engineering?

> What prompt engineering is, how to write a prompt that works, and where it stops, explained simply for your AI interview.

**In short:** Prompt engineering is writing and testing the instructions, context and examples a model gets, so its answers are right and consistent. It is often the first fix to try, but some problems need different data or a different model instead.

AI and LLM interview question Q076, Prompt and context engineering. Beginner, very common (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/what-is-prompt-engineering

## Say it in 30 seconds

Prompt engineering is writing the instructions, context and examples a model needs to give the answer I want. I write the rules as short lines, set the output format, and add a few real examples. Then I test the prompt on past cases where I already know the right answer, change one thing at a time, and test again. It is often the first fix to try, because a prompt edit costs little. When the test still fails, the problem may be the data or the model instead.

## Say it in 2 minutes

A model reads one block of text and writes text back. That block is the prompt: my instructions, the background it needs, a few examples and the question. Prompt engineering is deciding what goes in that block, then testing and improving it until the answers are right.

I start with a clear job and a reader, then write the rules as short lines. I give the context the model can't know, like our motor policy wording, and I set the output format. Anthropic's guide asks for that too. It also suggests three to five examples that look like the real work. For a claims team, that could mean sorting motor claims into fast track, manual review or fraud check, with replies the code can check.

The part I trust most is the test. Before I change anything, I write down what success means and collect past cases where I know the answer. I score every run, change one thing, and run the same cases again. OpenAI notes that model output is non-deterministic, meaning the same prompt can give different answers, so prompting is part art and part science.

The limit matters too. Anthropic says plainly that not every failing test is best solved by prompt engineering. Sometimes the model is the wrong choice for the job, or the answer depends on data the prompt doesn't hold. Then I change the model, add the data, or change the process instead.

## What is prompt engineering, in plain words?

A model reads one block of text and writes text back. That block is the prompt: your instructions, the background the model needs, a few examples and the question itself. Prompt engineering is deciding what goes in that block, then testing and improving it until the answers are right.

> "Prompt engineering is the process of writing effective instructions for a model, such that it consistently generates content that meets your requirements." (OpenAI)
>
> "Prompt engineering is the art and science of designing and optimizing prompts to guide AI models, particularly LLMs, towards generating the desired responses." (Google Cloud)

Think of a new claims handler on their first morning. Hand them a vague brief and you get vague work. Give them the policy, the claim form, two solved cases and a clear format for the reply, and their work starts to look the same from one file to the next. A claims team sorting 2,000 motor claims a week needs exactly that kind of consistency from its AI.

- **Prompt:** Everything sent to the model in one call, such as the instructions, the examples and the question.
- **System prompt:** The developer's standing instructions, usually hidden from the end user.
- **Few-shot example:** A solved case shown in the prompt, so the model copies its shape.
- **Test set:** Past cases where you already know the right answer.
- **Output format:** The shape of the reply, such as JSON, that code can read.

## How do you write a prompt that works?

Start with five parts: the job and the reader, short rules, the context the model cannot know, the output format, and a few examples that look like the real work.

1. **Name the job and the reader:** Say who the output is for and exactly what it must do. Vague jobs get vague work.
2. **Write the rules as short lines:** One rule per line, such as the allowed labels and what to do when a detail is missing.
3. **Give the context:** Paste in the policy or fee table the answer depends on. The model can't know your rules unless they are in the prompt.
4. **Set the output format:** Ask for JSON or a fixed template, and say so plainly. Anthropic's guide asks for this too.
5. **Add three to five examples:** Anthropic's guide says a few well-crafted examples improve accuracy and consistency, and it suggests 3-5 for best results.
6. **Test before you trust it:** Run the same test cases after every change, and score them. Anthropic's guide also asks for a clear definition of success first.

*Diagram, The prompt test loop: The draft goes through the same test cases each time, and every change is judged by the same score. Stop when the scores reach the target you set in advance, or when the test shows the prompt alone can't get there. Keep the test set for the next change.*
1. Run the draft on the same test cases.
2. Mark each answer right, wrong or unsure.
3. Take the misses and change one thing that caused them.
4. Run the same test cases again.
5. When the scores reach your target, ship it and keep the test set.

Here is a small triage prompt built from those parts, for a motor insurer. No model is called, so the code gives the same result every time. The check function matters most: the prompt asks for JSON, and the code confirms the reply really is JSON with a known label.

```python
# A claims team's triage prompt, built from parts. No model is called here:
# the reply format is checked in code, because a prompt alone can't promise it.
import json
RULES = [
    "Sort each claim into FAST_TRACK, MANUAL_REVIEW or FRAUD_CHECK.",
    "Use FRAUD_CHECK when the photos and the date of loss disagree.",
    "Never approve a payout. Only sort the claim.",
]
EXAMPLE_CLAIM = "Rear bumper dent, 2 photos, police report attached."
EXAMPLE_REPLY = '{"route": "FAST_TRACK", "reason": "Clear damage, report on file"}'
ROUTES = ("FAST_TRACK", "MANUAL_REVIEW", "FRAUD_CHECK")
def build_prompt(claim):
    lines = ["You are a claims triage assistant at a motor insurer."]
    lines += ["Rules:"] + ["- " + rule for rule in RULES]
    lines += ["Example claim: " + EXAMPLE_CLAIM, "Example reply: " + EXAMPLE_REPLY]
    lines += ["Claim: " + claim, "Reply with JSON only."]
    return "\n".join(lines)
def check_reply(reply):
    try:
        data = json.loads(reply)
    except json.JSONDecodeError:
        return "REJECTED: not JSON, ask again"
    if not isinstance(data, dict) or data.get("route") not in ROUTES:
        return "REJECTED: unknown route"
    return "OK: " + data["route"]
prompt =build_prompt("Tree fell on the car on Sunday. Photos show roof dents.")
print(len(prompt.splitlines()), "lines in the prompt")
print(prompt.splitlines()[-1])
for reply in ['{"route": "FAST_TRACK", "reason": "Clear"}', "Sure! It is fast track.", '{"route": "PAY_NOW"}']:
    print(check_reply(reply))
```

Output:

```text
9 lines in the prompt
Reply with JSON only.
OK: FAST_TRACK
REJECTED: not JSON, ask again
REJECTED: unknown route
```

## Where does prompt engineering stop?

Prompt engineering is often the first fix to try, and it has a limit. Anthropic's guide says: "Not every success criterion or failing eval is best solved by prompt engineering." Some problems need different data, a different model or a change to the process.

- **Try first: Change the prompt.** Quick to try, and cheap to run. Good for format, tone and rules the model already follows well.
- **Then: Change the model.** Sometimes a different model improves speed and cost more easily than rewording the prompt. Measure it on the same test set.
- **Also: Give it the data.** If the answer depends on this month's fee table, the table has to reach the model. A prompt can't know it.

*Diagram, What to change when a prompt fails: Start with cheap changes to the words and examples. If the answers stay wrong, give the model the data it needs, or measure a different model on the same test cases. Either way, prove the fix on the same test cases.*
1. Start with the words and examples, the usual first fix.
2. Still wrong? Give it the data, or measure another model.
3. Re-run the same test cases and keep what passes.

### How would you fix a bot that is wrong one time in five?

A bank's support assistant answers questions about card fees. In about one reply in five it quotes an old fee table. Customers ask things like "What is the fee for a late card payment?", and the complaints team wants it fixed this week.

1. **Build the test set:** Collect 60 real past questions with the answers the fee team approved. Keep them apart from the prompt.
2. **Score the current prompt:** Mark each reply right, wrong or unsure. Count them before you change anything.
3. **Read the wrong ones:** Look for a pattern. Here, most wrong replies quote the old fee table.
4. **Change one thing:** Add a rule: quote fees only from the table in the prompt, and say so when the table has no answer.
5. **Re-run everything:** Run all 60 again. If another question breaks, the fix made things worse.
6. **Check the data:** If the table itself is out of date, fix the table. No prompt can make stale facts current.

> **Tip:** Name the trade-off in the interview. A strict rule makes the bot say it doesn't know more often, which is fine for fee questions and risky for loan advice.

## What does the interviewer want to hear?

**A strong answer covers**

- [ ] A plain definition: writing and testing the instructions a model gets.
- [ ] The parts of a good prompt: job, rules, context, format and examples.
- [ ] Testing: the same cases, scored after every change.
- [ ] Limits: when to change the model, the data or the process instead.
- [ ] One real example from work, with the failure and the fix.

**Common traps**

- Trap: "Prompt engineering is just finding the right magic words." Better: It is writing, testing and measuring instructions on known cases. The test decides when you're done.
- Trap: "If the answer is wrong, add more rules." Better: First check whether the prompt is the problem at all. Stale data and a weak model need different fixes.
- Trap: "A longer prompt is always safer." Better: Long prompts cost more and can bury the rule that matters. Keep what the test shows helps, and cut the rest.

## Can you spot the weak prompt?

**Spot the prompt that gives consistent answers:** Which prompt is most likely to give the same kind of answer every time, across 2,000 claims a week?

A. Read this claim and tell me what you think.
B. Sort this claim into FAST_TRACK, MANUAL_REVIEW or FRAUD_CHECK. Reply with JSON only. Use FRAUD_CHECK if the photos and date of loss disagree.
C. Read the policy, then tell me if this claim is fine. Keep the answer short and friendly.
D. Sort this claim into FAST_TRACK, MANUAL_REVIEW or FRAUD_CHECK, and explain the reason in a full paragraph.

**Answer:** B. It names the labels, the output format and the one rule that changes the route. The other three leave the shape of the answer to chance.

**Quick check:** A prompt gets 30 of 50 past claims right. What do you do next?

A. Rewrite the whole prompt from scratch and test it once
B. Add three more rules and skip the test
C. Change one thing, then re-run the same 50 claims and compare the scores
D. Switch to the largest model you can find

**Answer:** C. Same cases, one change, same scoring: then you know whether the change helped. Adding rules without a test can make other claims worse.

## Can you answer these from memory?

**Flash cards**

- **What is prompt engineering?** Writing and testing the instructions, context and examples a model gets, so its output is right.
- **What goes in a good prompt?** The job and reader, short rules, context, output format, and a few examples.
- **Why use a test set?** Same cases, one change at a time: you can see whether the change actually helped.
- **Is it the first fix to try?** Often yes, because a prompt edit costs little. Some problems need data or a different model.
- **Why does the output vary?** The model samples each next word from probabilities, so one prompt can give different replies.
- **What is few-shot?** Showing the model a few solved examples in the prompt so it copies their shape.

## Likely follow-up questions

- Q077 Zero-shot vs few-shot prompting? https://designervenkat.online/interview/ai/zero-shot-vs-few-shot-prompting
- Q080 What goes in a system prompt? https://designervenkat.online/interview/ai/what-goes-in-a-system-prompt
- Q081 What makes a good prompt? https://designervenkat.online/interview/ai/what-makes-a-good-prompt
- Q078 What is chain-of-thought, and when does it help? https://designervenkat.online/interview/ai/what-is-chain-of-thought-prompting
- Q087 Why template and version your prompts? https://designervenkat.online/interview/ai/why-template-and-version-your-prompts

## Learn it in depth

- [Prompt Engineering](https://designervenkat.online/learn/ai-engineering/prompt-engineering)
- [Prompts That Hold Up](https://designervenkat.online/learn/ai-engineering/robust-prompt-engineering)
