Skip to content

Prompt Engineering Techniques: A Summary

This post covers the fundamentals of prompt engineering, based mainly on Andrew Ng’s prompt engineering course. It serves as the lead-in to the prompt injection series — injection itself isn’t covered here, so see the later posts for that.

Clear, specific instructions are the baseline for working with an LLM. Clear doesn’t mean short. In fact, the longer and more detailed the prompt, the more context you provide and the more precise the answer. Four techniques support this principle.

A prompt usually contains both the instruction and the data to process, and models easily confuse the two. Delimiters separate them so the model can tell them apart:

Summarize the text delimited by triple backticks, capturing its core point in one sentence:
```
Here is the text to be summarized.
```

Backticks aren’t the only option. Anything distinguishable works: triple single quotes ('''), triple double quotes ("""), triple dashes (---), angle brackets (<>), custom tags (<test></test), and so on.

If the output feeds into another step — another script or program, say — or if you just want the result to be easy to scan, you need to specify the output format. JSON, Markdown, and HTML are the common choices:

Generate 3 fictional book titles, authors, and genres. Provide them in JSON format with the keys: bookid, booktitle, author, type.

If a task can only be completed under certain conditions, have the AI run a logical check first so it doesn’t confidently make things up. In the instruction below, the supplied content is clearly insufficient to be organized into steps:

You will be given text wrapped in triple double quotes. Rewrite it in the following format:
Step 1: ...
Step 2: ...
Step 3: ...
"""
I love studying.
"""

Add a logical check:

You will be given text wrapped in triple double quotes. If the text contains a series of steps, rewrite them in the following format:
Step 1: ...
Step 2: ...
Step 3: ...
If the text does not contain steps, answer: no steps found.
"""
I love studying.
"""

Give the model a few examples to work from. This adjusts tone and style and handles complex format conversions. Take this log line:

2025-08-08, platform A suffered an XSS attack; analysis determined the attack was unsuccessful.

I want it converted to 20250808:A:XSS:FAIL. To convert a large batch of logs afterward, one example is enough:

Input: 2025-08-08, platform A suffered an XSS attack; analysis determined the attack was unsuccessful.
Output: 20250808:A:XSS:FAIL
Convert the content wrapped in the triple double quotes below following the example above:
"""
2025-06-06, platform B suffered an XXE attack; analysis determined the attack was unsuccessful.
2025-07-11, platform C suffered an SSRF attack; analysis determined the attack was unsuccessful.
2025-08-22, platform D suffered an RCE attack; analysis determined the attack was successful.
"""

These four principles show up in daily life too. Delimiters are like highlighting the key points when studying, or telling someone where to find the source material for a task, or writing up meeting minutes. Structured output is the template you get when filling out a form. Conditional checks are pre-flight checks — the checklist before a plane takes off, or the call you get when an item you ordered is out of stock. Few-shot prompting is showing someone a good prior example. A lot of prompt engineering is rooted in how we already communicate at work and in daily life.

LLMs still generate by predicting the next token probabilistically. If the question is too complex, the answer may be imprecise or even hallucinated. Or you may want the model to follow your own line of reasoning. In either case, guide the model’s reasoning in the prompt. If I ask for an article on how to lose weight, the model will predict its way to something, and the result is probably broad and generic. Guiding its reasoning with explicit steps makes it follow my logic:

Write an article on how to lose weight, following these steps:
1. First, research what percentage of the world's population is obese, broken down by men and women.
2. Then explain why weight loss matters.
3. Then explain how to lose weight, covering lifestyle habits and exercise recommendations.
4. End with a message of encouragement, wishing everyone success.

Another technique: have the model think before giving a conclusion. Think of a teacher working through the problems before grading students’ homework. Why does this matter? Models are agreeable. If you ask “I think this is right — what do you think?”, the model will usually say you’re right and follow your reasoning, overlooking subtle errors. The fix is to have it produce its own answer first, then compare that answer against the target.

The prompt below looks like a simple math problem, but many models get it wrong:

Bought 2 apples at 10 yuan each and 3 pears at 5 yuan each. Total = 20 + 15 = 45 yuan. Can you check whether this student's calculation is correct?

The answer is obviously 35, but the model will say 45 is completely correct. Have it think before concluding:

Bought 2 apples at 10 yuan each and 3 pears at 5 yuan each. Total = 20 + 15 = 45 yuan. Can you check whether this student's calculation is correct?
Don't look at the student's answer yet. Please:
1. Answer the problem yourself based on your own understanding.
2. Output your calculation in detail.
3. Compare your result with the student's.
4. Then judge whether the student's calculation is correct.

There’s no perfect prompt, only prompts that keep improving. Iteration is a loop: try a first draft, analyze whether the output meets expectations, revise the instruction, and repeat until the result is right.

image-20260104163114796.png

That’s self-explanatory, so no example needed. When iterating, there are many dimensions to tune: word count, target audience, output format, logic changes, new requirements, added guidance steps.

Role assignment gives the model an identity. At the top of the prompt, specify a role — “you are an expert in X.” This narrows the probability space of the model’s answers: it draws a boundary around the plausible responses, making the answer more professional and better aligned with your needs. If I ask:

How do I make braised pork belly?

the answer is fairly broad, covering where to source ingredients and the general steps. But if I assign a role:

You are a chef at a five-star hotel. Tell me how to make braised pork belly.

the answer is more professional, because each predicted token falls within the range of a five-star chef — more detailed technique, plated presentation, balancing color, aroma, and taste.

Role assignment also sets tone and emphasis. Ask what inflation is and you get a generic explanation. Assign a role:

You are a kindergarten teacher. Tell me what inflation is.

and it answers with stories and games. You could specify those requirements directly — keep it simple, use a gentle tone, give examples a child would understand — but that’s tedious. Naming the kindergarten teacher role carries all of it.

Boundary setting is a negative constraint — a reverse prompt that draws red lines around the answer. Models tend to be friendly and verbose. Ask for a resignation letter and it may open by thanking the manager and the company, then close by wishing them well. If you don’t want the pleasantries:

Write me a resignation letter. Avoid pleasantries.

That’s a tone constraint. Content constraints work too:

Recommend some places to visit in Beijing. No places that require tickets, and no crowded influencer spots.

Or a length constraint:

Summarize 3 key points from this article. Keep each summary under 30 characters.

This helps when you want to accomplish a task but don’t know what information to provide. Have the AI ask you first:

I want you to help me write an annual fitness plan. To make the plan fit me as well as possible, ask me 5 key questions you need answered before you start writing.

The AI will ask about your goals, physical condition, weekly availability, preferred activities, diet, and so on, which lets it build a better plan.

The overall approach: assign a role first to narrow the probability space of subsequent tokens, then state the requirements clearly with as much context as possible, then specify output requirements such as format and negative constraints, and finally keep iterating based on the results.

Here’s a complete example, built around planning a 3-day family trip to Xi’an:

[Role]
You are a senior private travel consultant with 10 years of experience, skilled at uncovering a city's deeper cultural sites and balancing an itinerary around the needs of different family members.
[Detailed context]
Next week I'm taking my family (4 people: me, my spouse, a 6-year-old child, and a 65-year-old parent) to Xi'an for 3 days. We're staying near the Bell Tower. We love historic architecture and local food, but we don't want a rushed schedule because of the elderly parent's and child's stamina.
[Output requirements]
Generate a detailed itinerary in a Markdown table with: time slot, attraction/activity, transportation, and pitfalls to avoid.
[Negative requirements]
Don't recommend the tourist-only "influencer food streets" (such as the main drag of the Muslim Quarter). Recommend places locals actually go.
Don't schedule departures before 7 a.m.
Don't include influencer spots that require long queues.
Special note: leave 2 hours for a midday rest every day.
[Iteration guidance]
Give me a preliminary plan first; I'll have you adjust the hotel recommendations based on my budget.

That covers prompt engineering techniques. Thanks for reading.